1.1 --- a/src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt Thu Aug 19 14:51:04 2021 +0200 1.2 +++ b/src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt Thu Aug 19 17:20:43 2021 +0200 1.3 @@ -25,11 +25,8 @@ 1.4 1.5 package de.uapcore.lightpit.servlet 1.6 1.7 -import de.uapcore.lightpit.AbstractServlet 1.8 -import de.uapcore.lightpit.HttpRequest 1.9 -import de.uapcore.lightpit.boolValidator 1.10 +import de.uapcore.lightpit.* 1.11 import de.uapcore.lightpit.dao.DataAccessObject 1.12 -import de.uapcore.lightpit.dateOptValidator 1.13 import de.uapcore.lightpit.entities.* 1.14 import de.uapcore.lightpit.types.IssueCategory 1.15 import de.uapcore.lightpit.types.IssueStatus 1.16 @@ -524,10 +521,20 @@ 1.17 val commentId = http.param("commentid")?.toIntOrNull() ?: -1 1.18 if (commentId > 0) { 1.19 val comment = dao.findComment(commentId) 1.20 - val originalAuthor = comment?.author?.username 1.21 + if (comment == null) { 1.22 + http.response.sendError(404) 1.23 + return 1.24 + } 1.25 + val originalAuthor = comment.author?.username 1.26 if (originalAuthor != null && originalAuthor == http.remoteUser) { 1.27 - comment.comment = http.param("comment") ?: "" 1.28 - dao.updateComment(comment) 1.29 + val newComment = http.param("comment") 1.30 + if (!newComment.isNullOrBlank()) { 1.31 + comment.comment = newComment 1.32 + dao.updateComment(comment) 1.33 + dao.insertHistoryEvent(comment) 1.34 + } else { 1.35 + logger().debug("Not updating comment ${comment.id} because nothing changed.") 1.36 + } 1.37 } else { 1.38 http.response.sendError(403) 1.39 return 1.40 @@ -537,7 +544,8 @@ 1.41 author = http.remoteUser?.let { dao.findUserByName(it) } 1.42 comment = http.param("comment") ?: "" 1.43 } 1.44 - dao.insertComment(comment) 1.45 + val newId = dao.insertComment(comment) 1.46 + dao.insertHistoryEvent(comment, newId) 1.47 } 1.48 1.49 http.renderCommit("${issuesHref}${issue.id}") 1.50 @@ -570,15 +578,31 @@ 1.51 } 1.52 1.53 val openId = if (issue.id < 0) { 1.54 - dao.insertIssue(issue) 1.55 + val id = dao.insertIssue(issue) 1.56 + dao.insertHistoryEvent(issue, id) 1.57 + id 1.58 } else { 1.59 - dao.updateIssue(issue) 1.60 + val reference = dao.findIssue(issue.id) 1.61 + if (reference == null) { 1.62 + http.response.sendError(404) 1.63 + return 1.64 + } 1.65 + 1.66 + if (issue.hasChanged(reference)) { 1.67 + dao.updateIssue(issue) 1.68 + dao.insertHistoryEvent(issue) 1.69 + } else { 1.70 + logger().debug("Not updating issue ${issue.id} because nothing changed.") 1.71 + } 1.72 + 1.73 val newComment = http.param("comment") 1.74 if (!newComment.isNullOrBlank()) { 1.75 - dao.insertComment(IssueComment(-1, issue.id).apply { 1.76 + val comment = IssueComment(-1, issue.id).apply { 1.77 author = http.remoteUser?.let { dao.findUserByName(it) } 1.78 comment = newComment 1.79 - }) 1.80 + } 1.81 + val commentid = dao.insertComment(comment) 1.82 + dao.insertHistoryEvent(comment, commentid) 1.83 } 1.84 issue.id 1.85 }