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.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    }