summaryrefslogtreecommitdiffstats
path: root/models/attachment.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-03-23 00:09:51 +0800
committerGitHub <noreply@github.com>2021-03-23 00:09:51 +0800
commit8567cba0d978e6ab68c337c0a80244704a15718a (patch)
treedb8794db6a32057adadda9460bf5923aee9ae89f /models/attachment.go
parent1a03fa7a4f353eb2f965cdcac39f630c281eca1e (diff)
downloadgitea-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/attachment.go')
-rw-r--r--models/attachment.go23
1 files changed, 16 insertions, 7 deletions
diff --git a/models/attachment.go b/models/attachment.go
index 478b4cd0d2..2126e6d773 100644
--- a/models/attachment.go
+++ b/models/attachment.go
@@ -125,8 +125,8 @@ func getAttachmentByUUID(e Engine, uuid string) (*Attachment, error) {
}
// GetAttachmentsByUUIDs returns attachment by given UUID list.
-func GetAttachmentsByUUIDs(uuids []string) ([]*Attachment, error) {
- return getAttachmentsByUUIDs(x, uuids)
+func GetAttachmentsByUUIDs(ctx DBContext, uuids []string) ([]*Attachment, error) {
+ return getAttachmentsByUUIDs(ctx.e, uuids)
}
func getAttachmentsByUUIDs(e Engine, uuids []string) ([]*Attachment, error) {
@@ -183,12 +183,12 @@ func getAttachmentByReleaseIDFileName(e Engine, releaseID int64, fileName string
// DeleteAttachment deletes the given attachment and optionally the associated file.
func DeleteAttachment(a *Attachment, remove bool) error {
- _, err := DeleteAttachments([]*Attachment{a}, remove)
+ _, err := DeleteAttachments(DefaultDBContext(), []*Attachment{a}, remove)
return err
}
// DeleteAttachments deletes the given attachments and optionally the associated files.
-func DeleteAttachments(attachments []*Attachment, remove bool) (int, error) {
+func DeleteAttachments(ctx DBContext, attachments []*Attachment, remove bool) (int, error) {
if len(attachments) == 0 {
return 0, nil
}
@@ -198,7 +198,7 @@ func DeleteAttachments(attachments []*Attachment, remove bool) (int, error) {
ids = append(ids, a.ID)
}
- cnt, err := x.In("id", ids).NoAutoCondition().Delete(attachments[0])
+ cnt, err := ctx.e.In("id", ids).NoAutoCondition().Delete(attachments[0])
if err != nil {
return 0, err
}
@@ -220,7 +220,7 @@ func DeleteAttachmentsByIssue(issueID int64, remove bool) (int, error) {
return 0, err
}
- return DeleteAttachments(attachments, remove)
+ return DeleteAttachments(DefaultDBContext(), attachments, remove)
}
// DeleteAttachmentsByComment deletes all attachments associated with the given comment.
@@ -230,7 +230,7 @@ func DeleteAttachmentsByComment(commentID int64, remove bool) (int, error) {
return 0, err
}
- return DeleteAttachments(attachments, remove)
+ return DeleteAttachments(DefaultDBContext(), attachments, remove)
}
// UpdateAttachment updates the given attachment in database
@@ -238,6 +238,15 @@ func UpdateAttachment(atta *Attachment) error {
return updateAttachment(x, atta)
}
+// UpdateAttachmentByUUID Updates attachment via uuid
+func UpdateAttachmentByUUID(ctx DBContext, attach *Attachment, cols ...string) error {
+ if attach.UUID == "" {
+ return fmt.Errorf("Attachement uuid should not blank")
+ }
+ _, err := ctx.e.Where("uuid=?", attach.UUID).Cols(cols...).Update(attach)
+ return err
+}
+
func updateAttachment(e Engine, atta *Attachment) error {
var sess *xorm.Session
if atta.ID != 0 && atta.UUID == "" {