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.portal.staging.permission;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.security.pacl.DoPrivileged;
020    import com.liferay.portal.kernel.staging.permission.StagingPermission;
021    import com.liferay.portal.model.Group;
022    import com.liferay.portal.security.permission.ActionKeys;
023    import com.liferay.portal.security.permission.PermissionChecker;
024    import com.liferay.portal.service.GroupLocalServiceUtil;
025    
026    /**
027     * @author Jorge Ferrer
028     */
029    @DoPrivileged
030    public class StagingPermissionImpl implements StagingPermission {
031    
032            @Override
033            public Boolean hasPermission(
034                    PermissionChecker permissionChecker, Group group, String className,
035                    long classPK, String portletId, String actionId) {
036    
037                    try {
038                            return doHasPermission(
039                                    permissionChecker, group, className, classPK, portletId,
040                                    actionId);
041                    }
042                    catch (Exception e) {
043                            _log.error(e, e);
044                    }
045    
046                    return null;
047            }
048    
049            @Override
050            public Boolean hasPermission(
051                    PermissionChecker permissionChecker, long groupId, String className,
052                    long classPK, String portletId, String actionId) {
053    
054                    try {
055                            Group group = GroupLocalServiceUtil.getGroup(groupId);
056    
057                            return doHasPermission(
058                                    permissionChecker, group, className, classPK, portletId,
059                                    actionId);
060                    }
061                    catch (Exception e) {
062                            _log.error(e, e);
063                    }
064    
065                    return null;
066            }
067    
068            protected Boolean doHasPermission(
069                            PermissionChecker permissionChecker, Group group, String className,
070                            long classPK, String portletId, String actionId)
071                    throws Exception {
072    
073                    if (!actionId.equals(ActionKeys.VIEW) &&
074                            !actionId.equals(ActionKeys.DELETE) && group.hasStagingGroup() &&
075                            group.isStagedPortlet(portletId)) {
076    
077                            return false;
078                    }
079                    else {
080                            return null;
081                    }
082            }
083    
084            private static Log _log = LogFactoryUtil.getLog(
085                    StagingPermissionImpl.class);
086    
087    }