Repository navigation
Open
Description
Parent
What to build
Enable signed-in users to request access from locked Invite only gates (PrivateDocumentGate) and request edit/comment access from public or read-only documents, notifying managers (Owner + Full access) with single-step review and a 7-day decline cooldown.
1. Prisma Schema & Notification Gating (apps/hocuspocus.server, packages/supabase)
- Add
DocumentAccessRequestmodel (onDelete: CascadetoDocumentMetadata.documentId):id String @id @default(uuid()),documentId String,requesterUserId String,requestedRole DocumentRole(DB CHECK"requestedRole" <> 'full'),message String?,status AccessRequestStatus @default(pending),resolvedBy String?,resolvedAt DateTime?,cooldownUntil DateTime?,createdAt DateTime @default(now()),updatedAt @updatedAt.- Partial unique index:
UNIQUE ("documentId", "requesterUserId") WHERE "status" = 'pending'.
- Notifications without double-mailing (
packages/supabase&hocuspocus-worker):- When a request is created (or approved), insert bell notifications for
Owner+ all activeFull accessmanagers (channel_id = NULLsafe when a document has nochannelsrow yet) AND enqueue/send transactional email viahocuspocus-worker. - Explicitly gate the notification category/type inside both
enqueue_push_notification()(07-4) andqueue_email_notification()(07-5) in both scripts and migration so direct worker emails do not trigger a second email from the DB notification trigger.
- When a request is created (or approved), insert bell notifications for
2. Backend Endpoints (src/modules/document-sharing/, OpenAPI covered)
(Because locked users never learn documentId on Invite only 403 responses, request creation MUST accept slug and resolve it server-side.)
POST /api/documents/access-requests(mounted BEFORE/:documentId/*):- Signed-in verified user (
401if anon/unauth); fail-closed rate limit (10/hr/user). - Accepts
{ slug, requestedRole, message? }(requestedRole ∈ {edit, comment, view}; neverfull). ResolvesslugagainstDocumentMetadata.slug(and alias table once#619lands). - Returns
404for trashed/nonexistent/Open docs (ownerId === null); idempotent200if pending request already exists;409if caller already holds>= requestedRole;429 COOLDOWN_ACTIVE(withretryAftertimestamp) if declined within the last7 days.
- Signed-in verified user (
GET /api/documents/:documentId/people&GET /api/documents/:docName:GET /peopleincludes pending requests (id,name,email,initials,requestedRole,message,createdAt) ONLY forOwner | Full access.- Authenticated
403privateGateResponsereturns caller-scoped{ hasPendingRequest, cooldownUntil }(still zero title/owner/documentIdleak).
POST /api/documents/:documentId/access-requests/:requestId/approve&.../decline:- Owner or
Full access.approveaccepts{ role }(defaults torequestedRole, editable up tofull), writesDocumentGrant+ Supabasedocument_access_grantsmirror atomically, updates request toapproved, and notifies requester. declinesetsstatus = 'declined',cooldownUntil = now() + 7 days. If another manager already resolved the request, return a clean conflict ("Already handled") so the UI refreshes rather than failing generically.
- Owner or
3. Webapp Gate, Header & Manager Review UI (apps/webapp)
PrivateDocumentGate(Invite onlylocked page):- Signed-out: "This document is Invite only. Sign in to open it or request access." (zero title, owner, or member count leak).
- Signed-in: "You don't have access to this document" + inline Request access form (role selector excluding
Full access, optional personal message,Request accessCTA) transitioning cleanly to"Request sent", or displaying the 7-day decline cooldown notice.
- In-document single CTA (no duplication):
- Pad header (desktop
DocumentAccessChip/ mobile 40px status substrip): show a singleRequest edit access(edit) button for signed-inCan comment/Can viewusers — do NOT duplicate this button in the desktop Share footer. Can viewlocked chat bar (ChannelInfoSurfacewhenCan view): offer quiet"Ask to comment"submittingrequestedRole: 'comment'.
- Pad header (desktop
- Manager review in Share:
- 1 pending request: inline banner showing requester avatar, name, email, optional note, editable role dropdown (
Full access..Can view),Approve(non-primary /variant="cancel"soCopy link/Copy invite linkkeeps solebtn-primaryper P4), andDecline. - 2+ pending requests: compact summary banner (
"{N} people requested access · Review →") opening theAccess requestsdrill-in view on desktop or the inline-pill request banners inside mobilePeople with access.
- 1 pending request: inline banner showing requester avatar, name, email, optional note, editable role dropdown (
- Update
CONTEXT.mdAccess requestglossary entry (_Avoid_: "join request", "ask-in").
Maintainer rulings, 2026-11-23
- Request submission takes
{ slug }(neverdocumentId, preventing ID leakage on locked docs). - Limit 1 pending request per user per document, and a 7-day cooldown after decline.
- Single
Request edit accessCTA lives in the pad header / mobile substrip (no Share footer duplicate);"Ask to comment"inCan viewchat bar requestscomment. - Managers can change the role right before pressing
Approve.
Acceptance criteria
-
POST /api/documents/access-requestsresolves byslugwithout revealingdocumentId, enforcesrequestedRole <> 'full', prevents duplicate pending requests, and returns429during the 7-day post-decline cooldown. - Authenticated locked gate (
PrivateDocumentGate) submits access requests and survives reload (hasPendingRequest/cooldownUntilin 403 gate response without leaking title/owner). - Approving with an edited role grants immediate access, notifies the requester without double-mailing, and clears the banner across manager clients; concurrent double-approval returns
"Already handled". - In-pad
Can view/Can commentnon-owners see a single headerRequest edit accessCTA (desktop/mobile) andCan viewchat"Ask to comment", with zero duplicate request buttons in Share footer. -
check-grants.sqlstays 0 rows and server integration tests verify cooldown, slug resolution, and no double-email delivery.
Blocked by
- Add four-tier document roles, orthogonal grants, and live access enforcement #826 — Base
document-sharingmodule, grants, and mirror helpers. - Build desktop Share popover, mobile Share sheet, and General access switch dialogs #827 —
SharePopover, mobile'share'BottomSheet,MobilePadTitlestatus substrip, and"Invite only"PrivateDocumentGate.
Agent brief
Type: AFK
Where to start (read from code, not measured, as of 2026-11-23):
- Supabase:
packages/supabase/scripts/{07-4-push-notifications-pgmq.sql,07-5-email-notifications-pgmq.sql,10-functions.sql} - Server:
apps/hocuspocus.server/src/api/controllers/documents.controller.ts(privateGateResponse),src/modules/document-sharing/,src/lib/email/ - Webapp:
apps/webapp/src/components/pages/document/components/PrivateDocumentGate.tsx,DocumentAccessChip.tsx,MobilePadTitle.tsx,SharePopover/ShareSheet,ChannelInfoSurface.tsx.
Deploy order: Supabase SQL → hocuspocus-worker → rest-api → webapp
Verify: Server integration tests + supabase_back check/test + webapp typecheck/lint/build + manual test of locked gate request, cooldown rejection, and 1-request vs 2+ request review.
Out of scope
- Direct email invites (
dpe_) and/invitemismatch flow (Add direct email invites with pending rows and flexible-claim join #833). - Ownership transfer requests (
dpt_) (Add accept-required ownership transfer, expiring grant reaper, and Open document copy #834).
Activity