protected int[] getRoleTypes(long companyId, Group group, String modelResource) {

    int[] types = RoleConstants.TYPES_REGULAR_AND_SITE;

    if (isPortalModelResource(modelResource)) {
      if (modelResource.equals(Organization.class.getName())
          || modelResource.equals(User.class.getName())) {

        types = RoleConstants.TYPES_ORGANIZATION_AND_REGULAR;
      } else {
        types = RoleConstants.TYPES_REGULAR;
      }
    } else {
      if (group != null) {
        if (group.isLayout()) {
          try {
            group = GroupServiceUtil.getGroup(group.getParentGroupId());
          } catch (Exception e) {
          }
        }

        if (group.isOrganization()) {
          types = RoleConstants.TYPES_ORGANIZATION_AND_REGULAR_AND_SITE;
        } else if (group.isUser()) {
          types = RoleConstants.TYPES_REGULAR;
        }
      }
    }

    return types;
  }
  protected String[] getStaticPortletIds(String position) throws PortalException {

    Layout layout = getLayout();

    String selector1 = StringPool.BLANK;

    Group group = layout.getGroup();

    if (group.isUser()) {
      selector1 = LayoutTypePortletConstants.STATIC_PORTLET_USER_SELECTOR;
    } else if (group.isOrganization()) {
      selector1 = LayoutTypePortletConstants.STATIC_PORTLET_ORGANIZATION_SELECTOR;
    } else if (group.isRegularSite()) {
      selector1 = LayoutTypePortletConstants.STATIC_PORTLET_REGULAR_SITE_SELECTOR;
    }

    String selector2 = layout.getFriendlyURL();

    String[] portletIds = PropsUtil.getArray(position, new Filter(selector1, selector2));

    for (int i = 0; i < portletIds.length; i++) {
      portletIds[i] = JS.getSafeName(portletIds[i]);
    }

    return portletIds;
  }
  /**
   * Returns the default role for the group with the primary key.
   *
   * <p>If the group is a site, then the default role is {@link
   * com.liferay.portal.model.RoleConstants#SITE_MEMBER}. If the group is an organization, then the
   * default role is {@link com.liferay.portal.model.RoleConstants#ORGANIZATION_USER}. If the group
   * is a user or user group, then the default role is {@link
   * com.liferay.portal.model.RoleConstants#POWER_USER}. For all other group types, the default role
   * is {@link com.liferay.portal.model.RoleConstants#USER}.
   *
   * @param groupId the primary key of the group
   * @return the default role for the group with the primary key
   * @throws PortalException if a group with the primary key could not be found, or if a default
   *     role could not be found for the group
   * @throws SystemException if a system exception occurred
   */
  public Role getDefaultGroupRole(long groupId) throws PortalException, SystemException {

    Group group = groupPersistence.findByPrimaryKey(groupId);

    if (group.isLayout()) {
      Layout layout = layoutLocalService.getLayout(group.getClassPK());

      group = layout.getGroup();
    }

    if (group.isStagingGroup()) {
      group = group.getLiveGroup();
    }

    Role role = null;

    if (group.isCompany()) {
      role = getRole(group.getCompanyId(), RoleConstants.USER);
    } else if (group.isLayoutPrototype()
        || group.isLayoutSetPrototype()
        || group.isRegularSite()
        || group.isSite()) {

      role = getRole(group.getCompanyId(), RoleConstants.SITE_MEMBER);
    } else if (group.isOrganization()) {
      role = getRole(group.getCompanyId(), RoleConstants.ORGANIZATION_USER);
    } else if (group.isUser() || group.isUserGroup()) {
      role = getRole(group.getCompanyId(), RoleConstants.POWER_USER);
    } else {
      role = getRole(group.getCompanyId(), RoleConstants.USER);
    }

    return role;
  }
  private void _buildParentGroupsBreadcrumb(
      LayoutSet layoutSet, PortletURL portletURL, ThemeDisplay themeDisplay, StringBundler sb)
      throws Exception {
    Group group = layoutSet.getGroup();

    if (group.isOrganization()) {
      Organization organization =
          OrganizationLocalServiceUtil.getOrganization(group.getOrganizationId());

      Organization parentOrganization = organization.getParentOrganization();

      if (parentOrganization != null) {
        Group parentGroup = parentOrganization.getGroup();

        LayoutSet parentLayoutSet =
            LayoutSetLocalServiceUtil.getLayoutSet(
                parentGroup.getGroupId(), layoutSet.isPrivateLayout());

        _buildParentGroupsBreadcrumb(parentLayoutSet, portletURL, themeDisplay, sb);
      }
    } else if (group.isUser()) {
      User groupUser = UserLocalServiceUtil.getUser(group.getClassPK());

      List<Organization> organizations =
          OrganizationLocalServiceUtil.getUserOrganizations(groupUser.getUserId(), true);

      if (!organizations.isEmpty()) {
        Organization organization = organizations.get(0);

        Group parentGroup = organization.getGroup();

        LayoutSet parentLayoutSet =
            LayoutSetLocalServiceUtil.getLayoutSet(
                parentGroup.getGroupId(), layoutSet.isPrivateLayout());

        _buildParentGroupsBreadcrumb(parentLayoutSet, portletURL, themeDisplay, sb);
      }
    }

    int layoutsPageCount = 0;

    if (layoutSet.isPrivateLayout()) {
      layoutsPageCount = group.getPrivateLayoutsPageCount();
    } else {
      layoutsPageCount = group.getPublicLayoutsPageCount();
    }

    if ((layoutsPageCount > 0) && !group.getName().equals(GroupConstants.GUEST)) {
      String layoutSetFriendlyURL = PortalUtil.getLayoutSetFriendlyURL(layoutSet, themeDisplay);

      sb.append("<li><span><a href=\"");
      sb.append(layoutSetFriendlyURL);
      sb.append("\">");
      sb.append(HtmlUtil.escape(group.getDescriptiveName()));
      sb.append("</a></span></li>");
    }
  }
  protected void addRequiredMemberRole(Group group, BooleanQuery permissionQuery) throws Exception {

    if (group.isOrganization()) {
      Role organizationUserRole =
          RoleLocalServiceUtil.getRole(group.getCompanyId(), RoleConstants.ORGANIZATION_USER);

      permissionQuery.addTerm(
          Field.GROUP_ROLE_ID,
          group.getGroupId() + StringPool.DASH + organizationUserRole.getRoleId());
    }

    if (group.isSite()) {
      Role siteMemberRole =
          RoleLocalServiceUtil.getRole(group.getCompanyId(), RoleConstants.SITE_MEMBER);

      permissionQuery.addTerm(
          Field.GROUP_ROLE_ID, group.getGroupId() + StringPool.DASH + siteMemberRole.getRoleId());
    }
  }
  protected List<SocialActivity> getSocialActivities(ResourceRequest resourceRequest, int max)
      throws Exception {

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

    Group group = _groupLocalService.getGroup(themeDisplay.getScopeGroupId());

    int start = 0;

    if (group.isOrganization()) {
      return _socialActivityLocalService.getOrganizationActivities(
          group.getOrganizationId(), start, max);
    } else if (group.isRegularSite()) {
      return _socialActivityLocalService.getGroupActivities(group.getGroupId(), start, max);
    } else if (group.isUser()) {
      return _socialActivityLocalService.getUserActivities(group.getClassPK(), start, max);
    }

    return Collections.emptyList();
  }
  public void addPermissions(String resourceName, long resourcePK)
      throws PortalException, SystemException {

    if (!MapUtil.getBoolean(_parameterMap, PortletDataHandlerKeys.PERMISSIONS)) {

      return;
    }

    List<KeyValuePair> permissions = new ArrayList<KeyValuePair>();

    Group group = GroupLocalServiceUtil.getGroup(_groupId);

    List<Role> roles = RoleLocalServiceUtil.getRoles(_companyId);

    PrimitiveLongList roleIds = new PrimitiveLongList(roles.size());
    Map<Long, String> roleIdsToNames = new HashMap<Long, String>();

    for (Role role : roles) {
      int type = role.getType();

      if ((type == RoleConstants.TYPE_REGULAR)
          || ((type == RoleConstants.TYPE_ORGANIZATION) && group.isOrganization())
          || ((type == RoleConstants.TYPE_SITE)
              && (group.isLayoutSetPrototype() || group.isSite()))) {

        String name = role.getName();

        roleIds.add(role.getRoleId());
        roleIdsToNames.put(role.getRoleId(), name);
      } else if ((type == RoleConstants.TYPE_PROVIDER) && role.isTeam()) {
        Team team = TeamLocalServiceUtil.getTeam(role.getClassPK());

        if (team.getGroupId() == _groupId) {
          String name = PermissionExporter.ROLE_TEAM_PREFIX + team.getName();

          roleIds.add(role.getRoleId());
          roleIdsToNames.put(role.getRoleId(), name);
        }
      }
    }

    List<String> actionIds = ResourceActionsUtil.getModelResourceActions(resourceName);

    Map<Long, Set<String>> roleIdsToActionIds =
        getActionIds(_companyId, roleIds.getArray(), resourceName, resourcePK, actionIds);

    for (Map.Entry<Long, String> entry : roleIdsToNames.entrySet()) {
      long roleId = entry.getKey();
      String name = entry.getValue();

      Set<String> availableActionIds = roleIdsToActionIds.get(roleId);

      if ((availableActionIds == null) || availableActionIds.isEmpty()) {
        continue;
      }

      KeyValuePair permission = new KeyValuePair(name, StringUtil.merge(availableActionIds));

      permissions.add(permission);
    }

    _permissionsMap.put(getPrimaryKeyString(resourceName, resourcePK), permissions);
  }
  public List<User> findByC_FN_MN_LN_SN_EA_S(
      long companyId,
      String[] firstNames,
      String[] middleNames,
      String[] lastNames,
      String[] screenNames,
      String[] emailAddresses,
      int status,
      LinkedHashMap<String, Object> params,
      boolean andOperator,
      int start,
      int end,
      OrderByComparator obc)
      throws SystemException {

    firstNames = CustomSQLUtil.keywords(firstNames);
    middleNames = CustomSQLUtil.keywords(middleNames);
    lastNames = CustomSQLUtil.keywords(lastNames);
    screenNames = CustomSQLUtil.keywords(screenNames);
    emailAddresses = CustomSQLUtil.keywords(emailAddresses);

    if (params == null) {
      params = _emptyLinkedHashMap;
    }

    Long[] groupIds = null;

    if (params.get("usersGroups") instanceof Long) {
      Long groupId = (Long) params.get("usersGroups");

      if (groupId > 0) {
        groupIds = new Long[] {groupId};
      }
    } else {
      groupIds = (Long[]) params.get("usersGroups");
    }

    boolean inherit = GetterUtil.getBoolean(params.get("inherit"));

    boolean doUnion = Validator.isNotNull(groupIds) && inherit;

    LinkedHashMap<String, Object> params1 = params;

    LinkedHashMap<String, Object> params2 = null;

    LinkedHashMap<String, Object> params3 = null;

    if (doUnion) {
      params2 = new LinkedHashMap<String, Object>(params1);

      params2.remove("usersGroups");

      params3 = new LinkedHashMap<String, Object>(params1);

      params3.remove("usersGroups");

      List<Long> organizationIds = new ArrayList<Long>();
      List<Long> userGroupIds = new ArrayList<Long>();

      for (long groupId : groupIds) {
        Group group = GroupLocalServiceUtil.fetchGroup(groupId);

        if ((group != null) && group.isOrganization()) {
          organizationIds.add(group.getOrganizationId());
        }

        List<Organization> organizations = GroupUtil.getOrganizations(groupId);

        for (Organization organization : organizations) {
          organizationIds.add(organization.getOrganizationId());
        }

        List<UserGroup> userGroups = GroupUtil.getUserGroups(groupId);

        for (int i = 0; i < userGroups.size(); i++) {
          UserGroup userGroup = userGroups.get(i);

          userGroupIds.add(userGroup.getUserGroupId());
        }
      }

      params2.put("usersOrgs", organizationIds.toArray(new Long[organizationIds.size()]));

      params3.put("usersUserGroups", userGroupIds.toArray(new Long[userGroupIds.size()]));
    }

    Session session = null;

    try {
      session = openSession();

      String sql = CustomSQLUtil.get(FIND_BY_C_FN_MN_LN_SN_EA_S);

      sql =
          CustomSQLUtil.replaceKeywords(
              sql, "lower(User_.firstName)", StringPool.LIKE, false, firstNames);
      sql =
          CustomSQLUtil.replaceKeywords(
              sql, "lower(User_.middleName)", StringPool.LIKE, false, middleNames);
      sql =
          CustomSQLUtil.replaceKeywords(
              sql, "lower(User_.lastName)", StringPool.LIKE, false, lastNames);
      sql =
          CustomSQLUtil.replaceKeywords(
              sql, "lower(User_.screenName)", StringPool.LIKE, false, screenNames);
      sql =
          CustomSQLUtil.replaceKeywords(
              sql, "lower(User_.emailAddress)", StringPool.LIKE, true, emailAddresses);

      if (status == WorkflowConstants.STATUS_ANY) {
        sql = StringUtil.replace(sql, _STATUS_SQL, StringPool.BLANK);
      }

      StringBundler sb = new StringBundler();

      sb.append(StringPool.OPEN_PARENTHESIS);
      sb.append(replaceJoinAndWhere(sql, params1));
      sb.append(StringPool.CLOSE_PARENTHESIS);

      if (doUnion) {
        sb.append(" UNION (");
        sb.append(replaceJoinAndWhere(sql, params2));
        sb.append(") UNION (");
        sb.append(replaceJoinAndWhere(sql, params3));
        sb.append(StringPool.CLOSE_PARENTHESIS);
      }

      if (obc != null) {
        sb.append(" ORDER BY ");
        sb.append(obc.toString());
      }

      sql = sb.toString();

      sql = CustomSQLUtil.replaceAndOperator(sql, andOperator);

      SQLQuery q = session.createSQLQuery(sql);

      q.addScalar("userId", Type.LONG);

      QueryPos qPos = QueryPos.getInstance(q);

      setJoin(qPos, params1);

      qPos.add(companyId);
      qPos.add(false);
      qPos.add(firstNames, 2);
      qPos.add(middleNames, 2);
      qPos.add(lastNames, 2);
      qPos.add(screenNames, 2);
      qPos.add(emailAddresses, 2);

      if (status != WorkflowConstants.STATUS_ANY) {
        qPos.add(status);
      }

      if (doUnion) {
        setJoin(qPos, params2);

        qPos.add(companyId);
        qPos.add(false);
        qPos.add(firstNames, 2);
        qPos.add(middleNames, 2);
        qPos.add(lastNames, 2);
        qPos.add(screenNames, 2);
        qPos.add(emailAddresses, 2);

        if (status != WorkflowConstants.STATUS_ANY) {
          qPos.add(status);
        }

        setJoin(qPos, params3);

        qPos.add(companyId);
        qPos.add(false);
        qPos.add(firstNames, 2);
        qPos.add(middleNames, 2);
        qPos.add(lastNames, 2);
        qPos.add(screenNames, 2);
        qPos.add(emailAddresses, 2);

        if (status != WorkflowConstants.STATUS_ANY) {
          qPos.add(status);
        }
      }

      List<Long> userIds = (List<Long>) QueryUtil.list(q, getDialect(), start, end);

      List<User> users = new ArrayList<User>(userIds.size());

      for (Long userId : userIds) {
        User user = UserUtil.findByPrimaryKey(userId);

        users.add(user);
      }

      return users;
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
  public int countByC_FN_MN_LN_SN_EA_S(
      long companyId,
      String[] firstNames,
      String[] middleNames,
      String[] lastNames,
      String[] screenNames,
      String[] emailAddresses,
      int status,
      LinkedHashMap<String, Object> params,
      boolean andOperator)
      throws SystemException {

    firstNames = CustomSQLUtil.keywords(firstNames);
    middleNames = CustomSQLUtil.keywords(middleNames);
    lastNames = CustomSQLUtil.keywords(lastNames);
    screenNames = CustomSQLUtil.keywords(screenNames);
    emailAddresses = CustomSQLUtil.keywords(emailAddresses);

    if (params == null) {
      params = _emptyLinkedHashMap;
    }

    Long[] groupIds = null;

    if (params.get("usersGroups") instanceof Long) {
      Long groupId = (Long) params.get("usersGroups");

      if (groupId > 0) {
        groupIds = new Long[] {groupId};
      }
    } else {
      groupIds = (Long[]) params.get("usersGroups");
    }

    boolean inherit = GetterUtil.getBoolean(params.get("inherit"));

    boolean doUnion = Validator.isNotNull(groupIds) && inherit;

    LinkedHashMap<String, Object> params1 = params;

    LinkedHashMap<String, Object> params2 = null;

    LinkedHashMap<String, Object> params3 = null;

    if (doUnion) {
      params2 = new LinkedHashMap<String, Object>(params1);

      params2.remove("usersGroups");

      params3 = new LinkedHashMap<String, Object>(params1);

      params3.remove("usersGroups");

      List<Long> organizationIds = new ArrayList<Long>();
      List<Long> userGroupIds = new ArrayList<Long>();

      for (long groupId : groupIds) {
        Group group = GroupLocalServiceUtil.fetchGroup(groupId);

        if ((group != null) && group.isOrganization()) {
          organizationIds.add(group.getOrganizationId());
        }

        List<Organization> organizations = GroupUtil.getOrganizations(groupId);

        for (Organization organization : organizations) {
          organizationIds.add(organization.getOrganizationId());
        }

        List<UserGroup> userGroups = GroupUtil.getUserGroups(groupId);

        for (int i = 0; i < userGroups.size(); i++) {
          UserGroup userGroup = userGroups.get(i);

          userGroupIds.add(userGroup.getUserGroupId());
        }
      }

      params2.put("usersOrgs", organizationIds.toArray(new Long[organizationIds.size()]));

      params3.put("usersUserGroups", userGroupIds.toArray(new Long[userGroupIds.size()]));
    }

    Session session = null;

    try {
      session = openSession();

      Set<Long> userIds = new HashSet<Long>();

      userIds.addAll(
          countByC_FN_MN_LN_SN_EA_S(
              session,
              companyId,
              firstNames,
              middleNames,
              lastNames,
              screenNames,
              emailAddresses,
              status,
              params1,
              andOperator));

      if (doUnion) {
        userIds.addAll(
            countByC_FN_MN_LN_SN_EA_S(
                session,
                companyId,
                firstNames,
                middleNames,
                lastNames,
                screenNames,
                emailAddresses,
                status,
                params2,
                andOperator));

        userIds.addAll(
            countByC_FN_MN_LN_SN_EA_S(
                session,
                companyId,
                firstNames,
                middleNames,
                lastNames,
                screenNames,
                emailAddresses,
                status,
                params3,
                andOperator));
      }

      return userIds.size();
    } catch (Exception e) {
      throw new SystemException(e);
    } finally {
      closeSession(session);
    }
  }
  protected boolean isViewableGroup(
      PermissionChecker permissionChecker,
      Layout layout,
      String controlPanelCategory,
      boolean checkResourcePermission)
      throws PortalException, SystemException {

    Group group = GroupLocalServiceUtil.getGroup(layout.getGroupId());

    // Inactive sites are not viewable

    if (!group.isActive()) {
      return false;
    } else if (group.isStagingGroup()) {
      Group liveGroup = group.getLiveGroup();

      if (!liveGroup.isActive()) {
        return false;
      }
    }

    // User private layouts are only viewable by the user and anyone who can
    // update the user. The user must also be active.

    if (group.isUser()) {
      long groupUserId = group.getClassPK();

      if (groupUserId == permissionChecker.getUserId()) {
        return true;
      }

      User groupUser = UserLocalServiceUtil.getUserById(groupUserId);

      if (!groupUser.isActive()) {
        return false;
      }

      if (layout.isPrivateLayout()) {
        if (GroupPermissionUtil.contains(
                permissionChecker, groupUser.getGroupId(), ActionKeys.MANAGE_LAYOUTS)
            || UserPermissionUtil.contains(
                permissionChecker,
                groupUserId,
                groupUser.getOrganizationIds(),
                ActionKeys.UPDATE)) {

          return true;
        }

        return false;
      }
    }

    // If the current group is staging, only users with editorial rights
    // can access it

    if (group.isStagingGroup()) {
      if (GroupPermissionUtil.contains(
          permissionChecker, group.getGroupId(), ActionKeys.VIEW_STAGING)) {

        return true;
      }

      return false;
    }

    // Control panel layouts are only viewable by authenticated users

    if (group.isControlPanel()) {
      if (!permissionChecker.isSignedIn()) {
        return false;
      }

      if (PortalPermissionUtil.contains(permissionChecker, ActionKeys.VIEW_CONTROL_PANEL)) {

        return true;
      }

      if (Validator.isNotNull(controlPanelCategory)) {
        return true;
      }

      return false;
    }

    // Site layouts are only viewable by users who are members of the site
    // or by users who can update the site

    if (group.isSite()) {
      if (GroupPermissionUtil.contains(
              permissionChecker, group.getGroupId(), ActionKeys.MANAGE_LAYOUTS)
          || GroupPermissionUtil.contains(
              permissionChecker, group.getGroupId(), ActionKeys.UPDATE)) {

        return true;
      }

      if (layout.isPrivateLayout() && !permissionChecker.isGroupMember(group.getGroupId())) {

        return false;
      }
    }

    // Organization site layouts are also viewable by users who belong to
    // the organization or by users who can update organization

    if (group.isCompany()) {
      return false;
    } else if (group.isLayoutPrototype()) {
      if (LayoutPrototypePermissionUtil.contains(
          permissionChecker, group.getClassPK(), ActionKeys.VIEW)) {

        return true;
      }

      return false;
    } else if (group.isLayoutSetPrototype()) {
      if (LayoutSetPrototypePermissionUtil.contains(
          permissionChecker, group.getClassPK(), ActionKeys.VIEW)) {

        return true;
      }

      return false;
    } else if (group.isOrganization()) {
      long organizationId = group.getOrganizationId();

      if (OrganizationLocalServiceUtil.hasUserOrganization(
          permissionChecker.getUserId(), organizationId, false, false)) {

        return true;
      } else if (OrganizationPermissionUtil.contains(
          permissionChecker, organizationId, ActionKeys.UPDATE)) {

        return true;
      }

      if (!PropsValues.ORGANIZATIONS_MEMBERSHIP_STRICT) {
        List<Organization> userOrgs =
            OrganizationLocalServiceUtil.getUserOrganizations(permissionChecker.getUserId());

        for (Organization organization : userOrgs) {
          for (Organization ancestorOrganization : organization.getAncestors()) {

            if (organizationId == ancestorOrganization.getOrganizationId()) {

              return true;
            }
          }
        }
      }
    } else if (group.isUserGroup()) {
      if (UserGroupPermissionUtil.contains(
          permissionChecker, group.getClassPK(), ActionKeys.UPDATE)) {

        return true;
      }
    }

    // Only check the actual Layout if all of the above failed

    if (containsWithoutViewableGroup(
        permissionChecker, layout, controlPanelCategory, ActionKeys.VIEW)) {

      return true;
    }

    // As a last resort, check if any top level pages are viewable by the
    // user

    List<Layout> layouts =
        LayoutLocalServiceUtil.getLayouts(
            layout.getGroupId(),
            layout.isPrivateLayout(),
            LayoutConstants.DEFAULT_PARENT_LAYOUT_ID);

    for (Layout curLayout : layouts) {
      if (!curLayout.isHidden()
          && containsWithoutViewableGroup(
              permissionChecker, curLayout, controlPanelCategory, ActionKeys.VIEW)) {

        return true;
      }
    }

    return false;
  }
Exemple #11
0
  public static void getRole(HttpServletRequest request) throws Exception {
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);

    PermissionChecker permissionChecker = themeDisplay.getPermissionChecker();

    long roleId = ParamUtil.getLong(request, "roleId");

    Role role = null;

    Group group = (Group) request.getAttribute(WebKeys.GROUP);

    if ((group != null) && group.isOrganization()) {
      long organizationId = group.getOrganizationId();

      while (organizationId != OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID) {

        Organization organization = OrganizationLocalServiceUtil.getOrganization(organizationId);

        long organizationGroupId = organization.getGroupId();

        if (GroupPermissionUtil.contains(
                permissionChecker, organizationGroupId, ActionKeys.ASSIGN_USER_ROLES)
            || OrganizationPermissionUtil.contains(
                permissionChecker, organizationId, ActionKeys.ASSIGN_USER_ROLES)
            || UserGroupRoleLocalServiceUtil.hasUserGroupRole(
                themeDisplay.getUserId(),
                organizationGroupId,
                RoleConstants.ORGANIZATION_ADMINISTRATOR,
                true)
            || UserGroupRoleLocalServiceUtil.hasUserGroupRole(
                themeDisplay.getUserId(),
                organizationGroupId,
                RoleConstants.ORGANIZATION_OWNER,
                true)) {

          if (roleId > 0) {
            role = RoleLocalServiceUtil.getRole(roleId);
          }

          break;
        }

        organizationId = organization.getParentOrganizationId();
      }

      if ((roleId > 0) && (role == null)) {
        role = RoleServiceUtil.getRole(roleId);
      }
    } else if ((group != null) && group.isRegularSite()) {
      if (GroupPermissionUtil.contains(permissionChecker, group, ActionKeys.ASSIGN_USER_ROLES)
          || UserGroupRoleLocalServiceUtil.hasUserGroupRole(
              themeDisplay.getUserId(), group.getGroupId(), RoleConstants.SITE_ADMINISTRATOR, true)
          || UserGroupRoleLocalServiceUtil.hasUserGroupRole(
              themeDisplay.getUserId(), group.getGroupId(), RoleConstants.SITE_OWNER, true)) {

        if (roleId > 0) {
          role = RoleLocalServiceUtil.getRole(roleId);
        }
      } else {
        if (roleId > 0) {
          role = RoleServiceUtil.getRole(roleId);
        }
      }
    } else {
      if (roleId > 0) {
        role = RoleServiceUtil.getRole(roleId);
      }
    }

    request.setAttribute(WebKeys.ROLE, role);
  }