Skip to content

Hide add / re-role / invite / approve from collection admins the stakeholder gate refuses - #3295

Merged
mstomar125 merged 1 commit into
mainfrom
issue-3294-stakeholder-gated-controls
Sep 29, 2026
Merged

mstomar125 merged 1 commit into
mainfrom
issue-3294-stakeholder-gated-controls

Conversation

@mstomar125

Copy link
Copy Markdown
Contributor

Closes #3294

Depends on cloud PR NodeSpaceAI/nodespace-cloud#200 and sync PR NodeSpaceAI/nodespace-sync#516. Merge order: cloud #200 → per-tenant rollout of 2026-09-29-stakeholder-self-check.sql → sync #516 → this PR.

What

On an open collection only its creator or an active workspace owner/admin may add another person, change their role, create an invite, or approve a join request (ADR-037 §2a, cloud #198). The cloud refuses everyone else with 42501. The collaboration view now hides those controls from collection admins that the server's stakeholder gate refuses.

Where the answer comes from: the desktop can't compute stakeholder status. It has neither the caller's Supabase uid nor the collection's server-stamped created_by. Instead, the cloud answers stakeholder_gate_allows_me(collection) (cloud #200), and sync's ListMembers returns it as optional bool stakeholder_gate_allows_caller (sync #516). That's the call this view already makes, so there's no extra round trip.

Gate semantics: the gate is always true on a restricted collection, because there the admin rule governs. So amAdmin && gate !== false equals restricted ? amAdmin : amAdmin && isStakeholder. The restricted flag is read authoritatively server-side, not from synced local state.

Changes by file:

  • src-tauri/proto/nodespace_pro.proto: refreshed from sync SchemaService: Runtime Schema Synchronization and Nested Field Support #516. The change is additive: one proto3 optional field.
  • src-tauri/src/commands/pro_sync.rs:
    • The new RosterDto { members, stakeholder_gate_allows_caller: Option<bool> } is built with From<ListMembersResponse>.
    • pro_list_members now returns it.
  • src/lib/services/membership-service.ts:
    • listMembers returns Roster { members, stakeholderGateAllowsCaller: boolean | null }.
    • Anything that isn't a boolean becomes null, never false.
  • src/lib/stores/membership.svelte.ts: each collection's cache gains stakeholderGate (null = unknown), set on every roster load.
  • collaboration-view.svelte:
    • It adds canManageOthers = amAdmin && view.stakeholderGate !== false.
    • Gated on canManageOthers: the role select, the add-existing form, the create-invite row, and approving a join request (role picker plus Approve). approve_request delegates to set_member, so approving seeds another person, which the stakeholder limit covers.
    • Still gated on amAdmin: Remove, the invite list with Revoke, and Reject. These are deletes, which the stakeholder limit doesn't cover.
    • A refused admin sees roles as badges, plus a note: "Only the collection's creator or a workspace owner/admin can add people to this open collection or change their roles."
    • Self-join is unaffected: it lives in the invitations inbox, which this PR doesn't change. Leave is unaffected too.
  • Refusal messages: friendly() maps the cloud's refusals.
    • The stakeholder seed and the stakeholder invite (42501) become "Only the collection's creator or a workspace owner/admin can …".
    • The creator-only admin grant on an open collection (23514) becomes "Only the collection's creator can make someone an admin of this open collection."

Older daemon / cloud schema not yet rolled out: there's no separate RPC, so there's no Unimplemented to handle. An older daemon never sets the field, and a new daemon on a tenant without the function (PGRST202), or with a failed or timed-out gate, leaves it unset. In every case the gate is null and nothing is hidden. If the server then refuses, the refusal is explained with the messages above.

Tests

  • Component (collaboration-view.test.ts), 10 scenarios, each asserting role select, add form, Create invite, Approve, approve-role, Remove, Revoke, Reject, the refusal note, and Leave:
    • creator;
    • workspace owner;
    • workspace admin;
    • a collection admin who isn't a stakeholder;
    • a pending workspace member holding admin;
    • a plain member;
    • a workspace admin with an editor tier;
    • a restricted-collection admin;
    • a restricted viewer;
    • an admin on an older daemon (gate unknown).
  • Component, other cases:
    • A refused admin sees a role badge instead of a select.
    • On an older daemon, the stakeholder refusal is explained for a role change and for an invite.
    • The creator-only admin-grant refusal is explained.
  • Store: the gate is stored for true, false and null, and an unloaded collection is unknown.
  • Service: snake_case→camelCase mapping; false passes through; null or missing becomes null.
  • Rust: roster_dto_carries_members_and_the_stakeholder_gate, covering members, Some(true)/Some(false), and None serializing to null.

Mutations: all 17 killed.

  • Component (C1–C12):
    • C1: the gate is ignored.
    • C2: an unknown gate hides the controls.
    • C3–C6: the role select, add form, invite row or approve fall back to amAdmin.
    • C7: the invites section is gated on canManageOthers.
    • C8–C10: each refusal mapping is removed.
    • C11: the note is removed.
    • C12: Remove is gated on canManageOthers.
  • Service (S1, S2): S1 turns unknown into false; S2 turns false into null.
  • Store (T1, T2): T1 drops the gate; T2 defaults it to false.
  • Rust: the DTO drops the gate.

Gates:

  • bun run quality:fix: passes, including workspace clippy -D warnings -D clippy::unused-async.
  • cargo clippy -p nodespace-app --all-targets -- -D warnings -D clippy::unused-async: clean.
  • bun run test:changed: passes (frontend, scripts, browser, and Rust nextest).

Follow-ups (not in this PR)

  • On an open collection only the creator may grant the admin tier (enforce_open_admin_grant). The desktop can't tell the creator from a workspace owner/admin, so the Admin option stays in the pickers, and a refused grant is explained. An email-bound admin invite on an open collection can be created but never redeemed. That predates this PR; it was found during review of cloud Optimize Embedding Re-generation: Granular Change Tracking & Single Background Processor #200.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Code Review Summary

This is a small, well-scoped change. The view's gating matches the tenant schema's enforcement, and I checked it against cloud#200's tenant-schema.sql and sync#516's list_members handler. When the gate is unknown the view hides nothing, and it only ever reads a definite false as "refused" (Rust Option<bool> → TS typeof === 'boolean' → store default null). I found no blockers.

Server parity (verified against the schema):

Control View gate Server
Role select, Add existing canManageOthers set_member → enforce_open_member_seed. Open: the caller must be a stakeholder. Restricted: the caller must be an active admin.
Create invite canManageOthers create_invite: is_collection_admin, plus is_collection_stakeholder when the collection is open
Approve (+ role) canManageOthers approve_request → set_member → the same seed trigger
Remove amAdmin remove_member is a DELETE, which the seed trigger doesn't govern
Revoke / Reject amAdmin revoke_invite (Reject reuses it) is is_collection_admin only

stakeholder_gate_allows_me returns true on a restricted collection. It returns false when the caller is inactive or can't see the collection's members. So amAdmin && gate !== false reproduces the admin-plus-stakeholder rule on both kinds of collection. It also hides the controls from a pending admin, whom is_collection_admin (active-only) would refuse anyway.

Refusal mapping: The sync daemon forwards PostgREST's message unchanged, with 42501 mapped to PermissionDenied and 23514 to FailedPrecondition. Tonic's Status Display prints it with {:?}, which doesn't escape ' inside a str. The seed regex also ends before the apostrophe in person's. All three regexes match the literal RAISE texts in the schema:

  • ...can create invites for open collection %
  • ...may add or change another person's membership...
  • only the creator may grant admin on open collection %

Because both are BEFORE triggers, enforce_open_admin_grant fires before enforce_open_member_seed (they run in alphabetical order). So an Admin pick by a non-stakeholder on an older daemon gets the creator-only message. That message is still accurate.

Reactivity: view is $derived(membership.get(id)), and patch replaces the cache entry. So canManageOthers re-derives on every roster load. The loading: true patch keeps the previous gate, so the controls don't flicker during a refresh.

I ran collaboration-view.test.ts, membership.test.ts and membership-service.test.ts locally: 55 of 55 pass. The scenario table checks every control plus the note in each of the 10 caller shapes, and the stated mutations map onto its assertions. That makes it a strong test.

Findings

Critical Issues

  • None.

Suggested Improvements

  • nodespace_pro.proto / RosterDto doc comments say "admin AND this is true, which is the server's rule on both kinds". For create_invite that is exact. It is not exact for set_member on an open collection: there can_modify_membership passes for any writer, so the server rule is "writer + stakeholder". A workspace owner who holds only an editor tier (your "workspace admin with an editor tier" scenario) can add or re-role people on the server, but the view hides those controls. The view is deliberately stricter and unchanged from before, so this is fine. Consider rewording the comment to "the client additionally requires collection admin" so a future reader doesn't take it as exact parity.
  • The pending-admin case sees the STAKEHOLDER_ONLY note ("Only the collection's creator or a workspace owner/admin can…"), but the real reason is their inactive workspace status. The note isn't wrong: a pending identity can't be a stakeholder. It could still mislead someone who is the collection's creator but is currently pending or suspended, because the note tells them the creator can do this. The edge case is rare. A follow-up could soften the note to "You can't add people or change roles in this open collection; ask its creator or a workspace owner/admin."

Nitpicks

  • Nit: collaboration-view.test.ts has a double blank line before the // --- Stakeholder gate block. Prettier also flags the long scenario rows and the roster([...]) wrapping in membership.test.ts. Prettier isn't part of quality:fix, and every touched file (including untouched parts of the .svelte file) already fails prettier --check, so this is optional.
  • Nit: STAKEHOLDER_ONLY is duplicated between the component and the test. That's acceptable for asserting user-facing copy, just noting it.
  • Repo rules are fine: no #NNNN references in the added code or comments, and the Rust test covers None → JSON null.

Verdict: APPROVE. Merge after cloud#200 → the per-tenant rollout → sync#516, as the PR body states.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Review response

The review approves with no blockers. I'm not changing code in response, because every remaining point is wording:

  1. "is the server's rule on both kinds" (proto / RosterDto comments): agreed. For set_member on an open collection the server's rule is writer + stakeholder, and the client adds the admin requirement on top, which makes it stricter. That comment lives in the proto, which comes from nodespace-sync#516, and that PR is already approved. I'd rather fix the wording in both repos in one small follow-up than re-push three approved PRs over a comment.
  2. The note for a pending or suspended creator: that caller can't write anyway. The wording could be softened in the same follow-up.
  3. Nits: the double blank line and the Prettier drift can wait. The touched files already fail prettier --check on main, and quality:fix doesn't run Prettier. The duplicated test string is left deliberately, so a copy change is caught by the test.

…eholder gate refuses

On an open collection only its creator or a workspace owner/admin may add
another person, change their role, create an invite or approve a join request
(ADR-037 §2a); the cloud refuses everyone else with 42501. The daemon's
ListMembers now reports the server's stakeholder gate (always open on a
restricted collection), carried through pro_list_members' RosterDto, the
service's Roster and the store's per-collection stakeholderGate.

CollaborationView offers those controls when the caller is a collection admin
and the gate isn't a definite false; a refused admin keeps remove / revoke /
reject, sees roles as badges, and is told who can manage the collection. An
unknown gate (older daemon or cloud schema) hides nothing, and the cloud's
refusals — stakeholder seed, stakeholder invite, creator-only admin grant — are
mapped to actionable messages.

Refreshes nodespace_pro.proto from nodespace-sync (additive optional field).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@mstomar125
mstomar125 force-pushed the issue-3294-stakeholder-gated-controls branch from 184011a to c044769 Compare September 29, 2026 12:57
@mstomar125
mstomar125 merged commit af8ddb6 into main Sep 29, 2026
@mstomar125
mstomar125 deleted the issue-3294-stakeholder-gated-controls branch September 29, 2026 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hide add-member / change-role controls on open collections from non-stakeholders (cloud now refuses them)

1 participant