コード例 #1
0
  protected void notifyCommunityAdministrators(MembershipRequest membershipRequest)
      throws IOException, PortalException, SystemException {

    List<UserGroupRole> admins = new UniqueList<UserGroupRole>();

    Role communityAdminRole =
        roleLocalService.getRole(
            membershipRequest.getCompanyId(), RoleConstants.COMMUNITY_ADMINISTRATOR);

    List<UserGroupRole> communityAdmins =
        userGroupRoleLocalService.getUserGroupRolesByGroupAndRole(
            membershipRequest.getGroupId(), communityAdminRole.getRoleId());

    admins.addAll(communityAdmins);

    Role communityOwnerRole =
        rolePersistence.findByC_N(membershipRequest.getCompanyId(), RoleConstants.COMMUNITY_OWNER);

    List<UserGroupRole> communityOwners =
        userGroupRoleLocalService.getUserGroupRolesByGroupAndRole(
            membershipRequest.getGroupId(), communityOwnerRole.getRoleId());

    admins.addAll(communityOwners);

    for (UserGroupRole userGroupRole : admins) {
      notify(
          userGroupRole.getUserId(),
          membershipRequest,
          PropsKeys.COMMUNITIES_EMAIL_MEMBERSHIP_REQUEST_SUBJECT,
          PropsKeys.COMMUNITIES_EMAIL_MEMBERSHIP_REQUEST_BODY);
    }
  }
コード例 #2
0
  @Override
  public void processAction(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig portletConfig,
      ActionRequest actionRequest,
      ActionResponse actionResponse)
      throws Exception {

    try {
      ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

      long membershipRequestId = ParamUtil.getLong(actionRequest, "membershipRequestId");

      int statusId = ParamUtil.getInteger(actionRequest, "statusId");
      String replyComments = ParamUtil.getString(actionRequest, "replyComments");

      ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);

      MembershipRequestServiceUtil.updateStatus(
          membershipRequestId, replyComments, statusId, serviceContext);

      if (statusId == MembershipRequestConstants.STATUS_APPROVED) {
        MembershipRequest membershipRequest =
            MembershipRequestServiceUtil.getMembershipRequest(membershipRequestId);

        LiveUsers.joinGroup(
            themeDisplay.getCompanyId(),
            membershipRequest.getGroupId(),
            new long[] {membershipRequest.getUserId()});
      }

      SessionMessages.add(actionRequest, "membership_reply_sent");

      sendRedirect(actionRequest, actionResponse);
    } catch (Exception e) {
      if (e instanceof NoSuchGroupException || e instanceof PrincipalException) {

        SessionErrors.add(actionRequest, e.getClass());

        setForward(actionRequest, "portlet.sites_admin.error");
      } else if (e instanceof MembershipRequestCommentsException) {

        SessionErrors.add(actionRequest, e.getClass());

        setForward(actionRequest, "portlet.sites_admin.reply_membership_request");
      } else {
        throw e;
      }
    }
  }
コード例 #3
0
  public void updateStatus(
      long replierUserId, long membershipRequestId, String replyComments, int statusId)
      throws PortalException, SystemException {

    validate(replyComments);

    MembershipRequest membershipRequest =
        membershipRequestPersistence.findByPrimaryKey(membershipRequestId);

    membershipRequest.setReplyComments(replyComments);
    membershipRequest.setReplyDate(new Date());
    membershipRequest.setReplierUserId(replierUserId);
    membershipRequest.setStatusId(statusId);

    membershipRequestPersistence.update(membershipRequest, false);

    if (statusId == MembershipRequestConstants.STATUS_APPROVED) {
      long[] addUserIds = new long[] {membershipRequest.getUserId()};

      userLocalService.addGroupUsers(membershipRequest.getGroupId(), addUserIds);
    }

    try {
      notify(
          membershipRequest.getUserId(),
          membershipRequest,
          PropsKeys.COMMUNITIES_EMAIL_MEMBERSHIP_REPLY_SUBJECT,
          PropsKeys.COMMUNITIES_EMAIL_MEMBERSHIP_REPLY_BODY);
    } catch (IOException ioe) {
      throw new SystemException(ioe);
    }
  }
  /**
   * Adds the membership request to the database. Also notifies the appropriate model listeners.
   *
   * @param membershipRequest the membership request
   * @return the membership request that was added
   */
  @Indexable(type = IndexableType.REINDEX)
  @Override
  public MembershipRequest addMembershipRequest(MembershipRequest membershipRequest) {
    membershipRequest.setNew(true);

    return membershipRequestPersistence.update(membershipRequest);
  }
コード例 #5
0
  public MembershipRequest addMembershipRequest(long userId, long groupId, String comments)
      throws PortalException, SystemException {

    User user = userPersistence.findByPrimaryKey(userId);
    Date now = new Date();

    validate(comments);

    long membershipRequestId = counterLocalService.increment();

    MembershipRequest membershipRequest = membershipRequestPersistence.create(membershipRequestId);

    membershipRequest.setCompanyId(user.getCompanyId());
    membershipRequest.setUserId(userId);
    membershipRequest.setCreateDate(now);
    membershipRequest.setGroupId(groupId);
    membershipRequest.setComments(comments);
    membershipRequest.setStatusId(MembershipRequestConstants.STATUS_PENDING);

    membershipRequestPersistence.update(membershipRequest, false);

    try {
      notifyCommunityAdministrators(membershipRequest);
    } catch (IOException ioe) {
      throw new SystemException(ioe);
    }

    return membershipRequest;
  }
コード例 #6
0
  protected Object[] updateGroup(ActionRequest actionRequest) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long userId = PortalUtil.getUserId(actionRequest);

    long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId");

    long parentGroupId =
        ParamUtil.getLong(
            actionRequest,
            "parentGroupSearchContainerPrimaryKeys",
            GroupConstants.DEFAULT_PARENT_GROUP_ID);
    String name = null;
    String description = null;
    int type = 0;
    String friendlyURL = null;
    boolean active = false;

    ServiceContext serviceContext =
        ServiceContextFactory.getInstance(Group.class.getName(), actionRequest);

    Group liveGroup = null;
    String oldFriendlyURL = null;
    String oldStagingFriendlyURL = null;

    if (liveGroupId <= 0) {

      // Add group

      name = ParamUtil.getString(actionRequest, "name");
      description = ParamUtil.getString(actionRequest, "description");
      type = ParamUtil.getInteger(actionRequest, "type");
      friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL");
      active = ParamUtil.getBoolean(actionRequest, "active");

      liveGroup =
          GroupServiceUtil.addGroup(
              parentGroupId,
              GroupConstants.DEFAULT_LIVE_GROUP_ID,
              name,
              description,
              type,
              friendlyURL,
              true,
              active,
              serviceContext);

      LiveUsers.joinGroup(themeDisplay.getCompanyId(), liveGroup.getGroupId(), userId);
    } else {

      // Update group

      liveGroup = GroupLocalServiceUtil.getGroup(liveGroupId);

      oldFriendlyURL = liveGroup.getFriendlyURL();

      name = ParamUtil.getString(actionRequest, "name", liveGroup.getName());
      description = ParamUtil.getString(actionRequest, "description", liveGroup.getDescription());
      type = ParamUtil.getInteger(actionRequest, "type", liveGroup.getType());
      friendlyURL = ParamUtil.getString(actionRequest, "friendlyURL", liveGroup.getFriendlyURL());
      active = ParamUtil.getBoolean(actionRequest, "active", liveGroup.getActive());

      liveGroup =
          GroupServiceUtil.updateGroup(
              liveGroupId,
              parentGroupId,
              name,
              description,
              type,
              friendlyURL,
              active,
              serviceContext);

      if (type == GroupConstants.TYPE_SITE_OPEN) {
        List<MembershipRequest> membershipRequests =
            MembershipRequestLocalServiceUtil.search(
                liveGroupId,
                MembershipRequestConstants.STATUS_PENDING,
                QueryUtil.ALL_POS,
                QueryUtil.ALL_POS);

        for (MembershipRequest membershipRequest : membershipRequests) {
          MembershipRequestServiceUtil.updateStatus(
              membershipRequest.getMembershipRequestId(),
              themeDisplay.translate("your-membership-has-been-approved"),
              MembershipRequestConstants.STATUS_APPROVED,
              serviceContext);

          LiveUsers.joinGroup(
              themeDisplay.getCompanyId(),
              membershipRequest.getGroupId(),
              new long[] {membershipRequest.getUserId()});
        }
      }
    }

    // Settings

    UnicodeProperties typeSettingsProperties = liveGroup.getTypeSettingsProperties();

    String customJspServletContextName =
        ParamUtil.getString(
            actionRequest,
            "customJspServletContextName",
            typeSettingsProperties.getProperty("customJspServletContextName"));

    typeSettingsProperties.setProperty("customJspServletContextName", customJspServletContextName);

    typeSettingsProperties.setProperty(
        "defaultSiteRoleIds",
        ListUtil.toString(getRoles(actionRequest), Role.ROLE_ID_ACCESSOR, StringPool.COMMA));
    typeSettingsProperties.setProperty(
        "defaultTeamIds",
        ListUtil.toString(getTeams(actionRequest), Team.TEAM_ID_ACCESSOR, StringPool.COMMA));

    String[] analyticsTypes =
        PrefsPropsUtil.getStringArray(
            themeDisplay.getCompanyId(), PropsKeys.ADMIN_ANALYTICS_TYPES, StringPool.NEW_LINE);

    for (String analyticsType : analyticsTypes) {
      if (analyticsType.equalsIgnoreCase("google")) {
        String googleAnalyticsId =
            ParamUtil.getString(
                actionRequest,
                "googleAnalyticsId",
                typeSettingsProperties.getProperty("googleAnalyticsId"));

        typeSettingsProperties.setProperty("googleAnalyticsId", googleAnalyticsId);
      } else {
        String analyticsScript =
            ParamUtil.getString(
                actionRequest,
                SitesUtil.ANALYTICS_PREFIX + analyticsType,
                typeSettingsProperties.getProperty(analyticsType));

        typeSettingsProperties.setProperty(
            SitesUtil.ANALYTICS_PREFIX + analyticsType, analyticsScript);
      }
    }

    String publicRobots =
        ParamUtil.getString(
            actionRequest, "publicRobots", liveGroup.getTypeSettingsProperty("false-robots.txt"));
    String privateRobots =
        ParamUtil.getString(
            actionRequest, "privateRobots", liveGroup.getTypeSettingsProperty("true-robots.txt"));

    typeSettingsProperties.setProperty("false-robots.txt", publicRobots);
    typeSettingsProperties.setProperty("true-robots.txt", privateRobots);

    int trashEnabled =
        ParamUtil.getInteger(
            actionRequest,
            "trashEnabled",
            GetterUtil.getInteger(typeSettingsProperties.getProperty("trashEnabled")));

    typeSettingsProperties.setProperty("trashEnabled", String.valueOf(trashEnabled));

    int trashEntriesMaxAgeCompany =
        PrefsPropsUtil.getInteger(themeDisplay.getCompanyId(), PropsKeys.TRASH_ENTRIES_MAX_AGE);

    int defaultTrashEntriesMaxAgeGroup =
        GetterUtil.getInteger(
            typeSettingsProperties.getProperty("trashEntriesMaxAge"), trashEntriesMaxAgeCompany);

    int trashEntriesMaxAgeGroup =
        ParamUtil.getInteger(actionRequest, "trashEntriesMaxAge", defaultTrashEntriesMaxAgeGroup);

    if (trashEntriesMaxAgeGroup != trashEntriesMaxAgeCompany) {
      typeSettingsProperties.setProperty(
          "trashEntriesMaxAge", String.valueOf(trashEntriesMaxAgeGroup));
    } else {
      typeSettingsProperties.remove("trashEntriesMaxAge");
    }

    // Virtual hosts

    LayoutSet publicLayoutSet = liveGroup.getPublicLayoutSet();

    String publicVirtualHost =
        ParamUtil.getString(
            actionRequest, "publicVirtualHost", publicLayoutSet.getVirtualHostname());

    LayoutSetServiceUtil.updateVirtualHost(liveGroup.getGroupId(), false, publicVirtualHost);

    LayoutSet privateLayoutSet = liveGroup.getPrivateLayoutSet();

    String privateVirtualHost =
        ParamUtil.getString(
            actionRequest, "privateVirtualHost", privateLayoutSet.getVirtualHostname());

    LayoutSetServiceUtil.updateVirtualHost(liveGroup.getGroupId(), true, privateVirtualHost);

    // Staging

    if (liveGroup.hasStagingGroup()) {
      Group stagingGroup = liveGroup.getStagingGroup();

      oldStagingFriendlyURL = stagingGroup.getFriendlyURL();

      friendlyURL =
          ParamUtil.getString(actionRequest, "stagingFriendlyURL", stagingGroup.getFriendlyURL());

      GroupServiceUtil.updateFriendlyURL(stagingGroup.getGroupId(), friendlyURL);

      LayoutSet stagingPublicLayoutSet = stagingGroup.getPublicLayoutSet();

      publicVirtualHost =
          ParamUtil.getString(
              actionRequest,
              "stagingPublicVirtualHost",
              stagingPublicLayoutSet.getVirtualHostname());

      LayoutSetServiceUtil.updateVirtualHost(stagingGroup.getGroupId(), false, publicVirtualHost);

      LayoutSet stagingPrivateLayoutSet = stagingGroup.getPrivateLayoutSet();

      privateVirtualHost =
          ParamUtil.getString(
              actionRequest,
              "stagingPrivateVirtualHost",
              stagingPrivateLayoutSet.getVirtualHostname());

      LayoutSetServiceUtil.updateVirtualHost(stagingGroup.getGroupId(), true, privateVirtualHost);
    }

    liveGroup =
        GroupServiceUtil.updateGroup(liveGroup.getGroupId(), typeSettingsProperties.toString());

    // Layout set prototypes

    if (!liveGroup.isStaged()) {
      long privateLayoutSetPrototypeId =
          ParamUtil.getLong(actionRequest, "privateLayoutSetPrototypeId");
      long publicLayoutSetPrototypeId =
          ParamUtil.getLong(actionRequest, "publicLayoutSetPrototypeId");

      boolean privateLayoutSetPrototypeLinkEnabled =
          ParamUtil.getBoolean(
              actionRequest,
              "privateLayoutSetPrototypeLinkEnabled",
              privateLayoutSet.isLayoutSetPrototypeLinkEnabled());
      boolean publicLayoutSetPrototypeLinkEnabled =
          ParamUtil.getBoolean(
              actionRequest,
              "publicLayoutSetPrototypeLinkEnabled",
              publicLayoutSet.isLayoutSetPrototypeLinkEnabled());

      if ((privateLayoutSetPrototypeId == 0)
          && (publicLayoutSetPrototypeId == 0)
          && !privateLayoutSetPrototypeLinkEnabled
          && !publicLayoutSetPrototypeLinkEnabled) {

        long layoutSetPrototypeId = ParamUtil.getLong(actionRequest, "layoutSetPrototypeId");
        int layoutSetVisibility = ParamUtil.getInteger(actionRequest, "layoutSetVisibility");
        boolean layoutSetPrototypeLinkEnabled =
            ParamUtil.getBoolean(
                actionRequest, "layoutSetPrototypeLinkEnabled", (layoutSetPrototypeId > 0));

        if (layoutSetVisibility == _LAYOUT_SET_VISIBILITY_PRIVATE) {
          privateLayoutSetPrototypeId = layoutSetPrototypeId;

          privateLayoutSetPrototypeLinkEnabled = layoutSetPrototypeLinkEnabled;
        } else {
          publicLayoutSetPrototypeId = layoutSetPrototypeId;

          publicLayoutSetPrototypeLinkEnabled = layoutSetPrototypeLinkEnabled;
        }
      }

      SitesUtil.updateLayoutSetPrototypesLinks(
          liveGroup,
          publicLayoutSetPrototypeId,
          privateLayoutSetPrototypeId,
          publicLayoutSetPrototypeLinkEnabled,
          privateLayoutSetPrototypeLinkEnabled);
    }

    // Staging

    String redirect = ParamUtil.getString(actionRequest, "redirect");

    long refererPlid = GetterUtil.getLong(HttpUtil.getParameter(redirect, "refererPlid", false));

    if (!privateLayoutSet.isLayoutSetPrototypeLinkActive()
        && !publicLayoutSet.isLayoutSetPrototypeLinkActive()) {

      if ((refererPlid > 0)
          && liveGroup.hasStagingGroup()
          && (themeDisplay.getScopeGroupId() != liveGroup.getGroupId())) {

        Layout firstLayout =
            LayoutLocalServiceUtil.fetchFirstLayout(
                liveGroup.getGroupId(), false, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);

        if (firstLayout == null) {
          firstLayout =
              LayoutLocalServiceUtil.fetchFirstLayout(
                  liveGroup.getGroupId(), true, LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);
        }

        if (firstLayout != null) {
          refererPlid = firstLayout.getPlid();
        } else {
          refererPlid = 0;
        }
      }

      StagingUtil.updateStaging(actionRequest, liveGroup);
    }

    return new Object[] {liveGroup, oldFriendlyURL, oldStagingFriendlyURL, refererPlid};
  }
コード例 #7
0
  protected void notify(
      long userId, MembershipRequest membershipRequest, String subjectProperty, String bodyProperty)
      throws IOException, PortalException, SystemException {

    Company company = companyPersistence.findByPrimaryKey(membershipRequest.getCompanyId());

    Group group = groupPersistence.findByPrimaryKey(membershipRequest.getGroupId());

    User user = userPersistence.findByPrimaryKey(userId);
    User requestUser = userPersistence.findByPrimaryKey(membershipRequest.getUserId());

    String fromName =
        PrefsPropsUtil.getString(
            membershipRequest.getCompanyId(), PropsKeys.COMMUNITIES_EMAIL_FROM_NAME);

    String fromAddress =
        PrefsPropsUtil.getString(
            membershipRequest.getCompanyId(), PropsKeys.COMMUNITIES_EMAIL_FROM_ADDRESS);

    String toName = user.getFullName();
    String toAddress = user.getEmailAddress();

    String subject = PrefsPropsUtil.getContent(membershipRequest.getCompanyId(), subjectProperty);

    String body = PrefsPropsUtil.getContent(membershipRequest.getCompanyId(), bodyProperty);

    String statusKey = null;

    if (membershipRequest.getStatusId() == MembershipRequestConstants.STATUS_APPROVED) {

      statusKey = "approved";
    } else if (membershipRequest.getStatusId() == MembershipRequestConstants.STATUS_DENIED) {

      statusKey = "denied";
    } else {
      statusKey = "pending";
    }

    subject =
        StringUtil.replace(
            subject,
            new String[] {
              "[$COMMUNITY_NAME$]",
              "[$COMPANY_ID$]",
              "[$COMPANY_MX$]",
              "[$COMPANY_NAME$]",
              "[$FROM_ADDRESS$]",
              "[$FROM_NAME$]",
              "[$PORTAL_URL$]",
              "[$REQUEST_USER_ADDRESS$]",
              "[$REQUEST_USER_NAME$]",
              "[$STATUS$]",
              "[$TO_NAME$]",
              "[$USER_ADDRESS$]",
              "[$USER_NAME$]",
            },
            new String[] {
              group.getName(),
              String.valueOf(company.getCompanyId()),
              company.getMx(),
              company.getName(),
              fromAddress,
              fromName,
              company.getVirtualHost(),
              requestUser.getEmailAddress(),
              requestUser.getFullName(),
              LanguageUtil.get(user.getLocale(), statusKey),
              toName,
              user.getEmailAddress(),
              user.getFullName()
            });

    body =
        StringUtil.replace(
            body,
            new String[] {
              "[$COMMENTS$]",
              "[$COMMUNITY_NAME$]",
              "[$COMPANY_ID$]",
              "[$COMPANY_MX$]",
              "[$COMPANY_NAME$]",
              "[$FROM_ADDRESS$]",
              "[$FROM_NAME$]",
              "[$PORTAL_URL$]",
              "[$REPLY_COMMENTS$]",
              "[$REQUEST_USER_NAME$]",
              "[$REQUEST_USER_ADDRESS$]",
              "[$STATUS$]",
              "[$TO_NAME$]",
              "[$USER_ADDRESS$]",
              "[$USER_NAME$]",
            },
            new String[] {
              membershipRequest.getComments(),
              group.getName(),
              String.valueOf(company.getCompanyId()),
              company.getMx(),
              company.getName(),
              fromAddress,
              fromName,
              company.getVirtualHost(),
              membershipRequest.getReplyComments(),
              requestUser.getFullName(),
              requestUser.getEmailAddress(),
              LanguageUtil.get(user.getLocale(), statusKey),
              toName,
              user.getEmailAddress(),
              user.getFullName()
            });

    InternetAddress from = new InternetAddress(fromAddress, fromName);

    InternetAddress to = new InternetAddress(toAddress, toName);

    MailMessage message = new MailMessage(from, to, subject, body, true);

    mailService.sendEmail(message);
  }