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/templates/code.html +1−57

@@ -59,7 +59,7 @@
59 59 </div>
60 60 {{if .Tree}}
61 61 <div class="tree-scroll">
62 {{template "tree_nodes" (treeContext .Name .Ref .Tree)}}
62 {{template "tree_nodes" (treeContext .Name .Ref "" .Tree)}}
63 63 </div>
64 64 {{if .TreeTruncated}}<p class="tree-note">Showing the first 4,000 files.</p>{{end}}
65 65 {{else}}
@@ -68,30 +68,6 @@
68 68 </aside>
69 69 {{end}}
70 70
71 {{define "tree_nodes"}}
72 <ul class="tree-list">
73 {{range .Nodes}}
74 <li>
75 {{if eq .Type "tree"}}
76 <details class="tree-dir{{if .Active}} active{{end}}" data-path="{{.Path}}"{{if .Open}} open{{end}}>
77 <summary class="tree-row">
78 <span class="tree-chevron">{{icon "chevron-right"}}</span>
79 <span class="tree-icon">{{icon "folder"}}</span>
80 <span class="tree-name" title="{{.Path}}">{{.Name}}</span>
81 </summary>
82 <div class="tree-children">{{template "tree_nodes" (treeContext $.Name $.Ref .Children)}}</div>
83 </details>
84 {{else}}
85 <a class="tree-row tree-file{{if .Active}} active{{end}}" data-path="{{.Path}}" href="/r/{{$.Name}}/blob/{{esc $.Ref}}/{{pathurl .Path}}" hx-get="/r/{{$.Name}}/blob/{{esc $.Ref}}/{{pathurl .Path}}" hx-target="#code-main" hx-swap="outerHTML" hx-push-url="true" title="{{.Path}}">
86 <span class="tree-icon {{fileclass .Name}}">{{icon (fileicon .Name)}}</span>
87 <span class="tree-name">{{.Name}}</span>
88 </a>
89 {{end}}
90 </li>
91 {{end}}
92 </ul>
93 {{end}}
94
95 71 {{define "code_main"}}
96 72 <section id="code-main" class="code-main" data-path="{{.Path}}" data-mode="{{.Mode}}" data-ref="{{.Ref}}">
97 73 {{if eq .Mode "blob"}}{{template "code_blob" .}}
@@ -197,35 +173,3 @@ git push -u origin {{.Ref}}</pre>
197 173 {{end}}
198 174 {{end}}
199 175 {{end}}
200
201 {{define "commits"}}
202 {{template "header" .}}
203 {{template "repohead" (nav .Name "code" .CanAdmin)}}
204 <div class="page-head">
205 <div class="page-head-main">
206 <h1>History</h1>
207 <p class="page-sub"><a href="/r/{{.Name}}/code?ref={{esc .Ref}}">{{.Ref}}</a> · newest first</p>
208 </div>
209 </div>
210 <div class="panel">
211 {{template "commitlist" .}}
212 </div>
213 {{template "footer" .}}
214 {{end}}
215
216 {{define "commit"}}
217 {{template "header" .}}
218 {{template "repohead" (nav .Name "code" .CanAdmin)}}
219 <div class="page-head">
220 <div class="page-head-main">
221 <h1>{{.Commit.Subject}}</h1>
222 <p class="page-sub">
223 <span class="sha">{{.Commit.SHA}}</span> · {{.Commit.Author}} · {{since .Commit.When}}
224 {{if .Parents}} · parent {{range .Parents}}<a class="sha" href="/r/{{$.Name}}/commit/{{.}}">{{short .}}</a> {{end}}{{end}}
225 </p>
226 </div>
227 </div>
228 {{if and .Body (ne .Body .Commit.Subject)}}<pre>{{.Body}}</pre>{{end}}
229 {{template "diff" .}}
230 {{template "footer" .}}
231 {{end}}