001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet;
016    
017    import com.liferay.portal.model.Group;
018    import com.liferay.portal.model.LayoutConstants;
019    import com.liferay.portal.model.Portlet;
020    import com.liferay.portal.security.permission.ActionKeys;
021    import com.liferay.portal.security.permission.PermissionChecker;
022    import com.liferay.portal.service.permission.PortletPermissionUtil;
023    import com.liferay.portal.theme.ThemeDisplay;
024    import com.liferay.portal.util.PortletCategoryKeys;
025    
026    /**
027     * @author Jorge Ferrer
028     */
029    public abstract class BaseControlPanelEntry implements ControlPanelEntry {
030    
031            public boolean isVisible(
032                            Portlet portlet, String category, ThemeDisplay themeDisplay)
033                    throws Exception {
034    
035                    PermissionChecker permissionChecker =
036                            themeDisplay.getPermissionChecker();
037    
038                    if (permissionChecker.isCompanyAdmin()) {
039                            return true;
040                    }
041    
042                    Group group = themeDisplay.getScopeGroup();
043    
044                    long plid = LayoutConstants.DEFAULT_PLID;
045    
046                    if (category.equals(PortletCategoryKeys.CONTENT)) {
047                            plid = group.getDefaultPublicPlid();
048    
049                            if (plid == LayoutConstants.DEFAULT_PLID) {
050                                    plid = group.getDefaultPrivatePlid();
051                            }
052                    }
053    
054                    if (category.equals(PortletCategoryKeys.CONTENT) &&
055                            permissionChecker.isCommunityAdmin(group.getGroupId())) {
056    
057                            return true;
058                    }
059    
060                    if (PortletPermissionUtil.contains(
061                                    permissionChecker, plid, portlet.getPortletId(),
062                                    ActionKeys.ACCESS_IN_CONTROL_PANEL, true)) {
063    
064                            return true;
065                    }
066    
067                    return isVisible(themeDisplay.getPermissionChecker(), portlet);
068            }
069    
070    }