Skip to content

feat(teams): preview a member's or role's vault permissions - #151

Merged
kipavy merged 8 commits into
mainfrom
feat/permission-preview
Nov 16, 2026
Merged

kipavy merged 8 commits into
mainfrom
feat/permission-preview

Conversation

@kipavy

@kipavy kipavy commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Adds POST /v1/teams/:team_id/permissions/preview. It returns what a team member, or a role, can see and do in the team vault, and optionally what that would become under an unsaved draft. The client uses it for a read-only "View as" mode and for "Preview as role". Nothing is written. Saving still goes through the existing member and role endpoints.

Request

  • subject: { "type": "member", "user_id" } or { "type": "role", "role_id" }
  • draft (optional):
    • for a member: { "role_ids", "allow", "deny" }
    • for a role: { "permissions" }
    • Masks are clamped to ALL_PERMISSIONS.
  • scope: "full" (default) or "vault_key_gate"

Gates

Gates run in this order, before the subject is looked up:

  1. The caller must be a team member.
  2. A member subject needs MANAGE_MEMBERS. A role subject needs MANAGE_ROLES.
  3. The full scope is Business-only (402 below Business). vault_key_gate is never plan-gated, so the Teams-plan "this removes their vault key" warning keeps working.

Response

{ locked, current, draft, affected }, where each preview is { team_bits, objects: { id: { mask, rule_set_id } }, rule_sets: { id: layers }, holds_vault_key_gate }.

  • objects only lists objects the caller can view.
  • rule_sets only lists sets where the caller has object-level MANAGE_ROLES, so a folder locked against managers stays locked.
  • The vault key gate uses the real definition (team CONNECT, or CONNECT on any live object), including objects the caller cannot see.
  • For a role draft, affected lists the holders whose visible masks change and the holders who would lose the vault key.
  • vault_key_gate scope returns empty objects / rule_sets.

Status codes

Code When
403 Missing permission
404 Caller not in the team, or a role from another team
402 full scope below Business
400 Draft shape doesn't match the subject (role draft on a member and vice versa), a draft on a built-in role, or a draft role_ids entry from another team
422 Body fails to parse. Unknown keys are rejected (deny_unknown_fields), so a typo such as scop is a 422, not a silent default.

Other changes

  • recheck_scope skips this endpoint. It is a read-only POST that the client refetches on every draft edit. Without the skip, each call re-checked every live terminal session in the team. Real permission writes still trigger the re-check.
  • Rule layering is shared with the live authorization path (compose_member_row, preview_for, object_refs in object_authz.rs), so the preview cannot drift from enforcement.

Tests

  • cargo test --bin voltius-server against a test database: 1070 passed.
  • cargo clippy --all-targets -- -D warnings: clean.
  • The new tests cover:
    • layer order and deny-then-allow
    • hidden objects and rule sets
    • deleted objects not keeping the gate alive
    • locked (lapsed Business) teams
    • a key gate held by custom role or object rule only
    • role drafts and their affected holders
    • every gate and status code above

Capability

GET /v1/meta advertises permission_preview: true. A server without the route answers a bare 404, the same as a missing member, so clients read support from meta instead of guessing from a 404.

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.

1 participant