RAIA™ Specification

3.33 Organisation Document Privileges — Per-Role Override Matrix

DOCUMENT PRIVILEGES MODEL 1. Role Def Org roles defined Read/Write/Admin 2. Scope Document types Per-category rules 3. Inherit Org→Team→User Hierarchical cascade 4. Enforce API gate + RLS Row-level security DOCUMENT PRIVILEGES MODEL — sequential pipeline through all phases. Per-organisation, per-role overrides on top of each document type’s default scope — for directors and administrators only.

← Back to Developer Hub TEXTBOOK SPECIFICATION
DOCUMENT PRIVILEGES MODEL 1. Role Def Org roles defined Read/Write/Admin 2. Scope Document types Per-category rules 3. Inherit Org→Team→User Hierarchical cascade 4. Enforce API gate + RLS Row-level security DOCUMENT PRIVILEGES MODEL — sequential pipeline through all phases.

Per-organisation, per-role overrides on top of each document type’s default scope — for directors and administrators only.

Settings RBAC Documents Shipped 4785e826
4
Roles in the matrix — administrator, director, manager, staff
5
Permission levels — shared, internal, landlord_only, tenant_only, staff_only
2
Org editors only — administrator and director can open or PATCH
1
Override table — tbl_organisation_document_permissions (null = use default)

Section A In Plain English

In Plain English

Every document type in Paperclip (gas safety, EPC, ID, rent statements, title deeds…) has a default audience: who is allowed to see it. That default is the same for every agency. Sometimes your firm needs a tighter or looser rule — e.g. “managers should not open landlord-only title packs” or “staff can view inspection reports.” Document Privileges is the settings screen where the company director or administrator paints those exceptions on a grid. Leave a cell on Default and the global rule wins. Pick a specific level and that override is stored for your organisation only.

Filing cabinet locks, not file contents

Think of document types as labelled drawers. The privileges screen does not rewrite files — it changes which staff keys open which drawers for your agency. Other organisations keep their own lock chart.

Who can change them?

RoleCan open the screen?Can save overrides?
DirectorYesYes
AdministratorYesYes
ManagerNo (403 / restricted banner)No
StaffNoNo

Section B User Guide — How to Use It

Open the Privileges Screen

  1. 1
    Sign in as director or administrator

    Use your staff account on the portal (app.estateaigents.com). Manager and staff roles are blocked server-side.

  2. 2
    Go to Organisation settings

    Navigate to Settings → Organisation (/settings/organisation). Open the Document Permissions tab, or go directly to /settings/organisation/privileges.

  3. 3
    Review the matrix by section

    Document types are grouped: Compliance & Safety, Financial & Billing, Tenancy, Licensing, Insurance, Title & Ownership, Personal / ID, Property Info, Services, Appliances, Other.

  4. 4
    Change only what you need, then Save

    The blue bar counts unsaved overrides. Click Save Changes. A green toast confirms. Leaving cells on Default keeps platform defaults.

Reading the Permission Matrix

Each row is one document type. Columns:

ColumnMeaning
Document TypeHuman label plus machine key (e.g. gas_safety)
ScopeThe catalogue default from tbl_document_types.default_scope
Admin / Director / Manager / StaffOverride dropdown per role. Empty = Default (no override row stored)
Default is intentional

Grey “Default” cells mean “use the document type’s built-in scope.” That is usually correct. Only override when your firm’s policy differs from the platform default.

Permission Levels

LevelWho it is forChip colour (UI)
sharedVisible broadly (typical compliance packs)Green
internalAgency / internal staffBlue
landlord_onlyProperty owner sideAmber
tenant_onlyTenant side (IDs, R2R)Purple
staff_onlyOperational staff onlyGray
Default (empty)No org override — catalogue default winsDashed gray

Save and Revert Overrides

  • Save sends only dirty cells as a PATCH batch.
  • To revert a cell to default: set the dropdown back to Default and save. The API deletes that override row.
  • Changes apply organisation-wide immediately after a successful save (no per-branch copy).

Troubleshooting

SymptomLikely causeWhat to do
Amber “Restricted area” bannerYour staff role is not director/administratorAsk a director/admin to make the change
“Authentication required”Session expiredSign in again
“No organisation linked to your profile”Staff row missing organisation_idFix staff identity linkage in Supabase / admin tools
Empty matrix / “No document types”tbl_document_types has no active rowsCheck catalogue seed / is_active
Save fails with invalid permissionClient sent a value outside the five levelsHard refresh; report if reproducible

Section C Developer Guide

What shipped

Commit 4785e826 — feat(settings): organisation document privileges screen — DB migration, API route, UI matrix. Portal paths under 03_technology/11_frontend/portal/.

flowchart LR
  subgraph UI["Portal UI"]
    P["/settings/organisation/privileges"]
    O["/settings/organisation"]
  end
  subgraph API["Next.js route"]
    G["GET document-permissions"]
    K["PATCH document-permissions"]
  end
  subgraph DB["Supabase"]
    DT["tbl_document_types"]
    OV["tbl_organisation_document_permissions"]
    ST["staff identity / role"]
  end
  O -->|tab| P
  P --> G
  P --> K
  G --> DT
  G --> OV
  K --> OV
  G --> ST
  K --> ST
  

Data Model

tbl_organisation_document_permissions

Org-scoped overrides. Absence of a row = default. Unique key: (organisation_id, document_type, role).

ColumnRole
organisation_idTenant scope for the override
document_typeFK-style key into tbl_document_types.document_type
roleOne of administrator | director | manager | staff
permissionOne of shared | internal | landlord_only | tenant_only | staff_only

Catalogue defaults live on tbl_document_types (document_type, label, default_scope, scope_is_fixed, ui_section, is_active). GET only returns is_active = true, ordered by ui_section, label.

API Contract

Route file: src/app/api/settings/organisation/document-permissions/route.ts

Auth gate: resolveOrgEditor — Supabase session user → resolveStaffIdentity → role ∈ {administrator, director} and non-null organisationId.

GET /api/settings/organisation/document-permissions

Returns merged view for the caller’s organisation:

{
  "document_types": [
    {
      "document_type": "gas_safety",
      "label": "Gas Safety Certificate",
      "default_scope": "shared",
      "scope_is_fixed": false,
      "ui_section": "compliance",
      "roles": [
        { "role": "administrator", "effective_permission": null },
        { "role": "director", "effective_permission": null },
        { "role": "manager", "effective_permission": "internal" },
        { "role": "staff", "effective_permission": null }
      ]
    }
  ]
}

effective_permission: null means no override (UI shows Default). Non-null is the stored override — not necessarily equal to default_scope.

PATCH /api/settings/organisation/document-permissions

{
  "overrides": [
    { "document_type": "gas_safety", "role": "manager", "permission": "internal" },
    { "document_type": "title_deed", "role": "staff", "permission": null }
  ]
}
  • permission non-null → upsert on conflict organisation_id,document_type,role
  • permission null → delete that override row (revert to default)
  • Validation: role ∈ VALID_ROLES; permission ∈ VALID_PERMISSIONS or null
  • Response: same shape as GET (re-fetch after write)

UI Paths & Components

PathFile
/settings/organisation/privilegessrc/app/settings/organisation/privileges/page.tsx
/settings/organisation (tab link)src/app/settings/organisation/page.tsx
Permission chips / labelssrc/components/documents/PermissionChip.tsx

UI keeps a local dirty map keyed ${document_type}::${role}. Save flattens dirty entries into the PATCH body. Section order is hard-coded in the page (SECTION_ORDER / SECTION_LABELS).

AuthZ Rules

Server-enforced — never trust the client alone

ORG_EDITOR_ROLES = administrator | director. Non-editors get HTTP 403 on both GET and PATCH. Unauthenticated → 401. Missing org on staff → 404. The restricted-area UI is a convenience; the API is the real gate.

Pitfalls

Known edges
  • Default derivation vs override: PermissionChip also has helper sets that map document types → suggested levels for display elsewhere. The privileges screen does not re-derive those on save — it only reads/writes overrides + catalogue defaults.
  • scope_is_fixed: returned on GET but the matrix still renders dropdowns for all roles; if product later locks fixed scopes, gate the cell in UI using this flag.
  • Effective permission semantics: GET’s effective_permission is the override value only (or null), not “override ?? default_scope”. Consumers that need the final resolved level must coalesce themselves.
  • Batch deletes: PATCH deletes run sequentially per null entry; large “reset all” payloads are many round-trips inside one request.

References & External Sources

SourceWhat it coversLink
Feature commit UI matrix, API route, PermissionChip touch — ship SHA 4785e826 on main
API route GET/PATCH contract and org-editor gate 03_technology/11_frontend/portal/src/app/api/settings/organisation/document-permissions/route.ts
Privileges page Client matrix, dirty map, section grouping 03_technology/11_frontend/portal/src/app/settings/organisation/privileges/page.tsx
PermissionChip Level labels/colours and type-level derivation helpers 03_technology/11_frontend/portal/src/components/documents/PermissionChip.tsx
Person / contact media Related portal media access patterns (signed URLs) 3.32 Contact Avatar Pipeline
Security architecture Broader trust and access posture Security Architecture Guide
PRIVILEGE ENFORCEMENT ARCHITECTURE Layer 1 Role Table tbl_org_roles Role → Permissions Mapping rules Layer 2 Policy Engine RLS policies Scope resolver Type + org context Layer 3 UI Gate Frontend permission API Middleware Backend enforcement Privileges cascade: org → team → user with type-scoped rules