Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software:2222/vole.git

A free and open-source forge that lives in your Git repo.

Reorganise the web package around one implementation per rule

c717d4eb92b4257b05fa065918b0071f6302f53e · Keenan Nemetz · 14d ago · parent 4506a4d3

Reorganise the web package around one implementation per rule

server/web had grown by feature, so several rules and widgets existed twice: the
comment stack for issues and change requests, the pager, the file tree, the write
preamble, and the ACL predicates. Each pair agreed today and would drift
tomorrow. No route, stored format, or permission rule changes; the few behaviour
differences found along the way are listed at the end.

Files now say what they answer:

  web.go          the Web type, render, open, the error pages
  page.go         Page, pageSection, who, nav
  templatefuncs.go the template function map, with the escaping rules noted
  ui.go           relative time, avatars, breadcrumbs, the pager
  markdown.go     the goldmark and bluemonday boundary
  codebrowser.go  the code browser, out of web.go
  tokens.go       the label/assignee token input
  rolepicker.go   the role control, out of admin.go
  comments.go     the comment view, thread builder, action menus, snippet
  comment_writes.go  add, edit and delete a comment, for both surfaces
  write_context.go   beginWrite/beginPost/beginAdminPost, fail, refuse
  capabilities.go    the ACL rules a page and a handler share
  audit.go        the audit log
  request_view.go the change conversation page, out of requests.go
  admin_access.go the instance-admin access rules, out of settings.go

A comment is one thing, so it has one view and one thread builder: metadata.Comment
is the same type on both surfaces and only a change request can anchor one to a
diff line. Adding, editing and deleting are one implementation each, with a
commentTopic naming what differs per surface. The pager is one control for issues,
changes and the instance feed; the file tree is one widget for the code browser
and a change's Files tab.

Every write starts at beginWrite (session, body bound, CSRF, repository, rules,
form) and asks capabilities.go for the one rule it needs, so the control a page
draws and the check a handler makes cannot disagree. A rejected write answers
through refuse; a write that fails for another reason answers through fail, which
re-renders the section for HTMX and returns text otherwise.

Templates follow the same split: chrome.html, components.html, diff.html and
role-picker.html hold what more than one surface renders, and each page owns its
fragments. The route table moved to routes.go, one function per surface.

Behaviour changes found while unifying:

  - A reply cycle (two comments answering each other, possible through a pushed
    metadata branch) used to drop both comments from the page; anything the walk
    does not reach is now emitted as a root.
  - A rejected anchored comment keeps its "Commenting on path:line" note and
    hidden anchor fields, so the reviewer does not have to pick the line again.
  - A repository whose access rules cannot be read answers 500 rather than 403;
    the account was being blamed for a broken instance.
  - Pager wording is now "Showing a-b of n / page x of y" with Previous/Next
    everywhere, and the instance feed's page links keep their kind filter.
  - The activity feed, issue list and change list share one page control.

Docs: docs/ui-plan.md gains a "Where the code lives" map, the write gate, the
shared comment model, the route table, and rules for rejected writes, shared
template fragments, and the stylesheet's section order. The passkey script is now
an ordinary asset (static/auth.js) under the same CSP as the rest.

server/web/release_actions.go +15−39

@@ -10,7 +10,6 @@ import (
10 10 "net/http"
11 11 "strings"
12 12
13 "github.com/rodent-software/vole/forge/access"
14 13 "github.com/rodent-software/vole/forge/repo"
15 14 "github.com/rodent-software/vole/metadata"
16 15 )
@@ -29,13 +28,14 @@ type releaseFormView struct {
29 28 Error string
30 29 }
31 30
31 // canManageReleases is the read-side half of the release writes: the pages that
32 // offer the form and the handlers that accept it ask the same capability.
32 33 func (w *Web) canManageReleases(r *http.Request, m *repo.Meta) bool {
33 pr := w.principal(r)
34 if pr == nil {
34 acl, err := m.ACL()
35 if err != nil {
35 36 return false
36 37 }
37 acl, err := m.ACL()
38 return err == nil && acl.RoleFor(pr.account.Name).AtLeast(access.Maintain)
38 return canMaintain(acl, w.accountName(r))
39 39 }
40 40
41 41 func (w *Web) releaseFormView(r *http.Request, m *repo.Meta, editing bool, tag, target, notes, msg string) releaseFormView {
@@ -62,27 +62,15 @@ func (w *Web) ReleaseNewPage(rw http.ResponseWriter, r *http.Request) {
62 62 }
63 63
64 64 func (w *Web) CreateRelease(rw http.ResponseWriter, r *http.Request) {
65 m, ok := w.open(rw, r)
65 ctx, ok := w.beginWrite(rw, r, maxSmallForm)
66 66 if !ok {
67 67 return
68 68 }
69 pr, ok := w.requireHTMLUser(rw, r)
70 if !ok {
71 return
72 }
73 r.Body = http.MaxBytesReader(rw, r.Body, 1<<20)
74 if !w.checkCSRF(r) {
75 http.Error(rw, "bad request", http.StatusForbidden)
76 return
77 }
78 if !w.canManageReleases(r, m) {
69 m := ctx.Repo
70 if !canMaintain(ctx.ACL, ctx.Name) {
79 71 w.notFound(rw, r)
80 72 return
81 73 }
82 if err := r.ParseForm(); err != nil {
83 http.Error(rw, "cannot read the form", http.StatusBadRequest)
84 return
85 }
86 74 tag := strings.TrimSpace(r.PostFormValue("tag"))
87 75 target := strings.TrimSpace(r.PostFormValue("target"))
88 76 notes := strings.TrimRight(r.PostFormValue("notes"), "\n")
@@ -120,11 +108,11 @@ func (w *Web) CreateRelease(rw http.ResponseWriter, r *http.Request) {
120 108 return
121 109 }
122 110 }
123 if err := g.WriteAnnotatedTag(tag, commit, notes, pr.account.Name, false); err != nil {
111 if err := g.WriteAnnotatedTag(tag, commit, notes, ctx.Name, false); err != nil {
124 112 fail(err.Error())
125 113 return
126 114 }
127 w.audit("web.release.create", pr.account.Name, m.Name+" "+tag)
115 w.audit("web.release.create", ctx.Name, m.Name+" "+tag)
128 116 http.Redirect(rw, r, "/r/"+m.Name+"/releases/"+pathURL(tag), http.StatusSeeOther)
129 117 }
130 118
@@ -158,27 +146,15 @@ func (w *Web) ReleaseEditPage(rw http.ResponseWriter, r *http.Request) {
158 146 }
159 147
160 148 func (w *Web) UpdateRelease(rw http.ResponseWriter, r *http.Request) {
161 m, ok := w.open(rw, r)
162 if !ok {
163 return
164 }
165 pr, ok := w.requireHTMLUser(rw, r)
149 ctx, ok := w.beginWrite(rw, r, maxSmallForm)
166 150 if !ok {
167 151 return
168 152 }
169 r.Body = http.MaxBytesReader(rw, r.Body, 1<<20)
170 if !w.checkCSRF(r) {
171 http.Error(rw, "bad request", http.StatusForbidden)
172 return
173 }
174 if !w.canManageReleases(r, m) {
153 m := ctx.Repo
154 if !canMaintain(ctx.ACL, ctx.Name) {
175 155 w.notFound(rw, r)
176 156 return
177 157 }
178 if err := r.ParseForm(); err != nil {
179 http.Error(rw, "cannot read the form", http.StatusBadRequest)
180 return
181 }
182 158 tag := strings.TrimSpace(r.PostFormValue("tag"))
183 159 notes := strings.TrimRight(r.PostFormValue("notes"), "\n")
184 160 t, err := m.Git().Tag(tag)
@@ -207,10 +183,10 @@ func (w *Web) UpdateRelease(rw http.ResponseWriter, r *http.Request) {
207 183 fail("Release notes are limited to 64 KiB.")
208 184 return
209 185 }
210 if err := m.Git().WriteAnnotatedTag(t.Name, t.Commit, notes, pr.account.Name, true); err != nil {
186 if err := m.Git().WriteAnnotatedTag(t.Name, t.Commit, notes, ctx.Name, true); err != nil {
211 187 fail(err.Error())
212 188 return
213 189 }
214 w.audit("web.release.edit", pr.account.Name, m.Name+" "+t.Name)
190 w.audit("web.release.edit", ctx.Name, m.Name+" "+t.Name)
215 191 http.Redirect(rw, r, "/r/"+m.Name+"/releases/"+pathURL(t.Name), http.StatusSeeOther)
216 192 }