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/git/vole.git

Write over SSH with a registered key:

git clone ssh://git@0.0.0.0: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 · 13d 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/code_tree.go +22−46

@@ -1,7 +1,6 @@
1 1 package web
2 2
3 3 import (
4 "html/template"
5 4 "net/url"
6 5 "sort"
7 6 "strings"
@@ -9,44 +8,6 @@ import (
9 8 "github.com/rodent-software/vole/core/git"
10 9 )
11 10
12 // codeView is the data shared by the full code page and the HTMX fragment that
13 // replaces its main pane. Fields under the blob section are only populated for
14 // blob views; the tree and shell fields are only populated for full pages.
15 type codeView struct {
16 Page
17 Name string
18 Ref string
19 Commit string
20 CloneURL string
21 SSHURL string
22 Site string
23 Count int
24 Branches []string
25 Latest []git.Commit
26 Tree []*treeNode
27 TreeTruncated bool
28
29 Mode string
30 Path string
31 Parent string
32 Crumbs []crumb
33 Entries []git.Entry
34
35 Readme template.HTML
36 ReadmeName string
37
38 Content string
39 Markdown template.HTML
40 Binary bool
41 Truncated bool
42 LineCut bool
43 Lines []string
44 Highlight template.HTML
45 Size int64
46 IsMarkdown bool
47 Preview bool
48 }
49
50 11 // maxTreeFiles bounds the server-rendered file tree. A repository larger than
51 12 // this still browses, but the tree shows the first slice rather than turning a
52 13 // page load into a very large DOM.
@@ -68,16 +29,31 @@ type treeNode struct {
68 29 }
69 30
70 31 // treeView is the context passed to the recursive tree template. Templates
71 // cannot build a struct literal, so this carries the repository and ref down
72 // the recursion.
32 // cannot build a struct literal, so this carries the repository, the ref and the
33 // change down the recursion.
34 //
35 // One context serves both trees because they are the same widget: the code
36 // browser writes Review empty, and a change's Files tab names the request, which
37 // is all the difference between "open this blob" and "open this changed file".
73 38 type treeView struct {
74 Name string
75 Ref string
76 Nodes []*treeNode
39 Name string
40 Ref string
41 Review string
42 Nodes []*treeNode
43 }
44
45 func treeContext(name, ref, review string, nodes []*treeNode) treeView {
46 return treeView{Name: name, Ref: ref, Review: review, Nodes: nodes}
77 47 }
78 48
79 func treeContext(name, ref string, nodes []*treeNode) treeView {
80 return treeView{Name: name, Ref: ref, Nodes: nodes}
49 // treeHref is where a row points: a blob at this ref, or the file's diff inside
50 // the change whose id is Review. The tree and the pane it swaps share it so a
51 // link and its hx-get can never disagree.
52 func treeHref(name, ref, review, path string) string {
53 if review != "" {
54 return "/r/" + name + "/requests/" + review + "/files/" + pathURL(path)
55 }
56 return "/r/" + name + "/blob/" + url.PathEscape(ref) + "/" + pathURL(path)
81 57 }
82 58
83 59 // buildFileTree flattens the repository's blobs and folds them back into the