1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.tasks.service.impl;
24  
25  import com.liferay.portal.PortalException;
26  import com.liferay.portal.SystemException;
27  import com.liferay.portal.security.auth.PrincipalException;
28  import com.liferay.portal.security.permission.ActionKeys;
29  import com.liferay.portal.security.permission.PermissionChecker;
30  import com.liferay.portal.service.permission.GroupPermissionUtil;
31  import com.liferay.portlet.tasks.model.TasksProposal;
32  import com.liferay.portlet.tasks.service.base.TasksProposalServiceBaseImpl;
33  import com.liferay.portlet.tasks.service.permission.TasksProposalPermission;
34  
35  /**
36   * <a href="TasksProposalServiceImpl.java.html"><b><i>View Source</i></b></a>
37   *
38   * @author Raymond Aug�
39   * @author Brian Wing Shun Chan
40   *
41   */
42  public class TasksProposalServiceImpl extends TasksProposalServiceBaseImpl {
43  
44      public TasksProposal addProposal(
45              long groupId, String className, String classPK, String name,
46              String description, long reviewUserId,
47              boolean addCommunityPermissions, boolean addGuestPermissions)
48          throws PortalException, SystemException{
49  
50          GroupPermissionUtil.check(
51              getPermissionChecker(), groupId, ActionKeys.MANAGE_LAYOUTS);
52  
53          return tasksProposalLocalService.addProposal(
54              getUserId(), groupId, className, classPK, name, description,
55              reviewUserId, addCommunityPermissions, addGuestPermissions);
56      }
57  
58      public TasksProposal addProposal(
59              long groupId, String className, String classPK, String name,
60              String description, long reviewUserId,
61              String[] communityPermissions, String[] guestPermissions)
62          throws PortalException, SystemException{
63  
64          GroupPermissionUtil.check(
65              getPermissionChecker(), groupId, ActionKeys.MANAGE_LAYOUTS);
66  
67          return tasksProposalLocalService.addProposal(
68              getUserId(), groupId, className, classPK, name, description,
69              reviewUserId, communityPermissions, guestPermissions);
70      }
71  
72      public void deleteProposal(long proposalId)
73          throws PortalException, SystemException{
74  
75          PermissionChecker permissionChecker = getPermissionChecker();
76  
77          TasksProposal proposal = tasksProposalPersistence.findByPrimaryKey(
78              proposalId);
79  
80          long groupId = proposal.getGroupId();
81  
82          if (!GroupPermissionUtil.contains(
83                  permissionChecker, groupId, ActionKeys.ASSIGN_REVIEWER) &&
84              !GroupPermissionUtil.contains(
85                  permissionChecker, groupId, ActionKeys.MANAGE_STAGING) &&
86              !GroupPermissionUtil.contains(
87                  permissionChecker, groupId, ActionKeys.PUBLISH_STAGING) &&
88              !TasksProposalPermission.contains(
89                  permissionChecker, proposalId, ActionKeys.DELETE)) {
90  
91              throw new PrincipalException();
92          }
93  
94          tasksProposalLocalService.deleteProposal(proposalId);
95      }
96  
97      public TasksProposal updateProposal(
98              long proposalId, String description, int dueDateMonth,
99              int dueDateDay, int dueDateYear, int dueDateHour, int dueDateMinute)
100         throws PortalException, SystemException{
101 
102         PermissionChecker permissionChecker = getPermissionChecker();
103 
104         TasksProposal proposal = tasksProposalPersistence.findByPrimaryKey(
105             proposalId);
106 
107         long groupId = proposal.getGroupId();
108 
109         if (!GroupPermissionUtil.contains(
110                 permissionChecker, groupId, ActionKeys.ASSIGN_REVIEWER) &&
111             !GroupPermissionUtil.contains(
112                 permissionChecker, groupId, ActionKeys.MANAGE_STAGING) &&
113             !GroupPermissionUtil.contains(
114                 permissionChecker, groupId, ActionKeys.PUBLISH_STAGING) &&
115             !TasksProposalPermission.contains(
116                 permissionChecker, proposalId, ActionKeys.UPDATE)) {
117 
118             throw new PrincipalException();
119         }
120 
121         return tasksProposalLocalService.updateProposal(
122             getUserId(), proposalId, description, dueDateMonth, dueDateDay,
123             dueDateYear, dueDateHour, dueDateMinute);
124     }
125 
126 }