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/capabilities.go +79
| @@ -0,0 +1,79 @@ | |||
| 1 | package web | ||
| 2 | |||
| 3 | // What a viewer may do in one repository, in the terms the pages use. | ||
| 4 | // | ||
| 5 | // Each function is one rule from forge/access, stated once. The tab that is | ||
| 6 | // shown, the button that is rendered, and the handler that would accept the write | ||
| 7 | // all ask the same question here, so a control cannot be offered to somebody the | ||
| 8 | // writer would refuse. | ||
| 9 | // | ||
| 10 | // The account name passed in is always the one a credential resolved to. Nothing | ||
| 11 | // here takes a name from a form field. | ||
| 12 | |||
| 13 | import "github.com/rodent-software/vole/forge/access" | ||
| 14 | |||
| 15 | // canDiscuss reports whether the account may take part in a repository at all: | ||
| 16 | // file an issue, comment on one, or open a change request. Those are one | ||
| 17 | // capability because discussing is what each of them is. | ||
| 18 | func canDiscuss(acl *access.ACL, name string) bool { | ||
| 19 | return acl != nil && name != "" && acl.CanDiscuss(name) | ||
| 20 | } | ||
| 21 | |||
| 22 | // canOpenChangeRequest reports whether the account may open a change request. It | ||
| 23 | // is separate from canDiscuss because a repository can allow discussion while | ||
| 24 | // only trusting established contributors with requests. | ||
| 25 | func canOpenChangeRequest(acl *access.ACL, name string) bool { | ||
| 26 | return acl != nil && name != "" && acl.CanOpenRequest(name) | ||
| 27 | } | ||
| 28 | |||
| 29 | // canMaintain reports whether the account holds the repository's maintainer | ||
| 30 | // capability: triaging other people's issues, approving change requests, | ||
| 31 | // allowing contributor CI, and managing releases. It says nothing about whose | ||
| 32 | // item is in front of it; that is canTriage's job. | ||
| 33 | func canMaintain(acl *access.ACL, name string) bool { | ||
| 34 | return acl != nil && name != "" && acl.CanTriage(name) | ||
| 35 | } | ||
| 36 | |||
| 37 | // canTriage reports whether the account may manage one issue or change request: | ||
| 38 | // a maintainer may triage any of them, and its author may manage their own. | ||
| 39 | func canTriage(acl *access.ACL, name, author string) bool { | ||
| 40 | return canMaintain(acl, name) || (author != "" && author == name) | ||
| 41 | } | ||
| 42 | |||
| 43 | // canApprove reports whether the account may approve change requests here. It | ||
| 44 | // does not decide whether one request may be approved: approving your own is a | ||
| 45 | // separate rule (see canApproveRequest), because the reader is owed the reason | ||
| 46 | // that applies rather than a general refusal. | ||
| 47 | func canApprove(acl *access.ACL, name string) bool { | ||
| 48 | return canMaintain(acl, name) | ||
| 49 | } | ||
| 50 | |||
| 51 | // canApproveRequest is canApprove plus the self-approval rule. It is what the | ||
| 52 | // approve control is drawn from. | ||
| 53 | func canApproveRequest(acl *access.ACL, name, author string) bool { | ||
| 54 | return canApprove(acl, name) && name != author | ||
| 55 | } | ||
| 56 | |||
| 57 | // contributorOnly reports whether the account is a contributor and nothing more, | ||
| 58 | // so every branch it may push is inside its own contrib/ namespace. The rule | ||
| 59 | // matters to change requests: a contributor must open one from their own branch, | ||
| 60 | // because that is the only branch the pre-receive hook would have let them write. | ||
| 61 | func contributorOnly(acl *access.ACL, name string) bool { | ||
| 62 | return acl != nil && name != "" && acl.RoleFor(name) == access.Contribute | ||
| 63 | } | ||
| 64 | |||
| 65 | // canAdminister reports whether the account holds the repository's admin role. | ||
| 66 | // An instance admin gets this on every repository through EffectiveRole, which is | ||
| 67 | // why the read path asks canRead rather than this. | ||
| 68 | func canAdminister(acl *access.ACL, name string) bool { | ||
| 69 | return acl != nil && name != "" && acl.Can(name, access.Admin) | ||
| 70 | } | ||
| 71 | |||
| 72 | // canModerateComment reports whether the account may edit or delete a comment: | ||
| 73 | // the account that wrote it, or an admin repairing a thread. | ||
| 74 | func canModerateComment(acl *access.ACL, name, author string) bool { | ||
| 75 | if acl == nil || name == "" { | ||
| 76 | return false | ||
| 77 | } | ||
| 78 | return name == author || acl.RoleFor(name).AtLeast(access.Admin) | ||
| 79 | } | ||