diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2023-04-20 16:21:10 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-20 04:21:10 -0400 |
commit | d5f2c9d74d63443cc2abbcabc268cf1121f58e8b (patch) | |
tree | d10ff79eaa534f916922567e18895e8bcffc866a /routers | |
parent | 95c2cb4b79bff04d11ad13933a8561026a42a2eb (diff) | |
download | gitea-d5f2c9d74d63443cc2abbcabc268cf1121f58e8b.tar.gz gitea-d5f2c9d74d63443cc2abbcabc268cf1121f58e8b.zip |
Fix issue attachment handling (#24202) (#24221)
Backport #24202
Close #24195
Fix the bug:
1. The old code doesn't handle `removedfile` event correctly
2. The old code doesn't provide attachments for type=CommentTypeReview
---------
Co-authored-by: silverwind <me@silverwind.io>
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/repo/issue_comment.go | 4 | ||||
-rw-r--r-- | routers/web/repo/issue.go | 28 |
2 files changed, 18 insertions, 14 deletions
diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go index 3d14343d47..6ae6063303 100644 --- a/routers/api/v1/repo/issue_comment.go +++ b/routers/api/v1/repo/issue_comment.go @@ -173,7 +173,7 @@ func ListIssueCommentsAndTimeline(ctx *context.APIContext) { IssueID: issue.ID, Since: since, Before: before, - Type: issues_model.CommentTypeUnknown, + Type: issues_model.CommentTypeUndefined, } comments, err := issues_model.FindComments(ctx, opts) @@ -549,7 +549,7 @@ func editIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) return } - if comment.Type != issues_model.CommentTypeComment && comment.Type != issues_model.CommentTypeReview && comment.Type != issues_model.CommentTypeCode { + if !comment.Type.HasContentSupport() { ctx.Status(http.StatusNoContent) return } diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 1a17afeef3..018925b8d1 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -1563,7 +1563,7 @@ func ViewIssue(ctx *context.Context) { return } } - } else if comment.Type == issues_model.CommentTypeCode || comment.Type == issues_model.CommentTypeReview || comment.Type == issues_model.CommentTypeDismissReview { + } else if comment.Type.HasContentSupport() { comment.RenderedContent, err = markdown.RenderString(&markup.RenderContext{ URLPrefix: ctx.Repo.RepoLink, Metas: ctx.Repo.Repository.ComposeMetas(), @@ -2800,7 +2800,7 @@ func UpdateCommentContent(ctx *context.Context) { return } - if comment.Type != issues_model.CommentTypeComment && comment.Type != issues_model.CommentTypeReview && comment.Type != issues_model.CommentTypeCode { + if !comment.Type.HasContentSupport() { ctx.Error(http.StatusNoContent) return } @@ -2864,7 +2864,7 @@ func DeleteComment(ctx *context.Context) { if !ctx.IsSigned || (ctx.Doer.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) { ctx.Error(http.StatusForbidden) return - } else if comment.Type != issues_model.CommentTypeComment && comment.Type != issues_model.CommentTypeCode { + } else if !comment.Type.HasContentSupport() { ctx.Error(http.StatusNoContent) return } @@ -3010,7 +3010,7 @@ func ChangeCommentReaction(ctx *context.Context) { return } - if comment.Type != issues_model.CommentTypeComment && comment.Type != issues_model.CommentTypeCode && comment.Type != issues_model.CommentTypeReview { + if !comment.Type.HasContentSupport() { ctx.Error(http.StatusNoContent) return } @@ -3126,15 +3126,19 @@ func GetCommentAttachments(ctx *context.Context) { ctx.NotFoundOrServerError("GetCommentByID", issues_model.IsErrCommentNotExist, err) return } + + if !comment.Type.HasAttachmentSupport() { + ctx.ServerError("GetCommentAttachments", fmt.Errorf("comment type %v does not support attachments", comment.Type)) + return + } + attachments := make([]*api.Attachment, 0) - if comment.Type == issues_model.CommentTypeComment { - if err := comment.LoadAttachments(ctx); err != nil { - ctx.ServerError("LoadAttachments", err) - return - } - for i := 0; i < len(comment.Attachments); i++ { - attachments = append(attachments, convert.ToAttachment(comment.Attachments[i])) - } + if err := comment.LoadAttachments(ctx); err != nil { + ctx.ServerError("LoadAttachments", err) + return + } + for i := 0; i < len(comment.Attachments); i++ { + attachments = append(attachments, convert.ToAttachment(comment.Attachments[i])) } ctx.JSON(http.StatusOK, attachments) } |