001    /**
002     * Copyright (c) 2000-2013 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            @Override
032            public boolean isVisible(
033                            Portlet portlet, String category, ThemeDisplay themeDisplay)
034                    throws Exception {
035    
036                    PermissionChecker permissionChecker =
037                            themeDisplay.getPermissionChecker();
038    
039                    if (permissionChecker.isCompanyAdmin()) {
040                            return true;
041                    }
042    
043                    Group group = themeDisplay.getScopeGroup();
044    
045                    long plid = LayoutConstants.DEFAULT_PLID;
046    
047                    if (category.equals(PortletCategoryKeys.CONTENT)) {
048                            plid = group.getDefaultPublicPlid();
049    
050                            if (plid == LayoutConstants.DEFAULT_PLID) {
051                                    plid = group.getDefaultPrivatePlid();
052                            }
053                    }
054    
055                    if (category.equals(PortletCategoryKeys.CONTENT) &&
056                            permissionChecker.isGroupAdmin(group.getGroupId()) &&
057                            !group.isUser()) {
058    
059                            return true;
060                    }
061    
062                    long groupId = group.getGroupId();
063    
064                    if (category.equals(PortletCategoryKeys.PORTAL) ||
065                            category.equals(PortletCategoryKeys.SERVER)) {
066    
067                            groupId = 0;
068                    }
069    
070                    if (PortletPermissionUtil.contains(
071                                    permissionChecker, groupId, plid, portlet.getPortletId(),
072                                    ActionKeys.ACCESS_IN_CONTROL_PANEL, true)) {
073    
074                            return true;
075                    }
076    
077                    return isVisible(themeDisplay.getPermissionChecker(), portlet);
078            }
079    
080    }