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;
  }
  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();
  }
Exemple #4
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);
  }