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;
16  
17  import com.liferay.portal.model.Group;
18  import com.liferay.portal.model.LayoutConstants;
19  import com.liferay.portal.model.Portlet;
20  import com.liferay.portal.security.permission.ActionKeys;
21  import com.liferay.portal.security.permission.PermissionChecker;
22  import com.liferay.portal.service.permission.PortletPermissionUtil;
23  import com.liferay.portal.theme.ThemeDisplay;
24  import com.liferay.portal.util.PortletCategoryKeys;
25  
26  /**
27   * <a href="BaseControlPanelEntry.java.html"><b><i>View Source</i></b></a>
28   *
29   * @author Jorge Ferrer
30   */
31  public abstract class BaseControlPanelEntry implements ControlPanelEntry {
32  
33      public boolean isVisible(
34              Portlet portlet, String category, ThemeDisplay themeDisplay)
35          throws Exception {
36  
37          PermissionChecker permissionChecker =
38              themeDisplay.getPermissionChecker();
39  
40          if (permissionChecker.isCompanyAdmin()) {
41              return true;
42          }
43  
44          Group group = themeDisplay.getScopeGroup();
45  
46          long plid = LayoutConstants.DEFAULT_PLID;
47  
48          if (category.equals(PortletCategoryKeys.CONTENT)) {
49              plid = group.getDefaultPublicPlid();
50  
51              if (plid == LayoutConstants.DEFAULT_PLID) {
52                  plid = group.getDefaultPrivatePlid();
53              }
54          }
55  
56          if (category.equals(PortletCategoryKeys.CONTENT) &&
57              permissionChecker.isCommunityAdmin(group.getGroupId()) &&
58              !group.isUser()) {
59  
60              return true;
61          }
62  
63          long groupId = group.getGroupId();
64  
65          if (category.equals(PortletCategoryKeys.PORTAL) ||
66              category.equals(PortletCategoryKeys.SERVER)) {
67  
68              groupId = 0;
69          }
70  
71          if (PortletPermissionUtil.contains(
72                  permissionChecker, groupId, plid, portlet.getPortletId(),
73                  ActionKeys.ACCESS_IN_CONTROL_PANEL, true)) {
74  
75              return true;
76          }
77  
78          return isVisible(themeDisplay.getPermissionChecker(), portlet);
79      }
80  
81  }