1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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   */
32  public class UsersControlPanelEntry extends BaseControlPanelEntry {
33  
34      public boolean isVisible(
35              PermissionChecker permissionChecker, Portlet portlet)
36          throws Exception {
37  
38          List<Organization> organizations =
39              OrganizationLocalServiceUtil.getUserOrganizations(
40                  permissionChecker.getUserId());
41  
42          for (Organization organization : organizations) {
43              if (OrganizationPermissionUtil.contains(
44                      permissionChecker, organization.getOrganizationId(),
45                      ActionKeys.MANAGE_USERS)) {
46  
47                  return true;
48              }
49  
50              if (OrganizationPermissionUtil.contains(
51                      permissionChecker, organization.getOrganizationId(),
52                      ActionKeys.MANAGE_SUBORGANIZATIONS)) {
53  
54                  return true;
55              }
56          }
57  
58          return false;
59      }
60  
61  }