Authorization and Object-Level Access Control

A signed-in person may be an editor of one document and a viewer of another. Authorization decides whether this person may perform this action on this specific resource.

On this page

Describe the roles and permitted actions

Start with no access and grant only the operations each role needs. Define who may invite collaborators as well as who may edit content. Check current membership on the server for every request, including downloads and background exports.

Role      Read    Edit    Invite
Owner     Yes     Yes     Yes
Editor    Yes     Yes     No
Viewer    Yes     No      No
Guest     No      No      No

Enforce the rule when writing the row

Suppose each document has a tenant and a membership row for every collaborator, including its owner. Scope the write to both tenant and current membership. Bind user and tenant identifiers from verified server context. Only report success when a row was updated. Hiding the Edit button helps the interface, while this check protects the data.

UPDATE documents AS d SET title = $1
WHERE d.id = $2 AND d.tenant_id = $3
  AND EXISTS (
    SELECT 1 FROM document_members AS m
    WHERE m.document_id = d.id AND m.user_id = $4
      AND m.role IN ('owner', 'editor')
  )
RETURNING d.id;

Official references