diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-03-23 00:09:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-23 00:09:51 +0800 |
commit | 8567cba0d978e6ab68c337c0a80244704a15718a (patch) | |
tree | db8794db6a32057adadda9460bf5923aee9ae89f /models/release.go | |
parent | 1a03fa7a4f353eb2f965cdcac39f630c281eca1e (diff) | |
download | gitea-8567cba0d978e6ab68c337c0a80244704a15718a.tar.gz gitea-8567cba0d978e6ab68c337c0a80244704a15718a.zip |
Implement delete release attachments and update release attachments' name (#14130)
* Implement delete release attachment
* Add attachments on release edit page
* Fix bug
* Finish del release attachments
* Fix frontend lint
* Fix tests
* Support edit release attachments
* Added tests
* Remove the unnecessary parameter isCreate from UpdateReleaseOrCreatReleaseFromTag
* Rename UpdateReleaseOrCreatReleaseFromTag to UpdateRelease
* Fix middle align
Diffstat (limited to 'models/release.go')
-rw-r--r-- | models/release.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/models/release.go b/models/release.go index 751d08d4d8..13b8f17218 100644 --- a/models/release.go +++ b/models/release.go @@ -6,6 +6,7 @@ package models import ( + "errors" "fmt" "sort" "strings" @@ -117,17 +118,20 @@ func UpdateRelease(ctx DBContext, rel *Release) error { } // AddReleaseAttachments adds a release attachments -func AddReleaseAttachments(releaseID int64, attachmentUUIDs []string) (err error) { +func AddReleaseAttachments(ctx DBContext, releaseID int64, attachmentUUIDs []string) (err error) { // Check attachments - attachments, err := GetAttachmentsByUUIDs(attachmentUUIDs) + attachments, err := getAttachmentsByUUIDs(ctx.e, attachmentUUIDs) if err != nil { return fmt.Errorf("GetAttachmentsByUUIDs [uuids: %v]: %v", attachmentUUIDs, err) } for i := range attachments { + if attachments[i].ReleaseID != 0 { + return errors.New("release permission denied") + } attachments[i].ReleaseID = releaseID // No assign value could be 0, so ignore AllCols(). - if _, err = x.ID(attachments[i].ID).Update(attachments[i]); err != nil { + if _, err = ctx.e.ID(attachments[i].ID).Update(attachments[i]); err != nil { return fmt.Errorf("update attachment [%d]: %v", attachments[i].ID, err) } } |