1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portlet.enterpriseadmin;
16  
17  import com.liferay.portal.model.Organization;
18  import com.liferay.portal.model.Portlet;
19  import com.liferay.portal.security.permission.ActionKeys;
20  import com.liferay.portal.security.permission.PermissionChecker;
21  import com.liferay.portal.service.OrganizationLocalServiceUtil;
22  import com.liferay.portal.service.permission.OrganizationPermissionUtil;
23  import com.liferay.portlet.BaseControlPanelEntry;
24  
25  import java.util.List;
26  
27  /**
28   * <a href="UsersControlPanelEntry.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Jorge Ferrer
31   * @author Daeyoung Song
32   */
33  public class UsersControlPanelEntry extends BaseControlPanelEntry {
34  
35      public boolean isVisible(
36              PermissionChecker permissionChecker, Portlet portlet)
37          throws Exception {
38  
39          List<Organization> organizations =
40              OrganizationLocalServiceUtil.getUserOrganizations(
41                  permissionChecker.getUserId());
42  
43          for (Organization organization : organizations) {
44              if (OrganizationPermissionUtil.contains(
45                      permissionChecker, organization.getOrganizationId(),
46                      ActionKeys.MANAGE_USERS)) {
47  
48                  return true;
49              }
50  
51              if (OrganizationPermissionUtil.contains(
52                      permissionChecker, organization.getOrganizationId(),
53                      ActionKeys.MANAGE_SUBORGANIZATIONS)) {
54  
55                  return true;
56              }
57  
58              if (OrganizationPermissionUtil.contains(
59                      permissionChecker, organization.getOrganizationId(),
60                      ActionKeys.VIEW)) {
61  
62                  return true;
63              }
64          }
65  
66          return false;
67      }
68  
69  }