I want to make it so when I invite someone to a workspace they can only see threads from that workspace, the threads across every workspace
I want to make it so when I invite someone to a workspace they can only see…
Today any signed-in user can read every workspace, thread and memory note (membership only gates writes). You want invitees scoped to the workspaces they were invited to.
Rule I'm implementing: a signed-in user can see a workspace (its threads, posts, members, memory, SSE stream) only when they are a member of it, or the owner has marked it open (open already means "anyone signed in can post here", so hiding it would make the switch meaningless). Everything else 404s, same as the existing member-only routes. Unchanged: threads flagged public stay readable by anyone with the link, and legacy threads with no workspace stay readable by anyone signed in.
Where it lands:
lib/session.ts: newrequireViewer/requireThreadReader;requireThreadReadable(SSE) uses them.lib/data.ts:listWorkspaces/listWorkspaceNamesreturn only visible workspaces (member or open), so the header dropdown,/,/workspacesand/<slug>shrink automatically;listThreadsgets avisibleTofilter for the unscoped API call.- Pages:
/<slug>,/workspaces/[id],/threads/[id]404 for non-members of private workspaces; the "you can read this but can't post" copy goes away since it can no longer happen. - APIs:
GET /api/threads,GET …/[id]/posts,GET …/[id]/prs,GET /api/workspaces/[id]/members,GET /api/threads/[id]/events. - README / architecture.md access-model text.
Code is in and committed locally (e9288d7, not pushed yet). Type-check passes. What changed, for anyone reading later:
lib/session.ts:canSeeWorkspace(ws, member)= member || ws.open is the one rule.requireViewer(workspaceId, user)(404 otherwise) andrequireThreadReader(threadId, user)(public threads and legacy workspace-less threads pass; everything else needs the workspace to be visible).requireThreadReadable(SSE) reuses it when signed in.requireThreadExistsis now documented as existence-only.lib/data.ts:listWorkspaces(userId)/listWorkspaceNames(userId)add awhere open OR exists(member row)so the header dropdown,/,/workspacesand/<slug>only show visible workspaces.listThreads({ visibleTo })for the unscopedGET /api/threads.- Pages/APIs gated as planned; dead "you can read this but can't post" copy removed from
/<slug>,/workspaces/[id]and the thread page (reading now implies posting rights, except a public thread in a private workspace, which keeps a "replying is for members" note).
Now spinning up a Postgres in the sandbox to run the new queries against real rows (3 users, private/open/other workspaces, 5 threads) rather than trusting toSQL() output alone.
threadide@e9288d7Done and pushed on thread/2cd58ad1 (threadide e9288d7).
What an invitee now sees: only the workspaces they belong to, plus any a owner has marked open. The header dropdown, /, /workspaces and /<slug> list only those; a private workspace they aren't in, and every thread in it, is a 404 (page, GET …/posts, GET …/prs, SSE stream, members list), the same answer the member-only routes already give. Unchanged: threads flagged public stay readable by anyone with the link, and the handful of legacy threads with no workspace stay readable by anyone signed in.
Where the rule lives: lib/session.ts canSeeWorkspace(ws, member) = member || open, with requireViewer / requireThreadReader on top; lib/data.ts applies the same thing in SQL so the lists can't leak. Details in the PR description and my progress post above.
Verified: tsc clean, and the gates + queries run against a real Postgres in the sandbox with 3 users, a private / open / other workspace and 5 threads: 19 assertions pass (owner sees 3 workspaces, invitee 2, outsider only the open one; outsider is 404'd on the private thread but can read the public one inside that workspace). Couldn't click through the pages themselves (the app needs GitHub OAuth), but their changes are one notFound() line each plus copy.
Two things to know:
- Anyone who used to browse other people's workspaces as a "viewer" loses that; there is no read-only role, by design. If you want one later, it's a second branch in
canSeeWorkspace. - The anonymous sign-in gate and link previews still show a workspace's name and counts to whoever has the URL (that was always the public-safe preview layer, no thread content). Say the word if you'd rather private workspaces 404 there too.
No migration or config needed.
I do want anyone to be able to view a forum though and they should have to sign in to post
Got it: that splits the request into two different things, and the first commit on this branch (e9288d7) conflated them.
- Navigation stays scoped: the header dropdown,
/,/workspacesonly list the workspaces you belong to (plus any marked open). An invitee doesn't get a tour of everyone else's forums. That part of e9288d7 stays. - Reading by URL goes the other way: anyone, signed in or not, can open
/<slug>and any/threads/[id]and read it. No more 404 for non-members, and no more sign-in gate for visitors. The/workspaces/[id]manage page (invite link, repos, memory notes) stays for members only. - Posting needs a session, as it already does: members, or anyone signed in when the workspace is open. Asking Claude stays members-only. The per-thread "anyone can reply" opt-in you built earlier (guest replies without an account) stays as is; it's off by default.
Consequence I'll handle: with every thread readable, the per-thread public flag no longer means anything for reading, so it stops mattering as a read gate; I'll only keep it as the prerequisite for "anyone can reply" and adjust the Manage menu copy so it doesn't promise a visibility it no longer controls.
If you meant "anyone signed in" rather than "anyone at all", say so; that's a one-line change in the same gate.
Code is in; tsc is clean and a next build is running. What changed on top of e9288d7, for anyone reading later:
lib/session.ts: the read gates from the first round (canSeeWorkspace,requireViewer,requireThreadReader,requireThreadReadable) are gone.requireThreadExistsis now the whole read gate.requireWriter(member, or anyone signed in when open) doubles as the gate for workspace-internal reads: the/workspaces/[id]manage page andGET …/members.lib/data.ts: the workspace filter is renamedlistedFor(navigation only: member or open).listThreadslost itsvisibleTofilter. NewgetWorkspaceBySlugso/<slug>can render for anyone.setThreadVisibilitybecamesetGuestReplies(id, bool).- Pages:
/<slug>and/threads/[id]render for everyone, no sign-in gate, no 404 for outsiders. Readers who can't post get one line in place of the composer ("Sign in to start a thread", "Replying is for members of X"). On/<slug>the title is the workspace name when it isn't in your dropdown (visitor, or non-member of a private one), "Threads" otherwise; the header dropdown shows the slug as a placeholder instead of pretending you're in another workspace. - APIs:
GET /api/threads,GET …/posts, the SSE stream need no session;GET …/prsstill does (it reads GitHub with your token). publicflag retired: with everything readable the per-thread "Make public" switch meant nothing, so the Manage menu now only has "Let anyone reply" and "Delete thread".PATCH /api/threads/[id]takes{ anyoneCanReply }only. Thethreads.publiccolumn stays (nothing reads it; no migration).- README / architecture.md / schema comments say the new rule.
threadide@df41415Done and pushed on thread/2cd58ad1 (threadide df41415, on top of e9288d7).
What it does now
- Anyone can view a forum. Every
/<slug>and every thread page renders for anyone with the URL, signed in or not: posts, diffs, live updates. No sign-in gate, no 404 for outsiders. - Sign in to post. Replying and starting threads need a session plus the existing rules (members, or anyone signed in when the workspace is open; asking Claude stays members-only). Readers who can't post see one line in place of the composer ("Sign in to reply", "Replying is for members of X. Ask one of them for the invite link").
- Your navigation is still yours. The header dropdown,
/and/workspaceslist only the workspaces you belong to (plus open ones). An invitee sees their workspace, not everyone else's. If they open another forum by link, the page is titled with that workspace's name and the dropdown shows its slug as a placeholder. - "Make public" is gone from the thread Manage menu: with everything readable it meant nothing. "Let anyone reply" (guest replies without an account, the opt-in you built earlier) and "Delete thread" remain. The
threads.publiccolumn is kept but unused; no migration.
Verified: tsc clean and next build succeeds. Couldn't click through (the app needs Postgres + GitHub OAuth), and this round is mostly deletions of gates, so I skipped the sandbox Postgres rig from the first round.
Two things to know
- The
/workspaces/[id]manage page (invite link, repos, memory notes) is deliberately not open: members, or anyone signed in when the workspace is open. Say so if you want it readable too. - If you ever want a truly private workspace again, the right place is a workspace-level flag (one check next to
requireThreadExists), not a return to the per-thread public switch.
PR description is written; the PR opens when this run ends.
Merged threadide #124 by @osebo (merge, 5977cae).