001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }