diff options
author | Unknwon <u@gogs.io> | 2015-08-20 04:31:28 +0800 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-08-20 04:31:28 +0800 |
commit | 371572cf5f853211fb11bb28bc41658119d3e247 (patch) | |
tree | 68530957b87dbc2f659d4a155bbec41bb557c033 /routers/repo | |
parent | f114f7874303d249b2956c894b1a90b042430acf (diff) | |
download | gitea-371572cf5f853211fb11bb28bc41658119d3e247.tar.gz gitea-371572cf5f853211fb11bb28bc41658119d3e247.zip |
allow edit issue and comment
Diffstat (limited to 'routers/repo')
-rw-r--r-- | routers/repo/issue.go | 69 |
1 files changed, 62 insertions, 7 deletions
diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 647b224d37..8790fcd7b3 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -543,19 +543,16 @@ func UpdateIssueTitle(ctx *middleware.Context) { return } - if !ctx.IsSigned || ctx.User.Id != issue.PosterID || !ctx.Repo.IsAdmin() { + if !ctx.IsSigned || (ctx.User.Id != issue.PosterID && !ctx.Repo.IsAdmin()) { ctx.Error(403) return } - title := ctx.Query("title") - if len(title) == 0 { - ctx.JSON(200, map[string]interface{}{ - "title": issue.Name, - }) + issue.Name = ctx.Query("title") + if len(issue.Name) == 0 { + ctx.Error(204) return } - issue.Name = title if err := models.UpdateIssue(issue); err != nil { ctx.Handle(500, "UpdateIssue", err) @@ -567,6 +564,28 @@ func UpdateIssueTitle(ctx *middleware.Context) { }) } +func UpdateIssueContent(ctx *middleware.Context) { + issue := getActionIssue(ctx) + if ctx.Written() { + return + } + + if !ctx.IsSigned || (ctx.User.Id != issue.PosterID && !ctx.Repo.IsAdmin()) { + ctx.Error(403) + return + } + + issue.Content = ctx.Query("content") + if err := models.UpdateIssue(issue); err != nil { + ctx.Handle(500, "UpdateIssue", err) + return + } + + ctx.JSON(200, map[string]interface{}{ + "content": string(base.RenderMarkdown([]byte(issue.Content), ctx.Query("context"))), + }) +} + func UpdateIssueLabel(ctx *middleware.Context) { issue := getActionIssue(ctx) if ctx.Written() { @@ -748,6 +767,42 @@ func NewComment(ctx *middleware.Context, form auth.CreateCommentForm) { ctx.Redirect(fmt.Sprintf("%s/issues/%d#%s", ctx.Repo.RepoLink, issue.Index, comment.HashTag())) } +func UpdateCommentContent(ctx *middleware.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) + } + 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 + } + + comment.Content = ctx.Query("content") + if len(comment.Content) == 0 { + ctx.JSON(200, map[string]interface{}{ + "content": "", + }) + return + } + if err := models.UpdateComment(comment); err != nil { + ctx.Handle(500, "UpdateComment", err) + return + } + + ctx.JSON(200, map[string]interface{}{ + "content": string(base.RenderMarkdown([]byte(comment.Content), ctx.Query("context"))), + }) +} + func Labels(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Tr("repo.labels") ctx.Data["PageIsLabels"] = true |