001    /**
002     * Copyright (c) 2000-2013 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.grouppages;
016    
017    import com.liferay.portal.model.Group;
018    import com.liferay.portal.model.Portlet;
019    import com.liferay.portal.model.RoleConstants;
020    import com.liferay.portal.security.permission.ActionKeys;
021    import com.liferay.portal.security.permission.PermissionChecker;
022    import com.liferay.portal.service.RoleLocalServiceUtil;
023    import com.liferay.portal.service.permission.GroupPermissionUtil;
024    import com.liferay.portal.util.PropsValues;
025    import com.liferay.portlet.BaseControlPanelEntry;
026    
027    /**
028     * @author Jorge Ferrer
029     * @author Sergio Gonz??lez
030     * @author Tibor Lipusz
031     */
032    public class GroupPagesControlPanelEntry extends BaseControlPanelEntry {
033    
034            @Override
035            protected boolean hasAccessPermissionDenied(
036                            PermissionChecker permissionChecker, Group group, Portlet portlet)
037                    throws Exception {
038    
039                    if (group.isUser()) {
040                            return hasUserLayoutsAccesPermissionDenied(permissionChecker);
041                    }
042    
043                    return group.isCompany();
044            }
045    
046            @Override
047            protected boolean hasPermissionImplicitlyGranted(
048                            PermissionChecker permissionChecker, Group group, Portlet portlet)
049                    throws Exception {
050    
051                    if (group.isUser()) {
052                            return super.hasAccessPermissionExplicitlyGranted(
053                                    permissionChecker, group, portlet);
054                    }
055    
056                    return GroupPermissionUtil.contains(
057                            permissionChecker, group.getGroupId(), ActionKeys.MANAGE_LAYOUTS);
058            }
059    
060            protected boolean hasUserLayoutsAccesPermissionDenied(
061                            PermissionChecker permissionChecker)
062                    throws Exception {
063    
064                    if (!PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_ENABLED &&
065                            !PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_ENABLED) {
066    
067                            return true;
068                    }
069    
070                    if ((PropsValues.LAYOUT_USER_PRIVATE_LAYOUTS_POWER_USER_REQUIRED ||
071                             PropsValues.LAYOUT_USER_PUBLIC_LAYOUTS_POWER_USER_REQUIRED) &&
072                            !RoleLocalServiceUtil.hasUserRole(
073                                    permissionChecker.getUserId(), permissionChecker.getCompanyId(),
074                                    RoleConstants.POWER_USER, true)) {
075    
076                            return true;
077                    }
078    
079                    return false;
080            }
081    
082    }