001
014
015 package com.liferay.portlet.usersadmin;
016
017 import com.liferay.portal.model.Organization;
018 import com.liferay.portal.model.Portlet;
019 import com.liferay.portal.model.Role;
020 import com.liferay.portal.model.RoleConstants;
021 import com.liferay.portal.model.UserGroupRole;
022 import com.liferay.portal.security.permission.ActionKeys;
023 import com.liferay.portal.security.permission.PermissionChecker;
024 import com.liferay.portal.service.OrganizationLocalServiceUtil;
025 import com.liferay.portal.service.UserGroupRoleLocalServiceUtil;
026 import com.liferay.portal.service.permission.OrganizationPermissionUtil;
027 import com.liferay.portlet.BaseControlPanelEntry;
028
029 import java.util.List;
030
031
034 public class UsersControlPanelEntry extends BaseControlPanelEntry {
035
036 @Override
037 public boolean isVisible(
038 PermissionChecker permissionChecker, Portlet portlet)
039 throws Exception {
040
041 List<UserGroupRole> userGroupRoles =
042 UserGroupRoleLocalServiceUtil.getUserGroupRoles(
043 permissionChecker.getUserId());
044
045 for (UserGroupRole userGroupRole : userGroupRoles) {
046 Role role = userGroupRole.getRole();
047
048 String roleName = role.getName();
049
050 if (roleName.equals(RoleConstants.ORGANIZATION_ADMINISTRATOR) ||
051 roleName.equals(RoleConstants.ORGANIZATION_OWNER)) {
052
053 return true;
054 }
055 }
056
057 List<Organization> organizations =
058 OrganizationLocalServiceUtil.getUserOrganizations(
059 permissionChecker.getUserId());
060
061 for (Organization organization : organizations) {
062 if (OrganizationPermissionUtil.contains(
063 permissionChecker, organization.getOrganizationId(),
064 ActionKeys.MANAGE_USERS)) {
065
066 return true;
067 }
068
069 if (OrganizationPermissionUtil.contains(
070 permissionChecker, organization.getOrganizationId(),
071 ActionKeys.MANAGE_SUBORGANIZATIONS)) {
072
073 return true;
074 }
075
076
082 }
083
084 return false;
085 }
086
087 }