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