Sat, 23 May 2020 13:24:49 +0200
issue and version form now also work if no project is selected in the session
--- a/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java Fri May 22 21:23:57 2020 +0200 +++ b/src/main/java/de/uapcore/lightpit/modules/ProjectsModule.java Sat May 23 13:24:49 2020 +0200 @@ -113,14 +113,14 @@ } void selectVersion(Version version) { - if (!version.getProject().equals(project)) throw new AssertionError("Nice, you implemented a bug!"); + if (!Objects.equals(project, version.getProject())) throw new AssertionError("Nice, you implemented a bug!"); this.version = version; this.issue = null; updateAttributes(); } void selectIssue(Issue issue) { - if (!issue.getProject().equals(project)) throw new AssertionError("Nice, you implemented a bug!"); + if (!Objects.equals(issue.getProject(), project)) throw new AssertionError("Nice, you implemented a bug!"); this.issue = issue; this.version = null; updateAttributes(); @@ -266,7 +266,8 @@ return ResponseType.HTML; } - private void configureEditVersionForm(HttpServletRequest req, SessionSelection selection) { + private void configureEditVersionForm(HttpServletRequest req, DataAccessObjects dao, SessionSelection selection) throws SQLException { + req.setAttribute("projects", dao.getProjectDao().list()); req.setAttribute("version", selection.version); req.setAttribute("versionStatusEnum", VersionStatus.values()); @@ -277,15 +278,10 @@ @RequestMapping(requestPath = "versions/edit", method = HttpMethod.GET) public ResponseType editVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException { final var sessionSelection = new SessionSelection(req, dao); - if (sessionSelection.project == null) { - // TODO: remove this bullshit and only retrieve the object from session if we are creating a fresh version - resp.sendError(HttpServletResponse.SC_FORBIDDEN); - return ResponseType.NONE; - } sessionSelection.selectVersion(findByParameter(req, Integer.class, "id", dao.getVersionDao()::find) .orElse(new Version(-1, sessionSelection.project))); - configureEditVersionForm(req, sessionSelection); + configureEditVersionForm(req, dao, sessionSelection); return ResponseType.HTML; } @@ -293,11 +289,6 @@ @RequestMapping(requestPath = "versions/commit", method = HttpMethod.POST) public ResponseType commitVersion(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException { final var sessionSelection = new SessionSelection(req, dao); - if (sessionSelection.project == null) { - // TODO: remove this bullshit and retrieve project id from hidden field - resp.sendError(HttpServletResponse.SC_FORBIDDEN); - return ResponseType.NONE; - } var version = new Version(-1, sessionSelection.project); try { @@ -316,17 +307,17 @@ LOG.warn("Form validation failure: {}", ex.getMessage()); LOG.debug("Details:", ex); sessionSelection.selectVersion(version); - configureEditVersionForm(req, sessionSelection); + configureEditVersionForm(req, dao, sessionSelection); } return ResponseType.HTML; } private void configureEditIssueForm(HttpServletRequest req, DataAccessObjects dao, SessionSelection selection) throws SQLException { + req.setAttribute("projects", dao.getProjectDao().list()); req.setAttribute("issue", selection.issue); req.setAttribute("issueStatusEnum", IssueStatus.values()); req.setAttribute("issueCategoryEnum", IssueCategory.values()); - req.setAttribute("versions", dao.getVersionDao().list(selection.project)); req.setAttribute("users", dao.getUserDao().list()); setContentPage(req, "issue-form"); @@ -336,11 +327,6 @@ @RequestMapping(requestPath = "issues/edit", method = HttpMethod.GET) public ResponseType editIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException { final var sessionSelection = new SessionSelection(req, dao); - if (sessionSelection.project == null) { - // TODO: remove this bullshit and only retrieve the object from session if we are creating a fresh issue - resp.sendError(HttpServletResponse.SC_FORBIDDEN); - return ResponseType.NONE; - } sessionSelection.selectIssue(findByParameter(req, Integer.class, "id", dao.getIssueDao()::find).orElse(new Issue(-1, sessionSelection.project))); @@ -351,12 +337,7 @@ @RequestMapping(requestPath = "issues/commit", method = HttpMethod.POST) public ResponseType commitIssue(HttpServletRequest req, HttpServletResponse resp, DataAccessObjects dao) throws IOException, SQLException { - // TODO: remove this bullshit and store the project ID as hidden field final var sessionSelection = new SessionSelection(req, dao); - if (sessionSelection.project == null) { - resp.sendError(HttpServletResponse.SC_FORBIDDEN); - return ResponseType.NONE; - } Issue issue = new Issue(-1, sessionSelection.project); try {
--- a/src/main/resources/localization/projects.properties Fri May 22 21:23:57 2020 +0200 +++ b/src/main/resources/localization/projects.properties Sat May 23 13:24:49 2020 +0200 @@ -36,6 +36,7 @@ thead.repoUrl=Repository thead.owner=Project Lead +thead.version.project=Project thead.version.name=Version thead.version.status=Status thead.version.ordinal=Custom Ordering @@ -50,6 +51,7 @@ version.status.LTS=LTS version.status.Deprecated=Deprecated +thead.issue.project=Project thead.issue.subject=Subject thead.issue.description=Description thead.issue.assignee=Assignee
--- a/src/main/resources/localization/projects_de.properties Fri May 22 21:23:57 2020 +0200 +++ b/src/main/resources/localization/projects_de.properties Sat May 23 13:24:49 2020 +0200 @@ -36,6 +36,7 @@ thead.repoUrl=Repository thead.owner=Projektleitung +thead.version.project=Projekt thead.version.name=Version thead.version.status=Status thead.version.ordinal=Sequenznummer @@ -50,6 +51,7 @@ version.status.LTS=Langzeitsupport version.status.Deprecated=Veraltet +thead.issue.project=Projekt thead.issue.subject=Thema thead.issue.description=Beschreibung thead.issue.assignee=Zugewiesen
--- a/src/main/webapp/WEB-INF/jsp/issue-form.jsp Fri May 22 21:23:57 2020 +0200 +++ b/src/main/webapp/WEB-INF/jsp/issue-form.jsp Sat May 23 13:24:49 2020 +0200 @@ -31,10 +31,10 @@ <c:set scope="page" var="moduleInfo" value="${requestScope[Constants.REQ_ATTR_MODULE_INFO]}"/> +<jsp:useBean id="projects" type="java.util.List<de.uapcore.lightpit.entities.Project>" scope="request" /> <jsp:useBean id="issue" type="de.uapcore.lightpit.entities.Issue" scope="request"/> <jsp:useBean id="issueStatusEnum" type="de.uapcore.lightpit.entities.IssueStatus[]" scope="request"/> <jsp:useBean id="issueCategoryEnum" type="de.uapcore.lightpit.entities.IssueCategory[]" scope="request"/> -<jsp:useBean id="versions" type="java.util.List<de.uapcore.lightpit.entities.Version>" scope="request"/> <jsp:useBean id="users" type="java.util.List<de.uapcore.lightpit.entities.User>" scope="request"/> <form action="./${moduleInfo.modulePath}/issues/commit" method="post"> @@ -45,6 +45,18 @@ </colgroup> <tbody> <tr> + <th><fmt:message key="thead.issue.project"/></th> + <td> + <select name="pid" required> + <c:forEach var="project" items="${projects}"> + <option value="${project.id}" <c:if test="${project eq issue.project}">selected</c:if> > + <c:out value="${project.name}" /> + </option> + </c:forEach> + </select> + </td> + </tr> + <tr> <th><fmt:message key="thead.issue.category"/></th> <td> <select name="category"> @@ -151,7 +163,15 @@ <tr> <td colspan="2"> <input type="hidden" name="id" value="${issue.id}"/> - <a href="./${moduleInfo.modulePath}/view?pid=${issue.project.id}" class="button"> + <c:choose> + <c:when test="${not empty issue.project and issue.project.id ge 0}"> + <c:set var="cancelUrl">./${moduleInfo.modulePath}/view?pid=${issue.project.id}</c:set> + </c:when> + <c:otherwise> + <c:set var="cancelUrl">./${moduleInfo.modulePath}/</c:set> + </c:otherwise> + </c:choose> + <a href="${cancelUrl}" class="button"> <fmt:message bundle="${lightpit_bundle}" key="button.cancel"/> </a> <button type="submit"><fmt:message bundle="${lightpit_bundle}" key="button.okay"/></button>
--- a/src/main/webapp/WEB-INF/jsp/version-form.jsp Fri May 22 21:23:57 2020 +0200 +++ b/src/main/webapp/WEB-INF/jsp/version-form.jsp Sat May 23 13:24:49 2020 +0200 @@ -30,8 +30,8 @@ <%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <c:set scope="page" var="moduleInfo" value="${requestScope[Constants.REQ_ATTR_MODULE_INFO]}"/> -<c:set scope="page" var="selectedProject" value="${sessionScope[ProjectsModule.SESSION_ATTR_SELECTED_PROJECT]}"/> +<jsp:useBean id="projects" type="java.util.List<de.uapcore.lightpit.entities.Project>" scope="request" /> <jsp:useBean id="version" type="de.uapcore.lightpit.entities.Version" scope="request"/> <jsp:useBean id="versionStatusEnum" type="de.uapcore.lightpit.entities.VersionStatus[]" scope="request"/> @@ -43,6 +43,18 @@ </colgroup> <tbody> <tr> + <th><fmt:message key="thead.version.project"/></th> + <td> + <select name="pid" required> + <c:forEach var="project" items="${projects}"> + <option value="${project.id}" <c:if test="${project eq version.project}">selected</c:if> > + <c:out value="${project.name}" /> + </option> + </c:forEach> + </select> + </td> + </tr> + <tr> <th><fmt:message key="thead.version.name"/></th> <td><input name="name" type="text" maxlength="20" required value="<c:out value="${version.name}"/>" /></td> </tr> @@ -69,7 +81,15 @@ <tr> <td colspan="2"> <input type="hidden" name="id" value="${version.id}"/> - <a href="./${moduleInfo.modulePath}/view?pid=${version.project.id}" class="button"> + <c:choose> + <c:when test="${not empty version.project and version.project.id ge 0}"> + <c:set var="cancelUrl">./${moduleInfo.modulePath}/view?pid=${version.project.id}</c:set> + </c:when> + <c:otherwise> + <c:set var="cancelUrl">./${moduleInfo.modulePath}/</c:set> + </c:otherwise> + </c:choose> + <a href="${cancelUrl}" class="button"> <fmt:message bundle="${lightpit_bundle}" key="button.cancel"/> </a> <button type="submit"><fmt:message bundle="${lightpit_bundle}" key="button.okay"/></button>