23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ |
24 */ |
25 |
25 |
26 package de.uapcore.lightpit.servlet |
26 package de.uapcore.lightpit.servlet |
27 |
27 |
28 import de.uapcore.lightpit.AbstractServlet |
28 import de.uapcore.lightpit.* |
29 import de.uapcore.lightpit.HttpRequest |
|
30 import de.uapcore.lightpit.boolValidator |
|
31 import de.uapcore.lightpit.dao.DataAccessObject |
29 import de.uapcore.lightpit.dao.DataAccessObject |
32 import de.uapcore.lightpit.dateOptValidator |
|
33 import de.uapcore.lightpit.entities.* |
30 import de.uapcore.lightpit.entities.* |
34 import de.uapcore.lightpit.types.IssueCategory |
31 import de.uapcore.lightpit.types.IssueCategory |
35 import de.uapcore.lightpit.types.IssueStatus |
32 import de.uapcore.lightpit.types.IssueStatus |
36 import de.uapcore.lightpit.types.VersionStatus |
33 import de.uapcore.lightpit.types.VersionStatus |
37 import de.uapcore.lightpit.types.WebColor |
34 import de.uapcore.lightpit.types.WebColor |
522 } |
519 } |
523 |
520 |
524 val commentId = http.param("commentid")?.toIntOrNull() ?: -1 |
521 val commentId = http.param("commentid")?.toIntOrNull() ?: -1 |
525 if (commentId > 0) { |
522 if (commentId > 0) { |
526 val comment = dao.findComment(commentId) |
523 val comment = dao.findComment(commentId) |
527 val originalAuthor = comment?.author?.username |
524 if (comment == null) { |
|
525 http.response.sendError(404) |
|
526 return |
|
527 } |
|
528 val originalAuthor = comment.author?.username |
528 if (originalAuthor != null && originalAuthor == http.remoteUser) { |
529 if (originalAuthor != null && originalAuthor == http.remoteUser) { |
529 comment.comment = http.param("comment") ?: "" |
530 val newComment = http.param("comment") |
530 dao.updateComment(comment) |
531 if (!newComment.isNullOrBlank()) { |
|
532 comment.comment = newComment |
|
533 dao.updateComment(comment) |
|
534 dao.insertHistoryEvent(comment) |
|
535 } else { |
|
536 logger().debug("Not updating comment ${comment.id} because nothing changed.") |
|
537 } |
531 } else { |
538 } else { |
532 http.response.sendError(403) |
539 http.response.sendError(403) |
533 return |
540 return |
534 } |
541 } |
535 } else { |
542 } else { |
536 val comment = IssueComment(-1, issue.id).apply { |
543 val comment = IssueComment(-1, issue.id).apply { |
537 author = http.remoteUser?.let { dao.findUserByName(it) } |
544 author = http.remoteUser?.let { dao.findUserByName(it) } |
538 comment = http.param("comment") ?: "" |
545 comment = http.param("comment") ?: "" |
539 } |
546 } |
540 dao.insertComment(comment) |
547 val newId = dao.insertComment(comment) |
|
548 dao.insertHistoryEvent(comment, newId) |
541 } |
549 } |
542 |
550 |
543 http.renderCommit("${issuesHref}${issue.id}") |
551 http.renderCommit("${issuesHref}${issue.id}") |
544 } |
552 } |
545 } |
553 } |
568 affected = http.param("affected")?.toIntOrNull()?.takeIf { it > 0 }?.let { Version(it, project.id) } |
576 affected = http.param("affected")?.toIntOrNull()?.takeIf { it > 0 }?.let { Version(it, project.id) } |
569 resolved = http.param("resolved")?.toIntOrNull()?.takeIf { it > 0 }?.let { Version(it, project.id) } |
577 resolved = http.param("resolved")?.toIntOrNull()?.takeIf { it > 0 }?.let { Version(it, project.id) } |
570 } |
578 } |
571 |
579 |
572 val openId = if (issue.id < 0) { |
580 val openId = if (issue.id < 0) { |
573 dao.insertIssue(issue) |
581 val id = dao.insertIssue(issue) |
|
582 dao.insertHistoryEvent(issue, id) |
|
583 id |
574 } else { |
584 } else { |
575 dao.updateIssue(issue) |
585 val reference = dao.findIssue(issue.id) |
|
586 if (reference == null) { |
|
587 http.response.sendError(404) |
|
588 return |
|
589 } |
|
590 |
|
591 if (issue.hasChanged(reference)) { |
|
592 dao.updateIssue(issue) |
|
593 dao.insertHistoryEvent(issue) |
|
594 } else { |
|
595 logger().debug("Not updating issue ${issue.id} because nothing changed.") |
|
596 } |
|
597 |
576 val newComment = http.param("comment") |
598 val newComment = http.param("comment") |
577 if (!newComment.isNullOrBlank()) { |
599 if (!newComment.isNullOrBlank()) { |
578 dao.insertComment(IssueComment(-1, issue.id).apply { |
600 val comment = IssueComment(-1, issue.id).apply { |
579 author = http.remoteUser?.let { dao.findUserByName(it) } |
601 author = http.remoteUser?.let { dao.findUserByName(it) } |
580 comment = newComment |
602 comment = newComment |
581 }) |
603 } |
|
604 val commentid = dao.insertComment(comment) |
|
605 dao.insertHistoryEvent(comment, commentid) |
582 } |
606 } |
583 issue.id |
607 issue.id |
584 } |
608 } |
585 |
609 |
586 if (http.param("more") != null) { |
610 if (http.param("more") != null) { |