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;
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  
59              return true;
60          }
61  
62          if (PortletPermissionUtil.contains(
63                  permissionChecker, plid, portlet.getPortletId(),
64                  ActionKeys.ACCESS_IN_CONTROL_PANEL, true)) {
65  
66              return true;
67          }
68  
69          return isVisible(themeDisplay.getPermissionChecker(), portlet);
70      }
71  
72  }