protected List<Group> filterGroups(List<Group> groups) throws PortalException { List<Group> filteredGroups = new ArrayList<>(); for (Group group : groups) { if (GroupPermissionUtil.contains(getPermissionChecker(), group, ActionKeys.VIEW)) { filteredGroups.add(group); } } return filteredGroups; }
@Override public boolean isScopeIdSelectable( PermissionChecker permissionChecker, String scopeId, long companyGroupId, Layout layout) throws PortalException, SystemException { long groupId = getGroupIdFromScopeId(scopeId, layout.getGroupId(), layout.isPrivateLayout()); if (scopeId.startsWith(SCOPE_ID_CHILD_GROUP_PREFIX)) { Group group = GroupLocalServiceUtil.getGroup(groupId); if (!group.hasAncestor(layout.getGroupId())) { return false; } } else if (scopeId.startsWith(SCOPE_ID_PARENT_GROUP_PREFIX)) { Group siteGroup = layout.getGroup(); if (!siteGroup.hasAncestor(groupId)) { return false; } if (SitesUtil.isContentSharingWithChildrenEnabled(siteGroup)) { return true; } if (!PrefsPropsUtil.getBoolean( layout.getCompanyId(), PropsKeys.SITES_CONTENT_SHARING_THROUGH_ADMINISTRATORS_ENABLED)) { return false; } return GroupPermissionUtil.contains(permissionChecker, groupId, ActionKeys.UPDATE); } else if (groupId != companyGroupId) { return GroupPermissionUtil.contains(permissionChecker, groupId, ActionKeys.UPDATE); } return true; }
@Override protected boolean hasPermissionImplicitlyGranted( PermissionChecker permissionChecker, Group group, Portlet portlet) throws Exception { return GroupPermissionUtil.contains(permissionChecker, group, ActionKeys.MANAGE_LAYOUTS); }
/** * Returns the user's groups "sites" associated with the group entity class names, * including the Control Panel group if the user is permitted to view the Control Panel. * * <ul> * <li>Class name "User" includes the user's layout set group. * <li>Class name "Organization" includes the user's immediate organization groups and * inherited organization groups. * <li>Class name "Group" includes the user's immediate organization groups and site * groups. * <li>A <code>classNames</code> value of <code>null</code> includes the user's layout set * group, organization groups, inherited organization groups, and site groups. * </ul> * * @param userId the primary key of the user * @param classNames the group entity class names (optionally <code>null</code>). For more * information see {@link #getUserSitesGroups(long, String[], int)}. * @param max the maximum number of groups to return * @return the user's groups "sites" * @throws PortalException if a portal exception occurred */ @Override public List<Group> getUserSitesGroups(long userId, String[] classNames, int max) throws PortalException { User user = userPersistence.findByPrimaryKey(userId); if (user.isDefaultUser()) { return Collections.emptyList(); } Set<Group> userSiteGroups = new LinkedHashSet<>(); if (classNames == null) { classNames = new String[] { Company.class.getName(), Group.class.getName(), Organization.class.getName(), User.class.getName() }; } if (ArrayUtil.contains(classNames, User.class.getName())) { if (PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_ENABLED || PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_ENABLED) { userSiteGroups.add(user.getGroup()); if (userSiteGroups.size() == max) { return new ArrayList<>(userSiteGroups); } } } if (ArrayUtil.contains(classNames, Company.class.getName())) { Group companyGroup = groupLocalService.getCompanyGroup(user.getCompanyId()); if (GroupPermissionUtil.contains( getPermissionChecker(), companyGroup, ActionKeys.VIEW_SITE_ADMINISTRATION)) { userSiteGroups.add(companyGroup); if (userSiteGroups.size() == max) { return new ArrayList<>(userSiteGroups); } } } if (ArrayUtil.contains(classNames, Group.class.getName()) || ArrayUtil.contains(classNames, Organization.class.getName())) { UserBag userBag = UserBagFactoryUtil.create(userId); if (ArrayUtil.contains(classNames, Group.class.getName())) { for (Group group : userBag.getUserGroups()) { if (group.isActive() && group.isSite()) { if (userSiteGroups.add(group) && (userSiteGroups.size() == max)) { return new ArrayList<>(userSiteGroups); } } } } if (ArrayUtil.contains(classNames, Organization.class.getName())) { for (Group group : userBag.getUserOrgGroups()) { if (group.isActive() && group.isSite()) { if (userSiteGroups.add(group) && (userSiteGroups.size() == max)) { return new ArrayList<>(userSiteGroups); } } } } } return new ArrayList<>(userSiteGroups); }
protected Organization updateOrganization(ActionRequest actionRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long organizationId = ParamUtil.getLong(actionRequest, "organizationId"); long parentOrganizationId = ParamUtil.getLong( actionRequest, "parentOrganizationSearchContainerPrimaryKeys", OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID); String name = ParamUtil.getString(actionRequest, "name"); int statusId = ParamUtil.getInteger(actionRequest, "statusId"); String type = ParamUtil.getString(actionRequest, "type"); long regionId = ParamUtil.getLong(actionRequest, "regionId"); long countryId = ParamUtil.getLong(actionRequest, "countryId"); String comments = ParamUtil.getString(actionRequest, "comments"); boolean deleteLogo = ParamUtil.getBoolean(actionRequest, "deleteLogo"); byte[] logoBytes = null; long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId"); if (fileEntryId > 0) { FileEntry fileEntry = DLAppLocalServiceUtil.getFileEntry(fileEntryId); logoBytes = FileUtil.getBytes(fileEntry.getContentStream()); } boolean site = ParamUtil.getBoolean(actionRequest, "site"); List<Address> addresses = UsersAdminUtil.getAddresses(actionRequest); List<EmailAddress> emailAddresses = UsersAdminUtil.getEmailAddresses(actionRequest); List<OrgLabor> orgLabors = UsersAdminUtil.getOrgLabors(actionRequest); List<Phone> phones = UsersAdminUtil.getPhones(actionRequest); List<Website> websites = UsersAdminUtil.getWebsites(actionRequest); ServiceContext serviceContext = ServiceContextFactory.getInstance(Organization.class.getName(), actionRequest); Organization organization = null; if (organizationId <= 0) { // Add organization organization = OrganizationServiceUtil.addOrganization( parentOrganizationId, name, type, regionId, countryId, statusId, comments, site, addresses, emailAddresses, orgLabors, phones, websites, serviceContext); } else { // Update organization organization = OrganizationServiceUtil.updateOrganization( organizationId, parentOrganizationId, name, type, regionId, countryId, statusId, comments, !deleteLogo, logoBytes, site, addresses, emailAddresses, orgLabors, phones, websites, serviceContext); } // Layout set prototypes long publicLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "publicLayoutSetPrototypeId"); long privateLayoutSetPrototypeId = ParamUtil.getLong(actionRequest, "privateLayoutSetPrototypeId"); boolean publicLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean( actionRequest, "publicLayoutSetPrototypeLinkEnabled", (publicLayoutSetPrototypeId > 0)); boolean privateLayoutSetPrototypeLinkEnabled = ParamUtil.getBoolean( actionRequest, "privateLayoutSetPrototypeLinkEnabled", (privateLayoutSetPrototypeId > 0)); Group organizationGroup = organization.getGroup(); if (GroupPermissionUtil.contains( themeDisplay.getPermissionChecker(), organizationGroup, ActionKeys.UPDATE)) { SitesUtil.updateLayoutSetPrototypesLinks( organizationGroup, publicLayoutSetPrototypeId, privateLayoutSetPrototypeId, publicLayoutSetPrototypeLinkEnabled, privateLayoutSetPrototypeLinkEnabled); } // Reminder queries String reminderQueries = actionRequest.getParameter("reminderQueries"); PortletPreferences portletPreferences = organization.getPreferences(); LocalizationUtil.setLocalizedPreferencesValues( actionRequest, portletPreferences, "reminderQueries"); portletPreferences.setValue("reminderQueries", reminderQueries); portletPreferences.store(); return organization; }
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); }