1.1 --- a/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java Fri May 22 21:23:57 2020 +0200 1.2 +++ b/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java Sat May 23 13:24:49 2020 +0200 1.3 @@ -113,14 +113,14 @@ 1.4 } 1.5 1.6 void selectVersion(Version version) { 1.7 - if (!version.getProject().equals(project)) throw new AssertionError("Nice, you implemented a bug!"); 1.8 + if (!Objects.equals(project, version.getProject())) throw new AssertionError("Nice, you implemented a bug!"); 1.9 this.version = version; 1.10 this.issue = null; 1.11 updateAttributes(); 1.12 } 1.13 1.14 void selectIssue(Issue issue) { 1.15 - if (!issue.getProject().equals(project)) throw new AssertionError("Nice, you implemented a bug!"); 1.16 + if (!Objects.equals(issue.getProject(), project)) throw new AssertionError("Nice, you implemented a bug!"); 1.17 this.issue = issue; 1.18 this.version = null; 1.19 updateAttributes(); 1.20 @@ -266,7 +266,8 @@ 1.21 return ResponseType.HTML; 1.22 } 1.23 1.24 - private void configureEditVersionForm(HttpServletRequest req, SessionSelection selection) { 1.25 + private void configureEditVersionForm(HttpServletRequest req, DataAccessObjects dao, SessionSelection selection) throws SQLException { 1.26 + req.setAttribute("projects", dao.getProjectDao().list()); 1.27 req.setAttribute("version", selection.version); 1.28 req.setAttribute("versionStatusEnum", VersionStatus.values()); 1.29 1.30 @@ -277,15 +278,10 @@ 1.31 @RequestMapping(requestPath = "versions/edit", method = HttpMethod.GET) 1.32 public ResponseType editVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException { 1.33 final var sessionSelection = new SessionSelection(req, dao); 1.34 - if (sessionSelection.project == null) { 1.35 - // TODO: remove this bullshit and only retrieve the object from session if we are creating a fresh version 1.36 - resp.sendError(HttpServletResponse.SC_FORBIDDEN); 1.37 - return ResponseType.NONE; 1.38 - } 1.39 1.40 sessionSelection.selectVersion(findByParameter(req, Integer.class, "id", dao.getVersionDao()::find) 1.41 .orElse(new Version(-1, sessionSelection.project))); 1.42 - configureEditVersionForm(req, sessionSelection); 1.43 + configureEditVersionForm(req, dao, sessionSelection); 1.44 1.45 return ResponseType.HTML; 1.46 } 1.47 @@ -293,11 +289,6 @@ 1.48 @RequestMapping(requestPath = "versions/commit", method = HttpMethod.POST) 1.49 public ResponseType commitVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException { 1.50 final var sessionSelection = new SessionSelection(req, dao); 1.51 - if (sessionSelection.project == null) { 1.52 - // TODO: remove this bullshit and retrieve project id from hidden field 1.53 - resp.sendError(HttpServletResponse.SC_FORBIDDEN); 1.54 - return ResponseType.NONE; 1.55 - } 1.56 1.57 var version = new Version(-1, sessionSelection.project); 1.58 try { 1.59 @@ -316,17 +307,17 @@ 1.60 LOG.warn("Form validation failure: {}", ex.getMessage()); 1.61 LOG.debug("Details:", ex); 1.62 sessionSelection.selectVersion(version); 1.63 - configureEditVersionForm(req, sessionSelection); 1.64 + configureEditVersionForm(req, dao, sessionSelection); 1.65 } 1.66 1.67 return ResponseType.HTML; 1.68 } 1.69 1.70 private void configureEditIssueForm(HttpServletRequest req, DataAccessObjects dao, SessionSelection selection) throws SQLException { 1.71 + req.setAttribute("projects", dao.getProjectDao().list()); 1.72 req.setAttribute("issue", selection.issue); 1.73 req.setAttribute("issueStatusEnum", IssueStatus.values()); 1.74 req.setAttribute("issueCategoryEnum", IssueCategory.values()); 1.75 - req.setAttribute("versions", dao.getVersionDao().list(selection.project)); 1.76 req.setAttribute("users", dao.getUserDao().list()); 1.77 1.78 setContentPage(req, "issue-form"); 1.79 @@ -336,11 +327,6 @@ 1.80 @RequestMapping(requestPath = "issues/edit", method = HttpMethod.GET) 1.81 public ResponseType editIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException { 1.82 final var sessionSelection = new SessionSelection(req, dao); 1.83 - if (sessionSelection.project == null) { 1.84 - // TODO: remove this bullshit and only retrieve the object from session if we are creating a fresh issue 1.85 - resp.sendError(HttpServletResponse.SC_FORBIDDEN); 1.86 - return ResponseType.NONE; 1.87 - } 1.88 1.89 sessionSelection.selectIssue(findByParameter(req, Integer.class, "id", 1.90 dao.getIssueDao()::find).orElse(new Issue(-1, sessionSelection.project))); 1.91 @@ -351,12 +337,7 @@ 1.92 1.93 @RequestMapping(requestPath = "issues/commit", method = HttpMethod.POST) 1.94 public ResponseType commitIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException { 1.95 - // TODO: remove this bullshit and store the project ID as hidden field 1.96 final var sessionSelection = new SessionSelection(req, dao); 1.97 - if (sessionSelection.project == null) { 1.98 - resp.sendError(HttpServletResponse.SC_FORBIDDEN); 1.99 - return ResponseType.NONE; 1.100 - } 1.101 1.102 Issue issue = new Issue(-1, sessionSelection.project); 1.103 try {