src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt

changeset 232
296e12ff8d1c
parent 231
dcb1d5a7ea3a
child 242
b7f3e972b13c
--- a/src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt	Thu Aug 19 14:51:04 2021 +0200
+++ b/src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt	Thu Aug 19 17:20:43 2021 +0200
@@ -25,11 +25,8 @@
 
 package de.uapcore.lightpit.servlet
 
-import de.uapcore.lightpit.AbstractServlet
-import de.uapcore.lightpit.HttpRequest
-import de.uapcore.lightpit.boolValidator
+import de.uapcore.lightpit.*
 import de.uapcore.lightpit.dao.DataAccessObject
-import de.uapcore.lightpit.dateOptValidator
 import de.uapcore.lightpit.entities.*
 import de.uapcore.lightpit.types.IssueCategory
 import de.uapcore.lightpit.types.IssueStatus
@@ -524,10 +521,20 @@
             val commentId = http.param("commentid")?.toIntOrNull() ?: -1
             if (commentId > 0) {
                 val comment = dao.findComment(commentId)
-                val originalAuthor = comment?.author?.username
+                if (comment == null) {
+                    http.response.sendError(404)
+                    return
+                }
+                val originalAuthor = comment.author?.username
                 if (originalAuthor != null && originalAuthor == http.remoteUser) {
-                    comment.comment = http.param("comment") ?: ""
-                    dao.updateComment(comment)
+                    val newComment = http.param("comment")
+                    if (!newComment.isNullOrBlank()) {
+                        comment.comment = newComment
+                        dao.updateComment(comment)
+                        dao.insertHistoryEvent(comment)
+                    } else {
+                        logger().debug("Not updating comment ${comment.id} because nothing changed.")
+                    }
                 } else {
                     http.response.sendError(403)
                     return
@@ -537,7 +544,8 @@
                     author = http.remoteUser?.let { dao.findUserByName(it) }
                     comment = http.param("comment") ?: ""
                 }
-                dao.insertComment(comment)
+                val newId = dao.insertComment(comment)
+                dao.insertHistoryEvent(comment, newId)
             }
 
             http.renderCommit("${issuesHref}${issue.id}")
@@ -570,15 +578,31 @@
             }
 
             val openId = if (issue.id < 0) {
-                dao.insertIssue(issue)
+                val id = dao.insertIssue(issue)
+                dao.insertHistoryEvent(issue, id)
+                id
             } else {
-                dao.updateIssue(issue)
+                val reference = dao.findIssue(issue.id)
+                if (reference == null) {
+                    http.response.sendError(404)
+                    return
+                }
+
+                if (issue.hasChanged(reference)) {
+                    dao.updateIssue(issue)
+                    dao.insertHistoryEvent(issue)
+                } else {
+                    logger().debug("Not updating issue ${issue.id} because nothing changed.")
+                }
+
                 val newComment = http.param("comment")
                 if (!newComment.isNullOrBlank()) {
-                    dao.insertComment(IssueComment(-1, issue.id).apply {
+                    val comment = IssueComment(-1, issue.id).apply {
                         author = http.remoteUser?.let { dao.findUserByName(it) }
                         comment = newComment
-                    })
+                    }
+                    val commentid = dao.insertComment(comment)
+                    dao.insertHistoryEvent(comment, commentid)
                 }
                 issue.id
             }

mercurial