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 /routers | |
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 'routers')
-rw-r--r-- | routers/api/v1/repo/release.go | 8 | ||||
-rw-r--r-- | routers/repo/release.go | 38 |
2 files changed, 36 insertions, 10 deletions
diff --git a/routers/api/v1/repo/release.go b/routers/api/v1/repo/release.go index e9eb4e0f9e..327a2d790b 100644 --- a/routers/api/v1/repo/release.go +++ b/routers/api/v1/repo/release.go @@ -202,8 +202,8 @@ func CreateRelease(ctx *context.APIContext) { rel.Repo = ctx.Repo.Repository rel.Publisher = ctx.User - if err = releaseservice.UpdateReleaseOrCreatReleaseFromTag(ctx.User, ctx.Repo.GitRepo, rel, nil, true); err != nil { - ctx.Error(http.StatusInternalServerError, "UpdateReleaseOrCreatReleaseFromTag", err) + if err = releaseservice.UpdateRelease(ctx.User, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil { + ctx.Error(http.StatusInternalServerError, "UpdateRelease", err) return } } @@ -277,8 +277,8 @@ func EditRelease(ctx *context.APIContext) { if form.IsPrerelease != nil { rel.IsPrerelease = *form.IsPrerelease } - if err := releaseservice.UpdateReleaseOrCreatReleaseFromTag(ctx.User, ctx.Repo.GitRepo, rel, nil, false); err != nil { - ctx.Error(http.StatusInternalServerError, "UpdateReleaseOrCreatReleaseFromTag", err) + if err := releaseservice.UpdateRelease(ctx.User, ctx.Repo.GitRepo, rel, nil, nil, nil); err != nil { + ctx.Error(http.StatusInternalServerError, "UpdateRelease", err) return } diff --git a/routers/repo/release.go b/routers/repo/release.go index d89a173669..7c87fce327 100644 --- a/routers/repo/release.go +++ b/routers/repo/release.go @@ -7,6 +7,7 @@ package repo import ( "fmt" + "strings" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/base" @@ -206,7 +207,7 @@ func LatestRelease(ctx *context.Context) { ctx.Redirect(release.HTMLURL()) } -// NewRelease render creating release page +// NewRelease render creating or edit release page func NewRelease(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("repo.release.new_release") ctx.Data["PageIsReleaseList"] = true @@ -221,10 +222,17 @@ func NewRelease(ctx *context.Context) { } if rel != nil { + rel.Repo = ctx.Repo.Repository + if err := rel.LoadAttributes(); err != nil { + ctx.ServerError("LoadAttributes", err) + return + } + ctx.Data["tag_name"] = rel.TagName ctx.Data["tag_target"] = rel.Target ctx.Data["title"] = rel.Title ctx.Data["content"] = rel.Note + ctx.Data["attachments"] = rel.Attachments } } ctx.Data["IsAttachmentEnabled"] = setting.Attachment.Enabled @@ -324,9 +332,9 @@ func NewReleasePost(ctx *context.Context) { rel.PublisherID = ctx.User.ID rel.IsTag = false - if err = releaseservice.UpdateReleaseOrCreatReleaseFromTag(ctx.User, ctx.Repo.GitRepo, rel, attachmentUUIDs, true); err != nil { + if err = releaseservice.UpdateRelease(ctx.User, ctx.Repo.GitRepo, rel, attachmentUUIDs, nil, nil); err != nil { ctx.Data["Err_TagName"] = true - ctx.ServerError("UpdateReleaseOrCreatReleaseFromTag", err) + ctx.ServerError("UpdateRelease", err) return } } @@ -363,6 +371,13 @@ func EditRelease(ctx *context.Context) { ctx.Data["prerelease"] = rel.IsPrerelease ctx.Data["IsDraft"] = rel.IsDraft + rel.Repo = ctx.Repo.Repository + if err := rel.LoadAttributes(); err != nil { + ctx.ServerError("LoadAttributes", err) + return + } + ctx.Data["attachments"] = rel.Attachments + ctx.HTML(200, tplReleaseNew) } @@ -400,16 +415,27 @@ func EditReleasePost(ctx *context.Context) { return } - var attachmentUUIDs []string + const delPrefix = "attachment-del-" + const editPrefix = "attachment-edit-" + var addAttachmentUUIDs, delAttachmentUUIDs []string + var editAttachments = make(map[string]string) // uuid -> new name if setting.Attachment.Enabled { - attachmentUUIDs = form.Files + addAttachmentUUIDs = form.Files + for k, v := range ctx.Req.Form { + if strings.HasPrefix(k, delPrefix) && v[0] == "true" { + delAttachmentUUIDs = append(delAttachmentUUIDs, k[len(delPrefix):]) + } else if strings.HasPrefix(k, editPrefix) { + editAttachments[k[len(editPrefix):]] = v[0] + } + } } rel.Title = form.Title rel.Note = form.Content rel.IsDraft = len(form.Draft) > 0 rel.IsPrerelease = form.Prerelease - if err = releaseservice.UpdateReleaseOrCreatReleaseFromTag(ctx.User, ctx.Repo.GitRepo, rel, attachmentUUIDs, false); err != nil { + if err = releaseservice.UpdateRelease(ctx.User, ctx.Repo.GitRepo, + rel, addAttachmentUUIDs, delAttachmentUUIDs, editAttachments); err != nil { ctx.ServerError("UpdateRelease", err) return } |