Files
CatoandClaude Opus 5 c353223f0e refactor(groups): one permission answer instead of five (#1077)
"May this person do this here?" had five implementations in two files, and
they disagreed with each other.

The disagreement was real, not stylistic. Fifteen preset cells said
`vote_required`. Through `canPerformAction` that returned allowed:true with a
`requiresVote` flag; through `checkGroupPermission` the same cell returned
false. Nothing in src/ ever read the flag, so no proposal was raised and no
vote was collected — the only thing enforcing a "vote" was the settings page
declining to render its delete button, which the API never checked. One door
opened, the other did not, and neither counted anything.

Collapsed to what the database will actually honour. Founders and admins keep
the abilities RLS already grants them; members stop being told yes for a write
Postgres rejects, except create_project, which no policy gates. All 81 cells
are now allow or deny. Real deliberation — proposals, quorum, a record of why
— belongs in Solon, not in a string in a config file.

With only two states the implementations stop disagreeing, so the merge became
mechanical: checkGroupPermission is now a thin adapter over canPerformAction,
keeping only canView/canJoin, which are visibility rather than authority and
have no cell in RolePermissions. getGroupPermissions, canPerformActions and
getMemberPermissions are deleted — repo-wide grep finds no caller for any of
them. canPerformActions mattered: it still carried the `if (!groupId) allow
everything` bug that was closed in canPerformAction, the same rule written
twice with the fix applied once.

PERMISSION_TO_ACTION is now typed against RolePermissions instead of string.
It previously mapped canView/canJoin to 'view' and 'join' — two actions no
preset defines — which is why the lookup needed a cast to compile.

`canView` and `canJoin` stay in the adapter, and `canJoin` now says what it
means. The old code answered it by looking the key up in RolePermissions under
'join', which no preset defines, so the lookup returned undefined and the
comparison to 'allow' was false — a member could not "join" a group they were
already in, which is right, but only by accident. It is now that answer on
purpose. No caller is affected: `canJoin` has none, and `canView` is unchanged
for all four of its call sites.

Tests go from 14 to 24. One new block asserts both doors give the same answer
for every action across all three roles, using an id-aware mock: the previous
mock answered every filter identically, so a swapped (groupId, userId) wire-up
passed. Mutation-proved — swapping the arguments now fails three tests. A
second block pins the visibility rules, including the member-cannot-rejoin
case; letting a member join again fails exactly that test.


Claude-Session: https://claude.ai/code/session_01Nx1u7uUWsgi3MagxbmQmPN

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-17 08:15:55 -07:00
..