Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep attachments on tasklist update (#16750) #16757

Merged
merged 3 commits into from
Aug 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions routers/web/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -2128,13 +2130,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
Expand All @@ -2156,10 +2151,19 @@ func UpdateCommentContent(ctx *context.Context) {
return
}

files := ctx.QueryStrings("files[]")
if err := updateAttachments(comment, files); err != nil {
ctx.ServerError("UpdateAttachments", err)
return
if comment.Type == models.CommentTypeComment {
if err := comment.LoadAttachments(); err != nil {
ctx.ServerError("LoadAttachments", 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{
Expand Down
3 changes: 2 additions & 1 deletion web_src/js/markup/tasklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down