From 9dcbae1bcc272a537d974a49aec164793458c503 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Fri, 20 Aug 2021 21:26:19 +0200 Subject: [PATCH 1/2] Keep attachments on tasklist update (#16750) * Send attachments too. * Use tasklist flag. * use action="ignoreAttachments" instead of "tasklist" * Use boolean parameter. Co-authored-by: zeripath --- routers/web/repo/issue.go | 21 ++++++++++++--------- web_src/js/markup/tasklist.js | 3 ++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 9639ea82014a..ebb4983076e5 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -2128,13 +2128,6 @@ func UpdateCommentContent(ctx *context.Context) { return } - if comment.Type == models.CommentTypeComment { - if err := comment.LoadAttachments(); err != nil { - ctx.ServerError("LoadAttachments", err) - return - } - } - if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) { ctx.Error(http.StatusForbidden) return @@ -2156,8 +2149,18 @@ func UpdateCommentContent(ctx *context.Context) { return } - files := ctx.QueryStrings("files[]") - if err := updateAttachments(comment, files); err != nil { + if ctx.QueryBool("ignore_attachments") { + return + } + + if comment.Type == models.CommentTypeComment { + if err := comment.LoadAttachments(); err != nil { + ctx.ServerError("LoadAttachments", err) + return + } + } + + if err := updateAttachments(comment, ctx.QueryStrings("files[]")); err != nil { ctx.ServerError("UpdateAttachments", err) return } diff --git a/web_src/js/markup/tasklist.js b/web_src/js/markup/tasklist.js index 24b29ddb7afc..ea1a1f824a13 100644 --- a/web_src/js/markup/tasklist.js +++ b/web_src/js/markup/tasklist.js @@ -46,9 +46,10 @@ export function initMarkupTasklist() { const {updateUrl, context} = editContentZone.dataset; await $.post(updateUrl, { + ignore_attachments: true, _csrf: window.config.csrf, content: newContent, - context, + context }); rawContent.textContent = newContent; From b07c47e816c17d08d6f6ec6bba8b5edfeb719e17 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 21 Aug 2021 21:04:47 +0800 Subject: [PATCH 2/2] when the update request doesn't intend to update attachments (eg: change checkbox state), ignore attachment updates (#16762) --- routers/web/repo/issue.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index ebb4983076e5..3162e0932d7c 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -1728,10 +1728,12 @@ func UpdateIssueContent(ctx *context.Context) { return } - files := ctx.QueryStrings("files[]") - if err := updateAttachments(issue, files); err != nil { - ctx.ServerError("UpdateAttachments", err) - return + // when update the request doesn't intend to update attachments (eg: change checkbox state), ignore attachment updates + if !ctx.QueryBool("ignore_attachments") { + if err := updateAttachments(issue, ctx.QueryStrings("files[]")); err != nil { + ctx.ServerError("UpdateAttachments", err) + return + } } content, err := markdown.RenderString(&markup.RenderContext{ @@ -2149,10 +2151,6 @@ func UpdateCommentContent(ctx *context.Context) { return } - if ctx.QueryBool("ignore_attachments") { - return - } - if comment.Type == models.CommentTypeComment { if err := comment.LoadAttachments(); err != nil { ctx.ServerError("LoadAttachments", err) @@ -2160,9 +2158,12 @@ func UpdateCommentContent(ctx *context.Context) { } } - if err := updateAttachments(comment, ctx.QueryStrings("files[]")); err != nil { - ctx.ServerError("UpdateAttachments", err) - return + // when the update request doesn't intend to update attachments (eg: change checkbox state), ignore attachment updates + if !ctx.QueryBool("ignore_attachments") { + if err := updateAttachments(comment, ctx.QueryStrings("files[]")); err != nil { + ctx.ServerError("UpdateAttachments", err) + return + } } content, err := markdown.RenderString(&markup.RenderContext{