vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Simplify release file management
fdd0b3e8373da4c684c73d88f997c3917966ac50 · Keenan Nemetz · 17d ago · parent c5187449
Simplify release file management Drop rename and move from the CLI and browser, outline the files table instead of wrapping it in a card, and label the release-page action Manage files.
server/web/release_files.go +6−119
| @@ -3,8 +3,8 @@ package web | |||
| 3 | 3 | // Release file management. Attaching has its own page because a multipart form | |
| 4 | 4 | // is not a release note: the release page lists the files and links here for the | |
| 5 | 5 | // file operations. Every write is the same metadata pointer write the CLI makes, | |
| 6 | // so a file moved or removed in the browser is indistinguishable from one moved | ||
| 7 | // with `vole release move` or `vole release remove`. | ||
| 6 | // so a file removed in the browser is indistinguishable from one removed with | ||
| 7 | // `vole release remove`. | ||
| 8 | 8 | ||
| 9 | 9 | import ( | |
| 10 | 10 | "fmt" | |
| @@ -24,7 +24,7 @@ type releaseAttachView struct { | |||
| 24 | 24 | Locked bool | |
| 25 | 25 | } | |
| 26 | 26 | ||
| 27 | // ReleaseAttachPage is GET /<name>/releases/<tag>/attach. The form is offered by | ||
| 27 | // ReleaseAttachPage is GET /<name>/releases/<tag>/attach. The page is offered by | ||
| 28 | 28 | // the release page as a link, not inline, because a browser upload is a page of | |
| 29 | 29 | // its own: it has its own body limit, its own refusal messages, and a directory | |
| 30 | 30 | // control that belongs beside the files rather than under the notes. | |
| @@ -46,7 +46,7 @@ func (w *Web) ReleaseAttachPage(rw http.ResponseWriter, r *http.Request) { | |||
| 46 | 46 | return | |
| 47 | 47 | } | |
| 48 | 48 | view := releaseAttachView{ | |
| 49 | Page: w.page(r, m.Name+" · attach files"), | ||
| 49 | Page: w.page(r, m.Name+" · manage files"), | ||
| 50 | 50 | Name: m.Name, | |
| 51 | 51 | Tag: t.Name, | |
| 52 | 52 | UploadCap: w.attachLimit(), | |
| @@ -65,27 +65,6 @@ func (w *Web) ReleaseAttachPage(rw http.ResponseWriter, r *http.Request) { | |||
| 65 | 65 | w.render(rw, "release_attach", view, status) | |
| 66 | 66 | } | |
| 67 | 67 | ||
| 68 | type releaseFileView struct { | ||
| 69 | Page | ||
| 70 | Name string | ||
| 71 | Tag string | ||
| 72 | Path string | ||
| 73 | NewPath string | ||
| 74 | Error string | ||
| 75 | Locked bool | ||
| 76 | } | ||
| 77 | |||
| 78 | func (w *Web) releaseFileView(r *http.Request, m *repo.Meta, tag, path, newpath, msg string) releaseFileView { | ||
| 79 | return releaseFileView{ | ||
| 80 | Page: w.page(r, m.Name+" · "+path), | ||
| 81 | Name: m.Name, | ||
| 82 | Tag: tag, | ||
| 83 | Path: path, | ||
| 84 | NewPath: newpath, | ||
| 85 | Error: msg, | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | 68 | // releaseFileAt finds the attached file the form names. | |
| 90 | 69 | func (w *Web) releaseFileAt(r *http.Request, m *repo.Meta, tag, name string) (metadata.Artifact, bool) { | |
| 91 | 70 | for _, a := range w.releaseArtifacts(r, m, tag) { | |
| @@ -96,102 +75,10 @@ func (w *Web) releaseFileAt(r *http.Request, m *repo.Meta, tag, name string) (me | |||
| 96 | 75 | return metadata.Artifact{}, false | |
| 97 | 76 | } | |
| 98 | 77 | ||
| 99 | // ReleaseFileEditPage is GET /<name>/releases/<tag>/files/edit?path=<path>. One | ||
| 100 | // form renames or moves the file; a second deletes it. | ||
| 101 | func (w *Web) ReleaseFileEditPage(rw http.ResponseWriter, r *http.Request) { | ||
| 102 | m, ok := w.open(rw, r) | ||
| 103 | if !ok { | ||
| 104 | return | ||
| 105 | } | ||
| 106 | if _, ok := w.requireHTMLUser(rw, r); !ok { | ||
| 107 | return | ||
| 108 | } | ||
| 109 | if !w.canManageReleases(r, m) { | ||
| 110 | w.notFound(rw, r) | ||
| 111 | return | ||
| 112 | } | ||
| 113 | t, err := m.Git().Tag(r.PathValue("tag")) | ||
| 114 | if err != nil { | ||
| 115 | w.notFound(rw, r) | ||
| 116 | return | ||
| 117 | } | ||
| 118 | name := r.URL.Query().Get("path") | ||
| 119 | if err := metadata.ValidArtifactPath(name); err != nil { | ||
| 120 | w.notFound(rw, r) | ||
| 121 | return | ||
| 122 | } | ||
| 123 | if _, found := w.releaseFileAt(r, m, t.Name, name); !found { | ||
| 124 | w.notFound(rw, r) | ||
| 125 | return | ||
| 126 | } | ||
| 127 | view := w.releaseFileView(r, m, t.Name, name, name, "") | ||
| 128 | status := 0 | ||
| 129 | if msg := w.releaseRefusal(m, t); msg != "" { | ||
| 130 | view.Locked = true | ||
| 131 | view.Error = msg | ||
| 132 | status = http.StatusConflict | ||
| 133 | if !t.Annotated { | ||
| 134 | status = http.StatusBadRequest | ||
| 135 | } | ||
| 136 | } | ||
| 137 | w.render(rw, "release_file_form", view, status) | ||
| 138 | } | ||
| 139 | |||
| 140 | // MoveReleaseFile is POST /<name>/releases/<tag>/files/edit. The old path and the | ||
| 141 | // new path are both form fields because an artifact path may contain slashes and | ||
| 142 | // spaces, which read badly in a URL and are easy to double-escape there. | ||
| 143 | func (w *Web) MoveReleaseFile(rw http.ResponseWriter, r *http.Request) { | ||
| 144 | ctx, ok := w.beginWrite(rw, r, maxSmallForm) | ||
| 145 | if !ok { | ||
| 146 | return | ||
| 147 | } | ||
| 148 | m := ctx.Repo | ||
| 149 | if !canMaintain(ctx.ACL, ctx.Name) { | ||
| 150 | w.notFound(rw, r) | ||
| 151 | return | ||
| 152 | } | ||
| 153 | tag := r.PathValue("tag") | ||
| 154 | path := r.PostFormValue("path") | ||
| 155 | newpath := r.PostFormValue("newpath") | ||
| 156 | t, err := m.Git().Tag(tag) | ||
| 157 | if err != nil { | ||
| 158 | w.notFound(rw, r) | ||
| 159 | return | ||
| 160 | } | ||
| 161 | view := w.releaseFileView(r, m, t.Name, path, newpath, "") | ||
| 162 | fail := func(status int, msg string) { | ||
| 163 | view.Error = msg | ||
| 164 | w.render(rw, "release_file_form", view, status) | ||
| 165 | } | ||
| 166 | if msg := w.releaseRefusal(m, t); msg != "" { | ||
| 167 | status := http.StatusConflict | ||
| 168 | if !t.Annotated { | ||
| 169 | status = http.StatusBadRequest | ||
| 170 | } | ||
| 171 | fail(status, msg) | ||
| 172 | return | ||
| 173 | } | ||
| 174 | if err := metadata.ValidArtifactPath(path); err != nil { | ||
| 175 | fail(http.StatusBadRequest, err.Error()) | ||
| 176 | return | ||
| 177 | } | ||
| 178 | if _, found := w.releaseFileAt(r, m, t.Name, path); !found { | ||
| 179 | fail(http.StatusBadRequest, "That file is no longer attached to this release.") | ||
| 180 | return | ||
| 181 | } | ||
| 182 | if err := metadata.MoveReleasePointer(m.Git(), metadata.Ref, t.Name, path, newpath, | ||
| 183 | fmt.Sprintf("release: %s move %s -> %s (web)", t.Name, path, newpath), ctx.Name); err != nil { | ||
| 184 | fail(http.StatusBadRequest, "cannot move the file: "+err.Error()) | ||
| 185 | return | ||
| 186 | } | ||
| 187 | w.refreshReleaseEvents(m) | ||
| 188 | w.audit("web.release.file.move", ctx.Name, m.Name, fmt.Sprintf("%s: %s -> %s", t.Name, path, newpath)) | ||
| 189 | http.Redirect(rw, r, "/"+m.Name+"/releases/"+pathURL(t.Name), http.StatusSeeOther) | ||
| 190 | } | ||
| 191 | |||
| 192 | 78 | // DeleteReleaseFile is POST /<name>/releases/<tag>/files/delete. It removes the | |
| 193 | 79 | // pointer; the object store keeps the bytes until gc proves nothing else names | |
| 194 | // them. | ||
| 80 | // them. The form sits on the release page and on the manage-files page, so the | ||
| 81 | // action is reachable without a second navigational step. | ||
| 195 | 82 | func (w *Web) DeleteReleaseFile(rw http.ResponseWriter, r *http.Request) { | |
| 196 | 83 | ctx, ok := w.beginWrite(rw, r, maxSmallForm) | |
| 197 | 84 | if !ok { | |