Skip to content

Commit 0840a50

Browse files
KN4CK3Rwxiaoguang
andauthored
Keep attachments on tasklist update (#16750) (#16757)
* Send attachments too. * Use tasklist flag. * use action="ignoreAttachments" instead of "tasklist" * Use boolean parameter. * when the update request doesn't intend to update attachments (eg: change checkbox state), ignore attachment updates (#16762) Co-authored-by: wxiaoguang <[email protected]>
1 parent 5ceff8f commit 0840a50

File tree

2 files changed

+21
-16
lines changed

2 files changed

+21
-16
lines changed

routers/web/repo/issue.go

+19-15
Original file line numberDiff line numberDiff line change
@@ -1728,10 +1728,12 @@ func UpdateIssueContent(ctx *context.Context) {
17281728
return
17291729
}
17301730

1731-
files := ctx.QueryStrings("files[]")
1732-
if err := updateAttachments(issue, files); err != nil {
1733-
ctx.ServerError("UpdateAttachments", err)
1734-
return
1731+
// when update the request doesn't intend to update attachments (eg: change checkbox state), ignore attachment updates
1732+
if !ctx.QueryBool("ignore_attachments") {
1733+
if err := updateAttachments(issue, ctx.QueryStrings("files[]")); err != nil {
1734+
ctx.ServerError("UpdateAttachments", err)
1735+
return
1736+
}
17351737
}
17361738

17371739
content, err := markdown.RenderString(&markup.RenderContext{
@@ -2128,13 +2130,6 @@ func UpdateCommentContent(ctx *context.Context) {
21282130
return
21292131
}
21302132

2131-
if comment.Type == models.CommentTypeComment {
2132-
if err := comment.LoadAttachments(); err != nil {
2133-
ctx.ServerError("LoadAttachments", err)
2134-
return
2135-
}
2136-
}
2137-
21382133
if !ctx.IsSigned || (ctx.User.ID != comment.PosterID && !ctx.Repo.CanWriteIssuesOrPulls(comment.Issue.IsPull)) {
21392134
ctx.Error(http.StatusForbidden)
21402135
return
@@ -2156,10 +2151,19 @@ func UpdateCommentContent(ctx *context.Context) {
21562151
return
21572152
}
21582153

2159-
files := ctx.QueryStrings("files[]")
2160-
if err := updateAttachments(comment, files); err != nil {
2161-
ctx.ServerError("UpdateAttachments", err)
2162-
return
2154+
if comment.Type == models.CommentTypeComment {
2155+
if err := comment.LoadAttachments(); err != nil {
2156+
ctx.ServerError("LoadAttachments", err)
2157+
return
2158+
}
2159+
}
2160+
2161+
// when the update request doesn't intend to update attachments (eg: change checkbox state), ignore attachment updates
2162+
if !ctx.QueryBool("ignore_attachments") {
2163+
if err := updateAttachments(comment, ctx.QueryStrings("files[]")); err != nil {
2164+
ctx.ServerError("UpdateAttachments", err)
2165+
return
2166+
}
21632167
}
21642168

21652169
content, err := markdown.RenderString(&markup.RenderContext{

web_src/js/markup/tasklist.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ export function initMarkupTasklist() {
4646
const {updateUrl, context} = editContentZone.dataset;
4747

4848
await $.post(updateUrl, {
49+
ignore_attachments: true,
4950
_csrf: window.config.csrf,
5051
content: newContent,
51-
context,
52+
context
5253
});
5354

5455
rawContent.textContent = newContent;

0 commit comments

Comments
 (0)