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.
Move channel forms off the releases page
ea6ce9fe5d829a7f4153793f0a096d00331f7e29 · Keenan Nemetz · 17d ago · parent de72893e
Move channel forms off the releases page Create and edit channels on focused release subpages, leaving the releases page with the read-only channel list and its row actions. The new-release target is now a grouped branch and tag picker instead of a free-text field, matching the channel form's selection of annotated releases.
server/web/channels.go +112−4
| @@ -63,6 +63,113 @@ type channelRow struct { | |||
| 63 | 63 | Body template.HTML | |
| 64 | 64 | } | |
| 65 | 65 | ||
| 66 | // channelForm is the browser form for creating or moving one channel. Editing | ||
| 67 | // locks the name: the CLI has no rename either, and a channel's identity is its | ||
| 68 | // URL. | ||
| 69 | type channelForm struct { | ||
| 70 | Name string | ||
| 71 | Tag string | ||
| 72 | Description string | ||
| 73 | Editing bool | ||
| 74 | Error string | ||
| 75 | } | ||
| 76 | |||
| 77 | type channelFormView struct { | ||
| 78 | Page | ||
| 79 | Name string | ||
| 80 | Tags []git.Tag | ||
| 81 | Channel channelForm | ||
| 82 | MissingTarget bool | ||
| 83 | } | ||
| 84 | |||
| 85 | // canManageChannels is the page-and-handler check for the channel form. It is the | ||
| 86 | // release maintainer capability plus a store to write to. | ||
| 87 | func (w *Web) canManageChannels(r *http.Request, m *repo.Meta) bool { | ||
| 88 | return w.ChannelStore != nil && w.canManageReleases(r, m) | ||
| 89 | } | ||
| 90 | |||
| 91 | // channelFormView lists only annotated tags: a channel names a release, and a | ||
| 92 | // select of valid targets is more honest than a text box that can name anything. | ||
| 93 | func (w *Web) channelFormView(r *http.Request, m *repo.Meta, tags []git.Tag, form channelForm) channelFormView { | ||
| 94 | annotated := make([]git.Tag, 0, len(tags)) | ||
| 95 | found := false | ||
| 96 | for _, t := range tags { | ||
| 97 | if !t.Annotated { | ||
| 98 | continue | ||
| 99 | } | ||
| 100 | annotated = append(annotated, t) | ||
| 101 | if t.Name == form.Tag { | ||
| 102 | found = true | ||
| 103 | } | ||
| 104 | } | ||
| 105 | title := m.Name + " · new channel" | ||
| 106 | if form.Editing { | ||
| 107 | title = m.Name + " · channel " + form.Name | ||
| 108 | } | ||
| 109 | return channelFormView{ | ||
| 110 | Page: w.page(r, title), | ||
| 111 | Name: m.Name, | ||
| 112 | Tags: annotated, | ||
| 113 | Channel: form, | ||
| 114 | MissingTarget: form.Tag != "" && !found, | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | func (w *Web) ChannelNewPage(rw http.ResponseWriter, r *http.Request) { | ||
| 119 | m, ok := w.open(rw, r) | ||
| 120 | if !ok { | ||
| 121 | return | ||
| 122 | } | ||
| 123 | if _, ok := w.requireHTMLUser(rw, r); !ok { | ||
| 124 | return | ||
| 125 | } | ||
| 126 | if !w.canManageChannels(r, m) { | ||
| 127 | w.notFound(rw, r) | ||
| 128 | return | ||
| 129 | } | ||
| 130 | tags, err := m.Git().Tags() | ||
| 131 | if err != nil { | ||
| 132 | w.serverError(rw, r, "cannot list tags: "+err.Error()) | ||
| 133 | return | ||
| 134 | } | ||
| 135 | w.render(rw, "channel_form", w.channelFormView(r, m, tags, channelForm{}), 0) | ||
| 136 | } | ||
| 137 | |||
| 138 | func (w *Web) ChannelEditPage(rw http.ResponseWriter, r *http.Request) { | ||
| 139 | m, ok := w.open(rw, r) | ||
| 140 | if !ok { | ||
| 141 | return | ||
| 142 | } | ||
| 143 | if _, ok := w.requireHTMLUser(rw, r); !ok { | ||
| 144 | return | ||
| 145 | } | ||
| 146 | if !w.canManageChannels(r, m) { | ||
| 147 | w.notFound(rw, r) | ||
| 148 | return | ||
| 149 | } | ||
| 150 | name := strings.TrimSpace(r.URL.Query().Get("channel")) | ||
| 151 | if err := channel.ValidName(name); err != nil { | ||
| 152 | w.notFound(rw, r) | ||
| 153 | return | ||
| 154 | } | ||
| 155 | ch, ok := w.channel(m, name) | ||
| 156 | if !ok { | ||
| 157 | w.notFound(rw, r) | ||
| 158 | return | ||
| 159 | } | ||
| 160 | tags, err := m.Git().Tags() | ||
| 161 | if err != nil { | ||
| 162 | w.serverError(rw, r, "cannot list tags: "+err.Error()) | ||
| 163 | return | ||
| 164 | } | ||
| 165 | w.render(rw, "channel_form", w.channelFormView(r, m, tags, channelForm{ | ||
| 166 | Name: ch.Name, | ||
| 167 | Tag: ch.Release, | ||
| 168 | Description: ch.Description, | ||
| 169 | Editing: true, | ||
| 170 | }), 0) | ||
| 171 | } | ||
| 172 | |||
| 66 | 173 | // SetChannel creates or moves a channel from the browser. It is the form of | |
| 67 | 174 | // `vole release channel set`: the same maintain check, annotated-tag requirement, | |
| 68 | 175 | // description bound, and audit record, with the actor taken from the session. | |
| @@ -91,11 +198,12 @@ func (w *Web) SetChannel(rw http.ResponseWriter, r *http.Request) { | |||
| 91 | 198 | w.serverError(rw, r, "cannot list tags: "+err.Error()) | |
| 92 | 199 | return | |
| 93 | 200 | } | |
| 94 | view := w.releasesView(r, m, tags) | ||
| 95 | view.ChannelForm = channelForm{Name: name, Tag: tag, Description: description, Editing: editing} | ||
| 201 | view := w.channelFormView(r, m, tags, channelForm{ | ||
| 202 | Name: name, Tag: tag, Description: description, Editing: editing, | ||
| 203 | }) | ||
| 96 | 204 | fail := func(msg string) { | |
| 97 | view.ChannelForm.Error = msg | ||
| 98 | w.render(rw, "releases", view, http.StatusBadRequest) | ||
| 205 | view.Channel.Error = msg | ||
| 206 | w.render(rw, "channel_form", view, http.StatusBadRequest) | ||
| 99 | 207 | } | |
| 100 | 208 | ||
| 101 | 209 | if err := channel.ValidName(name); err != nil { | |