auth/cell_grant_actions.ts

Cell-grant ACL RPC handlers.

Three request_response actions bound to specs in auth/cell_grant_action_specs.ts:

Grant management is manage-tier only (can_manage_cell = admin / owner). Editor-grant holders may edit a cell's content + relations but cannot manage its grants — delegating the share list would let an editor widen access or mint peer editors and escape the manager's authority.

  • cell_grant_create — admin / owner only. Refuses a cell whose moderation doesn't admit an audience (403 cell_grant_unapproved, after the manage gate). Validates role-shaped principals against the role registry; rejects owner-as-principal. Actor-shaped principals carry a pre-resolved actor_id (callers pick via actor_search). Idempotent — re-granting the same principal updates level via UPSERT. A mounted authorize_grant_create is asked after the spine's own gates, before the owner check and the write (403 cell_grant_not_authorized on refusal).
  • cell_grant_revoke — admin / owner, plus self for actor-shaped grants ("leave shared cell"), plus — when authorize_grant_revoke is mounted — the steward of a scoped role-shaped grant's scope. Returns still_admitted computed by re-running can_view_cell against the remaining grants.
  • cell_grant_list — admin / owner only. Viewers and editors alike get the IDOR-mask 404 (the share list is the manager's to curate).

Every miss and every authority denial is a 404 mask, as in auth/cell_actions.ts: cell_grant_create and cell_grant_list answer cell_not_found for a missing cell and a non-manager alike; cell_grant_revoke answers cell_grant_not_found for a missing grant, a grant whose cell is gone, and a caller with no authority to revoke it.

Audit events cell_grant_create / cell_grant_revoke carry IDs only (no display-name snapshots); see auth/cell_grant_audit_metadata.ts.

view source

Declarations
#

7 declarations

CellGrantActionDeps
#

auth/cell_grant_actions.ts view source

CellGrantActionDeps

type ActionFactoryDeps & { roles: RoleRegistry; authorize_grant_create?: CellGrantCreateAuthorize | undefined; authorize_grant_revoke?: CellGrantRevokeAuthorize | undefined; }

import type {CellGrantActionDeps} from '@fuzdev/fuz_app/auth/cell_grant_actions.js';

Dependencies for create_cell_grant_actions.

roles is the role registry — read for the role-validity gate on cell_grant_create; authorize_grant_create is the optional consumer gate (CellGrantCreateAuthorize) and authorize_grant_revoke the optional steward widening of cell_grant_revoke (CellGrantRevokeAuthorize). The other slots match CellActionDeps so audit-log emit goes through the same fire-and-forget plumbing.

log

Structured logger instance.

type Logger

audit

Bound audit emitter for audit writes.

type AuditEmitter

roles

type RoleRegistry

authorize_grant_create?

type (auth: RequestActorContext, input: CellGrantCreateAuthorizeInput, ctx: ActionContext): boolean | Promise<...>

auth

input

ctx

returns boolean | Promise<boolean>

authorize_grant_revoke?

type (auth: RequestActorContext, input: CellGrantRevokeAuthorizeInput, ctx: ActionContext): boolean | Promise<...>

auth

input

ctx

returns boolean | Promise<boolean>

CellGrantCreateAuthorize
#

auth/cell_grant_actions.ts view source

CellGrantCreateAuthorize import type {CellGrantCreateAuthorize} from '@fuzdev/fuz_app/auth/cell_grant_actions.js';

Opt-in gate on cell_grant_create — the TS twin of the Rust CellGrantCreateAuthorize trait. Asked after the spine's own gates — the manage tier (a non-manager gets the 404 mask and never reaches it), the moderation admission, and the role registry — and before the owner check and the write, for a new grant and a level change alike. false refuses with 403 ERROR_CELL_GRANT_NOT_AUTHORIZED, writing neither the grant nor an audit row. A consumer narrows sharing with it (say, role-shaped grants only to roles of the cell's own space); it can't widen it, as every caller it sees already manages the cell. Omitted = no gate past the spine's.

ctx is the request's: cell_grant_create has side effects, so ctx.db is the request transaction, and a callback needing the database (a scope-existence check, say) reads through it. Read-only — the callback decides, it never writes; a write would commit or roll back with the grant, and nothing enforces this but the callback.

(call)

type (auth: RequestActorContext, input: CellGrantCreateAuthorizeInput, ctx: ActionContext): boolean | Promise<...>

auth

input

ctx

returns boolean | Promise<boolean>

CellGrantCreateAuthorizeInput
#

auth/cell_grant_actions.ts view source

CellGrantCreateAuthorizeInput import type {CellGrantCreateAuthorizeInput} from '@fuzdev/fuz_app/auth/cell_grant_actions.js';

Input to a CellGrantCreateAuthorize callback — the twin of the Rust CellGrantCreateAuthorizeInput.

cell_id

The cell the grant names.

type Branded

cell_created_by

The cell's owner (null = a system cell).

type Branded | null

level

The level the grant confers — on an upsert, the new level.

type "viewer" | "editor"

principal

Who the grant admits: an actor, or a role at an optional scope.

type CellGrantPrincipalQueryInput

CellGrantRevokeAuthorize
#

auth/cell_grant_actions.ts view source

CellGrantRevokeAuthorize import type {CellGrantRevokeAuthorize} from '@fuzdev/fuz_app/auth/cell_grant_actions.js';

Opt-in widening of cell_grant_revoke to a scope's steward — the TS twin of the Rust CellGrantRevokeAuthorize trait.

The role-shaped twin of self-revoke: an actor-shaped grant's grantee may leave a cell, and for a role-shaped grant the grantee is the scope, so the scope's steward speaks for it (say, a teacher removing a cell shared into their classroom). The consumer decides what stewards a scope. The input carries the grant's role so a consumer whose scopes are stewarded only for certain roles can refuse the rest.

Deliberately fenced. The spine asks it only when the caller neither manages the cell nor holds the grant (self-revoke), and only for a role-shaped grant with a non-null scope_id — an actor-shaped grant or a scopeless role grant never reaches it, and a soft-deleted cell 404s first. true revokes as a manager would — same delete, still_admitted, and cell_grant_revoke audit row, its metadata stamped steward: true; false answers the same 404 ERROR_CELL_GRANT_NOT_FOUND mask as every other non-qualifying caller (not a 403 — the caller mustn't learn the grant exists); a throw is a hard error — it is not masked, so refuse with false, never a throw. Omitted = revoke is the manager's and the self-revoker's alone.

The grant it decides on is the grant revoked: the delete matches the grant's level as the callback saw it, so a level change landing between the read and the delete answers the 404 mask rather than revoking a grant the callback never judged. ctx.db is the request transaction (cell_grant_revoke has side effects), read through like CellGrantCreateAuthorize's, and read-only like it.

(call)

type (auth: RequestActorContext, input: CellGrantRevokeAuthorizeInput, ctx: ActionContext): boolean | Promise<...>

auth

input

ctx

returns boolean | Promise<boolean>

CellGrantRevokeAuthorizeInput
#

auth/cell_grant_actions.ts view source

CellGrantRevokeAuthorizeInput import type {CellGrantRevokeAuthorizeInput} from '@fuzdev/fuz_app/auth/cell_grant_actions.js';

Input to a CellGrantRevokeAuthorize callback — the twin of the Rust CellGrantRevokeAuthorizeInput. Only a role-shaped grant with a scope reaches the callback, so role and scope_id are always present.

grant_id

The grant being revoked.

type Branded

cell_id

The cell the grant names.

type Branded

cell_created_by

The cell's owner (null = a system cell).

type Branded | null

role

The role the grant admits.

type string

scope_id

The scope the grant is bound to — the scope whose steward the callback decides on.

type Branded

level

The level the grant confers.

type CellGrantLevel

create_cell_grant_actions
#

to_grant_json
#

auth/cell_grant_actions.ts view source

(row: CellGrantRow): { id: Branded<string, "Uuid">; created_at: string; role: string | null; scope_id: Branded<string, "Uuid"> | null; granted_by: Branded<...> | null; actor_id: Branded<...> | null; cell_id: Branded<...>; level: "viewer" | "editor"; } import {to_grant_json} from '@fuzdev/fuz_app/auth/cell_grant_actions.js';

row

returns

GrantJson

Depends on
#

Imported by
#