1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.itracker.web.actions.project;
20
21 import org.apache.commons.beanutils.PropertyUtils;
22 import org.apache.commons.beanutils.converters.IntegerConverter;
23 import org.apache.log4j.Logger;
24 import org.apache.struts.action.*;
25 import org.itracker.model.PermissionType;
26 import org.itracker.model.Project;
27 import org.itracker.model.Status;
28 import org.itracker.model.User;
29 import org.itracker.model.util.UserUtilities;
30 import org.itracker.services.IssueService;
31 import org.itracker.services.ProjectService;
32 import org.itracker.web.actions.base.ItrackerBaseAction;
33 import org.itracker.web.util.Constants;
34 import org.itracker.web.util.RequestHelper;
35 import org.itracker.web.util.ServletContextUtils;
36
37 import javax.servlet.ServletException;
38 import javax.servlet.http.HttpServletRequest;
39 import javax.servlet.http.HttpServletResponse;
40 import javax.servlet.http.HttpSession;
41 import java.io.IOException;
42 import java.lang.reflect.InvocationTargetException;
43 import java.util.Map;
44 import java.util.Set;
45
46
47 public class AssignIssueAction extends ItrackerBaseAction {
48
49 private static final Logger log = Logger.getLogger(AssignIssueAction.class);
50
51
52 public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
53
54 ActionMessages errors = new ActionMessages();
55
56 try {
57 IssueService issueService = ServletContextUtils.getItrackerServices().getIssueService();
58 ProjectService projectService = ServletContextUtils.getItrackerServices().getProjectService();
59
60 Integer defaultValue = -1;
61 IntegerConverter converter = new IntegerConverter(defaultValue);
62 Integer issueId = (Integer) converter.convert(Integer.class, (String) PropertyUtils.getSimpleProperty(form, "issueId"));
63 Integer projectId = (Integer) converter.convert(Integer.class, (String) PropertyUtils.getSimpleProperty(form, "projectId"));
64 Integer userId = (Integer) converter.convert(Integer.class, (String) PropertyUtils.getSimpleProperty(form, "userId"));
65
66 HttpSession session = request.getSession(true);
67 User currUser = (User) session.getAttribute(Constants.USER_KEY);
68 Map<Integer, Set<PermissionType>> userPermissions = RequestHelper.getUserPermissions(session);
69 Integer currUserId = currUser.getId();
70
71 Project project = projectService.getProject(projectId);
72 if (project == null) {
73 return mapping.findForward("unauthorized");
74 }
75
76 if (!userId.equals(currUserId) && !UserUtilities.hasPermission(userPermissions, projectId, UserUtilities.PERMISSION_ASSIGN_OTHERS)) {
77 return mapping.findForward("unauthorized");
78 } else if (!UserUtilities.hasPermission(userPermissions, projectId, UserUtilities.PERMISSION_ASSIGN_SELF)) {
79 return mapping.findForward("unauthorized");
80 }
81
82 if (project.getStatus() != Status.ACTIVE) {
83 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.projectlocked"));
84 } else {
85 issueService.assignIssue(issueId, userId, currUserId);
86 }
87 } catch (RuntimeException e) {
88 log.warn("execute: caught exception", e);
89 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
90 } catch (IllegalAccessException e) {
91 log.warn("execute: caught exception", e);
92 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
93 } catch (InvocationTargetException e) {
94 log.warn("execute: caught exception", e);
95 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
96 } catch (NoSuchMethodException e) {
97 log.warn("execute: caught exception", e);
98 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("itracker.web.error.system"));
99 }
100
101 if (!errors.isEmpty()) {
102 saveErrors(request, errors);
103 saveToken(request);
104 }
105 return mapping.findForward("index");
106 }
107
108 }
109