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/templates/issues.html +2−82

@@ -72,13 +72,7 @@
72 72 </tbody>
73 73 </table>
74 74 </div>
75 {{if gt .Pager.Pages 1}}
76 <nav class="pager" aria-label="Issue pages">
77 {{if .Pager.PrevURL}}<a class="button secondary" href="{{.Pager.PrevURL}}" hx-get="{{.Pager.PrevURL}}" hx-target="#issue-list" hx-swap="outerHTML" hx-push-url="true">Previous</a>{{else}}<span></span>{{end}}
78 <span class="muted">Showing {{.Pager.From}}–{{.Pager.To}} of {{.Pager.Total}} · page {{.Pager.Page}} of {{.Pager.Pages}}</span>
79 {{if .Pager.NextURL}}<a class="button secondary" href="{{.Pager.NextURL}}" hx-get="{{.Pager.NextURL}}" hx-target="#issue-list" hx-swap="outerHTML" hx-push-url="true">Next</a>{{else}}<span></span>{{end}}
80 </nav>
81 {{end}}
75 {{template "pager" .Pager}}
82 76 {{else if and (eq .State "open") .Closed}}
83 77 <div class="empty-state">
84 78 <p>No open issues. {{.Closed}} closed.</p>
@@ -142,80 +136,6 @@
142 136 </section>
143 137 {{end}}
144 138
145 {{define "issue_comment_card"}}
146 <article class="comment{{if .Deleted}} deleted{{end}}" id="c-{{.ID}}">
147 {{if .Deleted}}
148 <div class="comment-deleted">{{icon "circle-x"}}Comment deleted</div>
149 {{else}}
150 <header class="comment-head">
151 <span class="avatar c{{tone .Author}}" aria-hidden="true">{{initial (who .Author)}}</span>
152 <span class="comment-author">{{who .Author}}</span>
153 {{if .ReplyTo}}<span class="reply-context">replying to {{if .ReplyToDeleted}}<a href="#c-{{.ReplyTo}}">a deleted comment</a>{{else}}<a href="#c-{{.ReplyTo}}">{{who .ReplyToName}}</a>{{end}}</span>{{end}}
154 <span class="muted">{{since .Created.Unix}}</span>
155 {{if .Anchor}}<span class="muted">on <code>{{.Anchor.Path}}:{{.Anchor.Line}}</code> ({{.Anchor.Side}} side){{if not .Current}} · <span class="conflict">the file has changed since this comment</span>{{end}}</span>{{end}}
156 <div class="comment-menu" data-comment-menu>
157 <button type="button" class="comment-menu-toggle" data-comment-menu-toggle aria-haspopup="menu" aria-expanded="false" aria-label="Comment actions">&#8943;</button>
158 <div class="comment-menu-list" data-comment-menu-list role="menu" hidden>
159 {{if .CanReply}}<button type="button" role="menuitem" data-reply-to="{{.ID}}" data-reply-author="{{who .Author}}">Reply</button>{{end}}
160 <button type="button" role="menuitem" data-copy="{{.Source}}">Copy text</button>
161 <button type="button" role="menuitem" data-copy-link="{{.ID}}">Copy link</button>
162 {{if .CanEdit}}<button type="button" role="menuitem" data-comment-edit>Edit</button>{{end}}
163 {{if .CanDelete}}
164 <form method="post" action="{{.DeleteURL}}" data-confirm="Delete this comment?">
165 <input type="hidden" name="csrf" value="{{.CSRF}}">
166 <button type="submit" role="menuitem" class="menu-danger">Delete</button>
167 </form>
168 {{end}}
169 </div>
170 </div>
171 </header>
172 <div class="comment-body md">{{.Body}}</div>
173 {{if .CanEdit}}
174 <form class="comment-edit-form" data-comment-edit-form hidden method="post" action="{{.EditURL}}" hx-post="{{.EditURL}}" hx-target="#issue-thread" hx-swap="outerHTML" hx-disabled-elt="find button[type='submit']">
175 <input type="hidden" name="csrf" value="{{.CSRF}}">
176 <textarea name="body" required>{{.Source}}</textarea>
177 <div class="form-actions">
178 <button class="secondary" type="button" data-comment-edit-cancel>Cancel</button>
179 <button type="submit">Save</button>
180 </div>
181 </form>
182 {{end}}
183 {{end}}
184 </article>
185 {{end}}
186
187 {{define "issue_thread"}}
188 <div id="issue-thread">
189 <h2>{{icon "message-square"}}Comments <span class="muted">({{len .Issue.Comments}})</span></h2>
190 {{if .ThreadError}}<p class="error">{{.ThreadError}}</p>{{end}}
191 {{range .Comments}}
192 {{template "issue_comment_card" .}}
193 {{if .Replies}}
194 <details class="thread-replies" open>
195 <summary><span class="thread-chevron">{{icon "chevron-right"}}</span>{{len .Replies}} {{if eq (len .Replies) 1}}reply{{else}}replies{{end}}</summary>
196 <div class="comment-replies">{{range .Replies}}{{template "issue_comment_card" .}}{{end}}</div>
197 </details>
198 {{end}}
199 {{else}}
200 <p class="muted">No comments yet. From a clone of this repository:
201 <code>vole issue comment {{.Issue.ID}} -m "..."</code></p>
202 {{end}}
203
204 {{if .CanDiscuss}}
205 <form id="issue-comment-form" method="post" action="/r/{{.Name}}/issues/{{.Issue.ID}}/comments" class="form-block discussion-composer" hx-post="/r/{{.Name}}/issues/{{.Issue.ID}}/comments" hx-target="#issue-thread" hx-swap="outerHTML" hx-disabled-elt="find button[type='submit']">
206 <input type="hidden" name="csrf" value="{{.CSRF}}">
207 <input type="hidden" name="reply_to" value="" data-reply-input>
208 <div class="reply-target" data-reply-target hidden>
209 <span>Replying to <strong data-reply-name></strong></span>
210 <button class="link" type="button" data-reply-clear>Cancel reply</button>
211 </div>
212 <textarea name="body" required placeholder="Leave a comment. Markdown is welcome." aria-label="Comment"></textarea>
213 <div class="form-actions"><button type="submit">{{icon "message-square"}}Comment</button></div>
214 </form>
215 {{end}}
216 </div>
217 {{end}}
218
219 139 {{define "issue"}}
220 140 {{template "header" .}}
221 141 {{template "repohead" (nav .Name "issues" .CanAdmin)}}
@@ -253,7 +173,7 @@
253 173 </div>
254 174 </article>
255 175
256 {{template "issue_thread" .}}
176 {{template "comment_thread" .Thread}}
257 177
258 178 {{if .Backlinks}}
259 179 <h2>{{icon "git-branch"}}Referenced in commits</h2>