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.portlet.tasks.service.impl;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.kernel.util.GetterUtil;
020    import com.liferay.portal.model.Layout;
021    import com.liferay.portal.security.auth.PrincipalException;
022    import com.liferay.portal.security.permission.ActionKeys;
023    import com.liferay.portal.security.permission.PermissionChecker;
024    import com.liferay.portal.service.permission.GroupPermissionUtil;
025    import com.liferay.portal.service.permission.LayoutPermissionUtil;
026    import com.liferay.portlet.tasks.model.TasksProposal;
027    import com.liferay.portlet.tasks.service.base.TasksProposalServiceBaseImpl;
028    import com.liferay.portlet.tasks.service.permission.TasksProposalPermission;
029    
030    /**
031     * @author Raymond Augé
032     * @author Brian Wing Shun Chan
033     */
034    public class TasksProposalServiceImpl extends TasksProposalServiceBaseImpl {
035    
036            public TasksProposal addProposal(
037                            long groupId, String className, String classPK, String name,
038                            String description, long reviewUserId,
039                            boolean addCommunityPermissions, boolean addGuestPermissions)
040                    throws PortalException, SystemException{
041    
042                    PermissionChecker permissionChecker = getPermissionChecker();
043    
044                    if (!GroupPermissionUtil.contains(
045                                    permissionChecker, groupId, ActionKeys.MANAGE_LAYOUTS) &&
046                            (name.equals(Layout.class.getName()) &&
047                             !LayoutPermissionUtil.contains(
048                                    permissionChecker, GetterUtil.getLong(classPK),
049                                    ActionKeys.UPDATE))) {
050    
051                            throw new PrincipalException();
052                    }
053    
054                    return tasksProposalLocalService.addProposal(
055                            getUserId(), groupId, className, classPK, name, description,
056                            reviewUserId, addCommunityPermissions, addGuestPermissions);
057            }
058    
059            public TasksProposal addProposal(
060                            long groupId, String className, String classPK, String name,
061                            String description, long reviewUserId,
062                            String[] communityPermissions, String[] guestPermissions)
063                    throws PortalException, SystemException{
064    
065                    PermissionChecker permissionChecker = getPermissionChecker();
066    
067                    if (!GroupPermissionUtil.contains(
068                                    permissionChecker, groupId, ActionKeys.MANAGE_LAYOUTS) &&
069                            (name.equals(Layout.class.getName()) &&
070                             !LayoutPermissionUtil.contains(
071                                    permissionChecker, GetterUtil.getLong(classPK),
072                                    ActionKeys.UPDATE))) {
073    
074                            throw new PrincipalException();
075                    }
076    
077                    return tasksProposalLocalService.addProposal(
078                            getUserId(), groupId, className, classPK, name, description,
079                            reviewUserId, communityPermissions, guestPermissions);
080            }
081    
082            public void deleteProposal(long proposalId)
083                    throws PortalException, SystemException{
084    
085                    PermissionChecker permissionChecker = getPermissionChecker();
086    
087                    TasksProposal proposal = tasksProposalPersistence.findByPrimaryKey(
088                            proposalId);
089    
090                    long groupId = proposal.getGroupId();
091    
092                    if (!GroupPermissionUtil.contains(
093                                    permissionChecker, groupId, ActionKeys.ASSIGN_REVIEWER) &&
094                            !GroupPermissionUtil.contains(
095                                    permissionChecker, groupId, ActionKeys.MANAGE_STAGING) &&
096                            !GroupPermissionUtil.contains(
097                                    permissionChecker, groupId, ActionKeys.PUBLISH_STAGING) &&
098                            !TasksProposalPermission.contains(
099                                    permissionChecker, proposalId, ActionKeys.DELETE)) {
100    
101                            throw new PrincipalException();
102                    }
103    
104                    tasksProposalLocalService.deleteProposal(proposalId);
105            }
106    
107            public TasksProposal updateProposal(
108                            long proposalId, String description, int dueDateMonth,
109                            int dueDateDay, int dueDateYear, int dueDateHour, int dueDateMinute)
110                    throws PortalException, SystemException{
111    
112                    PermissionChecker permissionChecker = getPermissionChecker();
113    
114                    TasksProposal proposal = tasksProposalPersistence.findByPrimaryKey(
115                            proposalId);
116    
117                    long groupId = proposal.getGroupId();
118    
119                    if (!GroupPermissionUtil.contains(
120                                    permissionChecker, groupId, ActionKeys.ASSIGN_REVIEWER) &&
121                            !GroupPermissionUtil.contains(
122                                    permissionChecker, groupId, ActionKeys.MANAGE_STAGING) &&
123                            !GroupPermissionUtil.contains(
124                                    permissionChecker, groupId, ActionKeys.PUBLISH_STAGING) &&
125                            !TasksProposalPermission.contains(
126                                    permissionChecker, proposalId, ActionKeys.UPDATE)) {
127    
128                            throw new PrincipalException();
129                    }
130    
131                    return tasksProposalLocalService.updateProposal(
132                            getUserId(), proposalId, description, dueDateMonth, dueDateDay,
133                            dueDateYear, dueDateHour, dueDateMinute);
134            }
135    
136    }