private static LayoutSet _getParentLayoutSet(LayoutSet layoutSet) throws Exception { Group group = layoutSet.getGroup(); if (group.isSite()) { Group parentGroup = group.getParentGroup(); if (parentGroup != null) { return LayoutSetLocalServiceUtil.getLayoutSet( parentGroup.getGroupId(), layoutSet.isPrivateLayout()); } } else if (group.isUser()) { User user = UserLocalServiceUtil.getUser(group.getClassPK()); List<Organization> organizations = OrganizationLocalServiceUtil.getUserOrganizations(user.getUserId()); if (!organizations.isEmpty()) { Organization organization = organizations.get(0); Group parentGroup = organization.getGroup(); return LayoutSetLocalServiceUtil.getLayoutSet( parentGroup.getGroupId(), layoutSet.isPrivateLayout()); } } return null; }
@Override public boolean contains( PermissionChecker permissionChecker, long userId, long[] organizationIds, String actionId) { try { User user = null; if (userId != ResourceConstants.PRIMKEY_DNE) { user = UserLocalServiceUtil.getUserById(userId); if ((actionId.equals(ActionKeys.DELETE) || actionId.equals(ActionKeys.IMPERSONATE) || actionId.equals(ActionKeys.PERMISSIONS) || actionId.equals(ActionKeys.UPDATE) || actionId.equals(ActionKeys.VIEW)) && !permissionChecker.isOmniadmin() && (PortalUtil.isOmniadmin(user) || (!permissionChecker.isCompanyAdmin() && PortalUtil.isCompanyAdmin(user)))) { return false; } Contact contact = user.getContact(); if (permissionChecker.hasOwnerPermission( permissionChecker.getCompanyId(), User.class.getName(), userId, contact.getUserId(), actionId) || (permissionChecker.getUserId() == userId)) { return true; } } if (permissionChecker.hasPermission(0, User.class.getName(), userId, actionId)) { return true; } if (user == null) { return false; } if (organizationIds == null) { organizationIds = user.getOrganizationIds(); } for (long organizationId : organizationIds) { Organization organization = OrganizationLocalServiceUtil.getOrganization(organizationId); if (OrganizationPermissionUtil.contains( permissionChecker, organization, ActionKeys.MANAGE_USERS)) { if (permissionChecker.getUserId() == user.getUserId()) { return true; } Group organizationGroup = organization.getGroup(); // Organization administrators can only manage normal users. // Owners can only manage normal users and administrators. if (UserGroupRoleLocalServiceUtil.hasUserGroupRole( user.getUserId(), organizationGroup.getGroupId(), RoleConstants.ORGANIZATION_OWNER, true)) { continue; } else if (UserGroupRoleLocalServiceUtil.hasUserGroupRole( user.getUserId(), organizationGroup.getGroupId(), RoleConstants.ORGANIZATION_ADMINISTRATOR, true) && !UserGroupRoleLocalServiceUtil.hasUserGroupRole( permissionChecker.getUserId(), organizationGroup.getGroupId(), RoleConstants.ORGANIZATION_OWNER, true)) { continue; } return true; } } } catch (Exception e) { _log.error(e, e); } return false; }