-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Enable Uploading/Removing Attachments When Editing an Issue/Comment #8426
Changes from 10 commits
36a83bd
687c880
95f2393
1ec28ce
8007fc5
7c54450
99756ba
f53dbb4
dd561e7
640b958
229b0e2
96cad21
94cfed7
2a9c18e
427d9c4
ce3bdf0
4ad1190
382d484
f8d15e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -513,8 +513,9 @@ func RegisterRoutes(m *macaron.Macaron) { | |
}) | ||
}, ignSignIn) | ||
|
||
m.Group("", func() { | ||
m.Post("/attachments", repo.UploadAttachment) | ||
m.Group("/attachments", func() { | ||
m.Post("", repo.UploadAttachment) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why we get repo attachments for update and delete, but issue/comment attachments for get? I understand that there's a special case for issues/comments under creation, but attachments can also be modified on edit. By the way, this is a great opportunity to validate user permissions when updating/deleting an attachment associated to an existing issue/comment that they don't have access to. The criteria should be the same as for edit/delete the issue/comment. Perhaps this is a matter for another PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, right checking for deleting attachment should definitely be done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @guillep2k However, as you said it's okay to modify attachments on edit. Do you think I should modify my codes? If there is anything I misunderstand, please let me know 😃 @lafriks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think that changing the API is not required per se, but it would be needed when access permissions were to be checked, so it can wait for the next PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @guillep2k There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hummm... I see the problem. I underestimate the effort to check attachment permission. No wonder Gitea does not actually delete file on server when removing it from dropzone. So I guess the possible solution may be either:
Correct me if I'm wrong. 😕 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But isn't the same problem present in update as well? I think that only repo access is checked when you know the attachment GUID. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me recap:
m.Group("/attachments", func() {
m.Post("", repo.UploadAttachment)
m.Post("/delete", repo.DeleteAttachment)
}, reqSignIn) The way to fix it is either:
Correct me if I'm wrong. Thank you~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are correct 😉 User bob creates an issue with attachments Back to your options: I think we should decide whether solving this is a matter of this PR or another. Considering that update was already affected, perhaps we can treat this as a different problem. I forgot about @sapk PR. It's reasonable to expect this to be resolved there. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I found I'm wrong, UploaderID is correctly set (using sqlite). It turns out it's my codes in $.post($dropzone.data('remove-url'), {
file: file.uuid,
_csrf: $dropzone.data('csrf')
}); I used So I think checking |
||
m.Post("/delete", repo.DeleteAttachment) | ||
sapk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, reqSignIn) | ||
|
||
m.Group("/:username", func() { | ||
|
@@ -710,6 +711,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |
m.Post("/reactions/:action", bindIgnErr(auth.ReactionForm{}), repo.ChangeIssueReaction) | ||
m.Post("/lock", reqRepoIssueWriter, bindIgnErr(auth.IssueLockForm{}), repo.LockIssue) | ||
m.Post("/unlock", reqRepoIssueWriter, repo.UnlockIssue) | ||
m.Get("/attachments", repo.GetIssueAttachments) | ||
}, context.RepoMustNotBeArchived()) | ||
|
||
m.Post("/labels", reqRepoIssuesOrPullsWriter, repo.UpdateIssueLabel) | ||
|
@@ -721,6 +723,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |
m.Post("", repo.UpdateCommentContent) | ||
m.Post("/delete", repo.DeleteComment) | ||
m.Post("/reactions/:action", bindIgnErr(auth.ReactionForm{}), repo.ChangeCommentReaction) | ||
m.Get("/attachments", repo.GetCommentAttachments) | ||
}, context.RepoMustNotBeArchived()) | ||
m.Group("/labels", func() { | ||
m.Post("/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it's worth having a common function and use it from Comment and Issue to avoid duplicating code? This function is not too short but also not too long, so it sits in-between.