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 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 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; }
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); }