# HG changeset patch # User Mike Becker # Date 1627916657 -7200 # Node ID 479dd7993ef9067673e6605ce241498d124345a6 # Parent fe4de34822a50b914a80771d02908b1392ad715c #22 adds possibility to edit own comments diff -r fe4de34822a5 -r 479dd7993ef9 src/main/kotlin/de/uapcore/lightpit/Constants.kt --- a/src/main/kotlin/de/uapcore/lightpit/Constants.kt Mon Aug 02 15:13:04 2021 +0200 +++ b/src/main/kotlin/de/uapcore/lightpit/Constants.kt Mon Aug 02 17:04:17 2021 +0200 @@ -92,6 +92,11 @@ const val REQ_ATTR_STYLESHEET = "extraCss" /** + * Key for the name of the optional java script file. + */ + const val REQ_ATTR_JAVASCRIPT = "javascriptFile" + + /** * Key for a location the page shall redirect to. * Will be used in a meta element. */ diff -r fe4de34822a5 -r 479dd7993ef9 src/main/kotlin/de/uapcore/lightpit/RequestMapping.kt --- a/src/main/kotlin/de/uapcore/lightpit/RequestMapping.kt Mon Aug 02 15:13:04 2021 +0200 +++ b/src/main/kotlin/de/uapcore/lightpit/RequestMapping.kt Mon Aug 02 17:04:17 2021 +0200 @@ -60,7 +60,7 @@ /** * The name of the content page. * - * @see Constants#REQ_ATTR_CONTENT_PAGE + * @see Constants#REQ_ATTR_PAGE_TITLE */ var pageTitle = "" set(value) { @@ -82,6 +82,19 @@ } /** + * A list of additional style sheets. + * + * @see Constants#REQ_ATTR_JAVASCRIPT + */ + var javascript = "" + set(value) { + field = value + request.setAttribute(Constants.REQ_ATTR_JAVASCRIPT, + value.withExt(".js") + ) + } + + /** * The name of the navigation menu JSP. * * @see Constants#REQ_ATTR_NAVIGATION diff -r fe4de34822a5 -r 479dd7993ef9 src/main/kotlin/de/uapcore/lightpit/dao/DataAccessObject.kt --- a/src/main/kotlin/de/uapcore/lightpit/dao/DataAccessObject.kt Mon Aug 02 15:13:04 2021 +0200 +++ b/src/main/kotlin/de/uapcore/lightpit/dao/DataAccessObject.kt Mon Aug 02 17:04:17 2021 +0200 @@ -75,5 +75,7 @@ fun updateIssue(issue: Issue) fun listComments(issue: Issue): List + fun findComment(id: Int): IssueComment? fun insertComment(issueComment: IssueComment) + fun updateComment(issueComment: IssueComment) } \ No newline at end of file diff -r fe4de34822a5 -r 479dd7993ef9 src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt --- a/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt Mon Aug 02 15:13:04 2021 +0200 +++ b/src/main/kotlin/de/uapcore/lightpit/dao/PostgresDataAccessObject.kt Mon Aug 02 17:04:17 2021 +0200 @@ -658,6 +658,12 @@ queryAll { it.extractIssueComment() } } + override fun findComment(id: Int): IssueComment? = + withStatement("select * from lpit_issue_comment left join lpit_user using (userid) where commentid = ?") { + setInt(1, id) + querySingle { it.extractIssueComment() } + } + override fun insertComment(issueComment: IssueComment) { useStatement("update lpit_issue set updated = now() where issueid = ?") { updateIssueDate -> withStatement("insert into lpit_issue_comment (issueid, comment, userid) values (?, ? ,?)") { @@ -672,5 +678,19 @@ } } } + + override fun updateComment(issueComment: IssueComment) { + useStatement("update lpit_issue set updated = now() where issueid = ?") { updateIssueDate -> + withStatement("update lpit_issue_comment set comment = ?, updatecount = updatecount + 1, updated = now() where commentid = ?") { + with(issueComment) { + updateIssueDate.setInt(1, issueid) + setStringSafe(1, comment) + setInt(2, id) + } + executeUpdate() + updateIssueDate.executeUpdate() + } + } + } // } \ No newline at end of file diff -r fe4de34822a5 -r 479dd7993ef9 src/main/kotlin/de/uapcore/lightpit/entities/IssueComment.kt --- a/src/main/kotlin/de/uapcore/lightpit/entities/IssueComment.kt Mon Aug 02 15:13:04 2021 +0200 +++ b/src/main/kotlin/de/uapcore/lightpit/entities/IssueComment.kt Mon Aug 02 17:04:17 2021 +0200 @@ -30,6 +30,7 @@ data class IssueComment(override val id: Int, val issueid: Int) : Entity { var author: User? = null + var commentFormatted: String = "" var comment: String = "" var created: Timestamp = Timestamp.from(Instant.now()) var updated: Timestamp = Timestamp.from(Instant.now()) diff -r fe4de34822a5 -r 479dd7993ef9 src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt --- a/src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt Mon Aug 02 15:13:04 2021 +0200 +++ b/src/main/kotlin/de/uapcore/lightpit/servlet/ProjectServlet.kt Mon Aug 02 17:04:17 2021 +0200 @@ -441,7 +441,6 @@ with(http) { pageTitle = "${projectInfo.project.name}: #${issue.id} ${issue.subject}" view = IssueDetailView(issue, comments, project, version, component) - // TODO: feed path for this particular issue feedPath = feedPath(projectInfo.project) navigationMenu = activeProjectNavMenu( dao.listProjects(), @@ -450,6 +449,7 @@ component ) styleSheets = listOf("projects") + javascript = "issue-editor" render("issue-view") } } @@ -492,6 +492,7 @@ component ) styleSheets = listOf("projects") + javascript = "issue-editor" render("issue-form") } } @@ -506,13 +507,26 @@ } // TODO: throw validator exception instead of using a default - val comment = IssueComment(-1, issue.id).apply { - author = http.remoteUser?.let { dao.findUserByName(it) } - comment = http.param("comment") ?: "" + + val commentId = http.param("commentid")?.toIntOrNull() ?: -1 + if (commentId > 0) { + val comment = dao.findComment(commentId) + val originalAuthor = comment?.author?.username + if (originalAuthor != null && originalAuthor == http.remoteUser) { + comment.comment = http.param("comment") ?: "" + dao.updateComment(comment) + } else { + http.response.sendError(403) + return + } + } else { + val comment = IssueComment(-1, issue.id).apply { + author = http.remoteUser?.let { dao.findUserByName(it) } + comment = http.param("comment") ?: "" + } + dao.insertComment(comment) } - dao.insertComment(comment) - http.renderCommit("${issuesHref}${issue.id}") } } diff -r fe4de34822a5 -r 479dd7993ef9 src/main/kotlin/de/uapcore/lightpit/viewmodel/Issues.kt --- a/src/main/kotlin/de/uapcore/lightpit/viewmodel/Issues.kt Mon Aug 02 15:13:04 2021 +0200 +++ b/src/main/kotlin/de/uapcore/lightpit/viewmodel/Issues.kt Mon Aug 02 17:04:17 2021 +0200 @@ -78,7 +78,7 @@ issue.description = process(issue.description?:"") for (comment in comments) { - comment.comment = process(comment.comment) + comment.commentFormatted = process(comment.comment) } } } diff -r fe4de34822a5 -r 479dd7993ef9 src/main/resources/localization/strings.properties --- a/src/main/resources/localization/strings.properties Mon Aug 02 15:13:04 2021 +0200 +++ b/src/main/resources/localization/strings.properties Mon Aug 02 17:04:17 2021 +0200 @@ -25,6 +25,7 @@ app.license.title=License app.name=Lightweight Project and Issue Tracking button.cancel=Cancel +button.comment.edit=Edit Comment button.comment=Comment button.component.create=New Component button.component.edit=Edit Component @@ -70,6 +71,8 @@ issue.category.Test=Test issue.category=Category issue.comments.anonauthor=Anonymous Author +issue.comments.lastupdate=Last edited: +issue.comments.updateCount=total edits issue.comments=Comments issue.created=Created issue.description=Description diff -r fe4de34822a5 -r 479dd7993ef9 src/main/resources/localization/strings_de.properties --- a/src/main/resources/localization/strings_de.properties Mon Aug 02 15:13:04 2021 +0200 +++ b/src/main/resources/localization/strings_de.properties Mon Aug 02 17:04:17 2021 +0200 @@ -24,6 +24,7 @@ app.changelog=Versionshistorie app.license.title=Lizenz (Englisch) button.cancel=Abbrechen +button.comment.edit=Absenden button.comment=Kommentieren button.component.create=Neue Komponente button.component.edit=Komponente Bearbeiten @@ -55,11 +56,11 @@ error.message = Server Nachricht error.returnLink = Kehre zurück zu error.timestamp = Zeitstempel -feed=Feed feed.issues.created=Vorgang wurde erstellt. feed.issues.description=Feed \u00fcber k\u00fcrzlich aktualisierte Vorg\u00e4nge. feed.issues.title=LightPIT Vorg\u00e4nge feed.issues.updated=Vorgang wurde aktualisiert. +feed=Feed issue.affected-versions=Betroffene Versionen issue.assignee=Zugewiesen issue.category.Bug=Fehler @@ -69,6 +70,8 @@ issue.category.Test=Test issue.category=Kategorie issue.comments.anonauthor=Anonymer Autor +issue.comments.lastupdate=Zuletzt bearbeitet: +issue.comments.updateCount=mal bearbeitet issue.comments=Kommentare issue.created=Erstellt issue.description=Beschreibung diff -r fe4de34822a5 -r 479dd7993ef9 src/main/webapp/WEB-INF/changelogs/changelog-de.jspf --- a/src/main/webapp/WEB-INF/changelogs/changelog-de.jspf Mon Aug 02 15:13:04 2021 +0200 +++ b/src/main/webapp/WEB-INF/changelogs/changelog-de.jspf Mon Aug 02 17:04:17 2021 +0200 @@ -28,6 +28,7 @@