diff --git a/src/main/scala/app/IssuesController.scala b/src/main/scala/app/IssuesController.scala index 98281e5..f62b86f 100644 --- a/src/main/scala/app/IssuesController.scala +++ b/src/main/scala/app/IssuesController.scala @@ -155,6 +155,16 @@ } }) + ajaxPost("/:owner/:repository/issue_comments/delete/:id")(readableUsersOnly { repository => + defining(repository.owner, repository.name){ case (owner, name) => + getComment(owner, name, params("id")).map { comment => + if(isEditable(owner, name, comment.commentedUserName)){ + Ok(deleteComment(comment.commentId)) + } else Unauthorized + } getOrElse NotFound + } + }) + ajaxGet("/:owner/:repository/issues/_data/:id")(readableUsersOnly { repository => getIssue(repository.owner, repository.name, params("id")) map { x => if(isEditable(x.userName, x.repositoryName, x.openedUserName)){ diff --git a/src/main/scala/service/IssuesService.scala b/src/main/scala/service/IssuesService.scala index 16fa972..493692e 100644 --- a/src/main/scala/service/IssuesService.scala +++ b/src/main/scala/service/IssuesService.scala @@ -249,6 +249,9 @@ } .update (content, currentDate) + def deleteComment(commentId: Int) = + IssueComments filter (_.byPrimaryKey(commentId)) delete + def updateClosed(owner: String, repository: String, issueId: Int, closed: Boolean) = Issues .filter (_.byPrimaryKey(owner, repository, issueId)) diff --git a/src/main/twirl/issues/commentlist.scala.html b/src/main/twirl/issues/commentlist.scala.html index ecff874..3c19aa4 100644 --- a/src/main/twirl/issues/commentlist.scala.html +++ b/src/main/twirl/issues/commentlist.scala.html @@ -15,7 +15,8 @@ @datetime(comment.registeredDate) @if(comment.action != "commit" && comment.action != "merge" && (hasWritePermission || loginAccount.map(_.userName == comment.commentedUserName).getOrElse(false))){ - +   + } @@ -69,5 +70,18 @@ }); return false; }); + $('i.icon-remove-circle').click(function(){ + if(confirm('Are you sure you want to delete this?')) { + var id = $(this).closest('a').data('comment-id'); + $.post('@url(repository)/issue_comments/delete/' + id, + function(data){ + if(data > 0) { + $('#comment-' + id).prev('div.issue-avatar-image').remove(); + $('#comment-' + id).remove(); + } + }); + } + return false; + }); }); \ No newline at end of file