Example #1
0
 public void execute(Event<UIGroupSelector> event) throws Exception {
   UIGroupSelector uiSelectGroupForm = event.getSource();
   UIUserSelector uiSelectUserForm = uiSelectGroupForm.<UIComponent>getParent().getParent();
   String groupId = event.getRequestContext().getRequestParameter(OBJECTID);
   uiSelectUserForm.setSelectedGroup(groupId);
   OrganizationService service =
       uiSelectGroupForm.getApplicationComponent(OrganizationService.class);
   PageList users =
       uiSelectUserForm.removeDuplicate(service.getUserHandler().findUsersByGroup(groupId));
   users.setPageSize(10);
   uiSelectUserForm.uiIterator_.setPageList(users);
   uiSelectUserForm.setKeyword(null);
   event.getRequestContext().addUIComponentToUpdateByAjax(uiSelectUserForm);
 }
Example #2
0
  @SuppressWarnings("unchecked")
  public static boolean hasUserInGroup(String groupId, String userId) throws Exception {
    List<User> userList = new ArrayList<User>();
    PageList pageList = getUserHandler().findUsersByGroup(groupId);
    for (int i = 1; i <= pageList.getAvailablePage(); i++) {
      userList.clear();
      userList.addAll(pageList.getPage(i));
      for (User user : userList) {
        if (user.getUserName().equals(userId)) return true;
      }
    }

    return false;
  }
  public void setValues(Group group) throws Exception {
    PageList pageList = null;
    if (group == null) {
      pageList = EmptySerializablePageList.get();
    } else {
      OrganizationService service = getApplicationComponent(OrganizationService.class);
      MembershipHandler handler = service.getMembershipHandler();
      ListAccess<?> list = handler.findAllMembershipsByGroup(group);
      pageList =
          new FindMembershipByGroupPageList(
              group.getId(), list.getSize() > 10 ? list.getSize() : 10);
    }
    UIGridUser uiGrid = getChild(UIGridUser.class);
    pageList.setPageSize(5);

    UIPageIterator pageIterator = uiGrid.getUIPageIterator();
    /** We keep the currently selected page index * */
    int backupPageIndex = pageIterator.getCurrentPage();
    pageIterator.setPageList(pageList);

    if (group != null) {
      String groupId = group.getId();
      String currentUser = Util.getPortalRequestContext().getRemoteUser();

      // show action if user is administrator or manager of current group
      boolean showAction =
          GroupManagement.isAdministrator(currentUser)
              || GroupManagement.isManagerOfGroup(currentUser, groupId);

      if (!showAction) {
        pageList.setPageSize(10);
        if (getChild(UIGroupMembershipForm.class) != null) removeChild(UIGroupMembershipForm.class);
        uiGrid.configure("id", USER_BEAN_FIELD, null);
      } else {
        pageList.setPageSize(5);
        uiGrid.configure("id", USER_BEAN_FIELD, USER_ACTION);
        if (getChild(UIGroupMembershipForm.class) == null)
          addChild(UIGroupMembershipForm.class, null, null);
      }
    } else {
      pageList.setPageSize(10);
      if (getChild(UIGroupMembershipForm.class) != null) removeChild(UIGroupMembershipForm.class);
    }

    /** Reset the selected page index * */
    if (backupPageIndex > pageIterator.getAvailablePage()) {
      backupPageIndex = pageIterator.getAvailablePage();
    }
    pageIterator.setCurrentPage(backupPageIndex);
  }
Example #4
0
 public PageList removeDuplicate(PageList users) throws Exception {
   List after = new ArrayList();
   for (Object u : users.getAll()) {
     if (after.contains(u)) continue;
     after.add(u);
   }
   return new ObjectPageList(after, 10);
 }
Example #5
0
    public void execute(Event<UIUserSelector> event) throws Exception {
      UIUserSelector uiSelectUserForm = event.getSource();
      String groupId = uiSelectUserForm.getSelectedGroup();
      OrganizationService service =
          uiSelectUserForm.getApplicationComponent(OrganizationService.class);

      PageList users = PageList.EMPTY_LIST;
      if (groupId != null && groupId.trim().length() != 0) {
        if (service.getGroupHandler().findGroupById(groupId) != null) {
          users =
              uiSelectUserForm.removeDuplicate(service.getUserHandler().findUsersByGroup(groupId));
        }
      } else {
        users = service.getUserHandler().findUsers(new Query());
      }
      users.setPageSize(10);
      uiSelectUserForm.uiIterator_.setPageList(users);
      uiSelectUserForm.setKeyword(null);
      event.getRequestContext().addUIComponentToUpdateByAjax(uiSelectUserForm);
    }
Example #6
0
  /** {@inheritDoc} */
  @SuppressWarnings("deprecation")
  public Space createSpace(Space space, String creator, String invitedGroupId) {
    // Creates new space by creating new group
    String groupId = null;
    try {
      groupId = SpaceUtils.createGroup(space.getPrettyName(), creator);
    } catch (SpaceException e) {
      LOG.error("Error while creating group", e);
    }

    if (invitedGroupId != null) { // Invites user in group join to new created
      // space.
      // Gets users in group and then invites user to join into space.
      OrganizationService org = getOrgService();
      try {

        // Cannot use due to http://jira.exoplatform.org/browse/EXOGTN-173
        // ListAccess<User> groupMembersAccess =
        // org.getUserHandler().findUsersByGroup(invitedGroupId);
        // User [] users = groupMembersAccess.load(0, groupMembersAccess.getSize());
        PageList<User> groupMembersAccess = org.getUserHandler().findUsersByGroup(invitedGroupId);
        List<User> users = groupMembersAccess.getAll();

        for (User user : users) {
          String userId = user.getUserName();
          if (!userId.equals(creator)) {
            String[] invitedUsers = space.getInvitedUsers();
            if (!ArrayUtils.contains(invitedUsers, userId)) {
              invitedUsers = (String[]) ArrayUtils.add(invitedUsers, userId);
              space.setInvitedUsers(invitedUsers);
            }
          }
        }
      } catch (Exception e) {
        LOG.error("Failed to invite users from group " + invitedGroupId, e);
      }
    }

    String prettyName = groupId.split("/")[2];

    if (!prettyName.equals(space.getPrettyName())) {
      // work around for SOC-2366
      space.setPrettyName(groupId.split("/")[2]);
    }

    String[] managers = new String[] {creator};
    String[] members = new String[] {creator};
    space.setManagers(managers);
    space.setMembers(members);
    space.setGroupId(groupId);
    space.setUrl(space.getPrettyName());

    saveSpace(space, true);
    spaceLifeCycle.spaceCreated(space, creator);

    try {
      SpaceApplicationHandler spaceApplicationHandler = getSpaceApplicationHandler(space);
      spaceApplicationHandler.initApps(space, getSpaceApplicationConfigPlugin());
      for (SpaceApplication spaceApplication :
          getSpaceApplicationConfigPlugin().getSpaceApplicationList()) {
        setApp(
            space,
            spaceApplication.getPortletName(),
            spaceApplication.getAppTitle(),
            spaceApplication.isRemovable(),
            Space.ACTIVE_STATUS);
      }
    } catch (Exception e) {
      LOG.warn("Failed to init apps", e);
    }

    saveSpace(space, false);

    return space;
  }
    public void execute(Event<UIForgetPassword> event) throws Exception {
      UIForgetPassword uiForm = event.getSource();
      UILogin uilogin = uiForm.getParent();
      WebuiRequestContext requestContext = event.getRequestContext();
      PortalRequestContext portalContext = PortalRequestContext.getCurrentInstance();
      String url = portalContext.getRequest().getRequestURL().toString();
      MailService mailSrc = uiForm.getApplicationComponent(MailService.class);
      OrganizationService orgSrc = uiForm.getApplicationComponent(OrganizationService.class);
      String userName = uiForm.getUIStringInput(Username).getValue();
      String email = uiForm.getUIStringInput(Email).getValue();
      uiForm.reset();

      User user = null;

      String tokenId = null;

      // User provided his username
      if (userName != null) {
        user = orgSrc.getUserHandler().findUserByName(userName);
        if (user == null) {
          requestContext
              .getUIApplication()
              .addMessage(new ApplicationMessage("UIForgetPassword.msg.user-not-exist", null));
          return;
        }
      }

      // User provided his email address
      if (user == null && email != null) {
        Query query = new Query();
        // Querying on email won't work. PLIDM-12
        // Note that querying on email is inefficient as it loops over all users...
        query.setEmail(email);
        PageList<User> users = orgSrc.getUserHandler().findUsers(query);
        if (users.getAll().size() > 0) {
          user = users.getAll().get(0);
        } else {
          requestContext
              .getUIApplication()
              .addMessage(new ApplicationMessage("UIForgetPassword.msg.email-not-exist", null));
          return;
        }
      }

      email = user.getEmail();

      // Create token
      RemindPasswordTokenService tokenService =
          uiForm.getApplicationComponent(RemindPasswordTokenService.class);
      Credentials credentials = new Credentials(user.getUserName(), "");
      tokenId = tokenService.createToken(credentials);

      String portalName = URLEncoder.encode(Util.getUIPortal().getName(), "UTF-8");

      ResourceBundle res = requestContext.getApplicationResourceBundle();
      String headerMail = "headermail";
      String footerMail = "footer";
      try {
        headerMail =
            res.getString(uiForm.getId() + ".mail.header")
                + "\n\n"
                + res.getString(uiForm.getId() + ".mail.user")
                + user.getUserName()
                + "\n"
                + res.getString(uiForm.getId() + ".mail.link");
        footerMail = "\n\n\n" + res.getString(uiForm.getId() + ".mail.footer");
      } catch (MissingResourceException e) {
        e.printStackTrace();
      }
      String host = url.substring(0, url.indexOf(requestContext.getRequestContextPath()));
      String activeLink =
          host
              + requestContext.getRequestContextPath()
              + "/public/"
              + portalName
              + "?portal:componentId=UIPortal&portal:action=RecoveryPasswordAndUsername&tokenId="
              + tokenId;
      String mailText = headerMail + "\n" + activeLink + footerMail;
      try {
        mailSrc.sendMessage(
            res.getString("UIForgetPassword.mail.from"),
            email,
            res.getString("UIForgetPassword.mail.subject"),
            mailText);
      } catch (Exception e) {
        requestContext
            .getUIApplication()
            .addMessage(new ApplicationMessage("UIForgetPassword.msg.send-mail-fail", null));
        requestContext.addUIComponentToUpdateByAjax(uilogin);

        return;
      }

      uilogin.getChild(UILoginForm.class).setRendered(true);
      uilogin.getChild(UIForgetPasswordWizard.class).setRendered(false);
      uilogin.getChild(UIForgetPassword.class).setRendered(false);
      requestContext
          .getUIApplication()
          .addMessage(new ApplicationMessage("UIForgetPassword.msg.send-mail-success", null));
      requestContext.addUIComponentToUpdateByAjax(uilogin);
    }