summaryrefslogtreecommitdiffstats
path: root/routers/repo
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-07-26 02:48:17 +0800
committerUnknwon <u@gogs.io>2016-07-26 02:48:17 +0800
commit899e7994595f5fc500de8cdf39e1b737f9f00982 (patch)
tree1477940293968f1ee2781e04209b7038e9774d95 /routers/repo
parent2295fafb34e2467f3b380a4db8832aa2c70ecc5a (diff)
downloadgitea-899e7994595f5fc500de8cdf39e1b737f9f00982.tar.gz
gitea-899e7994595f5fc500de8cdf39e1b737f9f00982.zip
#1601 support delete issue comment
Diffstat (limited to 'routers/repo')
-rw-r--r--routers/repo/issue.go37
1 files changed, 26 insertions, 11 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index 269066eb61..471a017283 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -803,11 +803,7 @@ func UpdateIssueAssignee(ctx *context.Context) {
func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
if err != nil {
- if models.IsErrIssueNotExist(err) {
- ctx.Handle(404, "GetIssueByIndex", err)
- } else {
- ctx.Handle(500, "GetIssueByIndex", err)
- }
+ ctx.HandleError("GetIssueByIndex", models.IsErrIssueNotExist, err, 404)
return
}
if issue.IsPull {
@@ -899,11 +895,7 @@ func NewComment(ctx *context.Context, form auth.CreateCommentForm) {
func UpdateCommentContent(ctx *context.Context) {
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
if err != nil {
- if models.IsErrCommentNotExist(err) {
- ctx.Error(404, "GetCommentByID")
- } else {
- ctx.Handle(500, "GetCommentByID", err)
- }
+ ctx.HandleError("GetCommentByID", models.IsErrCommentNotExist, err, 404)
return
}
@@ -922,7 +914,7 @@ func UpdateCommentContent(ctx *context.Context) {
})
return
}
- if err := models.UpdateComment(comment); err != nil {
+ if err = models.UpdateComment(comment); err != nil {
ctx.Handle(500, "UpdateComment", err)
return
}
@@ -932,6 +924,29 @@ func UpdateCommentContent(ctx *context.Context) {
})
}
+func DeleteComment(ctx *context.Context) {
+ comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
+ if err != nil {
+ ctx.HandleError("GetCommentByID", models.IsErrCommentNotExist, err, 404)
+ return
+ }
+
+ if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.IsAdmin()) {
+ ctx.Error(403)
+ return
+ } else if comment.Type != models.COMMENT_TYPE_COMMENT {
+ ctx.Error(204)
+ return
+ }
+
+ if err = models.DeleteCommentByID(comment.ID); err != nil {
+ ctx.Handle(500, "DeleteCommentByID", err)
+ return
+ }
+
+ ctx.Status(200)
+}
+
func Labels(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.labels")
ctx.Data["PageIsIssueList"] = true