Skip to content

feat(org-fs): public file sharing via read_public flag - #4125

Merged
viktormarinho merged 5 commits into
mainfrom
viktormarinho/file-public-share
Jun 24, 2026
Merged

viktormarinho merged 5 commits into
mainfrom
viktormarinho/file-public-share

Conversation

@viktormarinho

@viktormarinho viktormarinho commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

What is this contribution about?

Adds a per-file read_public flag to the org filesystem so a member can share a single file with the open internet over the same /api/:org/fs/:volume/read proxy URL the org already uses. The Library file preview gains a Share popover — copy link plus a public ↔ org-only switch. When a file is public the read route streams it with no auth or membership, and the org-membership middleware defers that one route to it so the link works for everyone (anonymous viewers, external embeds, signed-in non-members); publishing is gated on ORG_FS_WRITE and private files behave exactly as before.

Screenshots/Demonstration

UI change — a Share button in the Library file preview toolbar (regular files, fullscreen dialog, and HTML/deck preview). Loom/screenshots can be added on request.

How to Test

  1. Open a file in the Library preview and click Share.
  2. Toggle Make public on, copy the link, and open it in an incognito window (or curl) — it loads with no login.
  3. Toggle it off — the same link now returns 403 for non-members. (Flipping the switch requires ORG_FS_WRITE.)

Migration Notes

Adds migration 115-org-fs-read-public — a read_public boolean NOT NULL DEFAULT false column on org_fs_entry, registered in migrations/index.ts. Applies automatically on boot / bun run migrate; no config changes.

Review Checklist

  • PR title is clear and descriptive
  • Changes are tested and working (typecheck + lint + migration-manifest check pass; runtime/e2e not yet exercised)
  • Documentation is updated (if needed)
  • No breaking changes

Summary by cubic

Add public sharing for files and folders via a per-entry read_public flag with inherited visibility from parent folders. The Library gains Share controls, and the read route serves public files without auth; private behavior is unchanged.

  • New Features

    • Share UI in Library previews and cards: copy link and toggle public ↔ org-only on files and folders; new Share dialog; globe badge shows own vs inherited public. Read-only public-* volumes are excluded.
    • Public reads at /api/:org/fs/:volume/read?path=...: streams to anyone when public (own or inherited). Org-membership middleware defers only this route; ?presign stays member-only. HTML gets a sandbox CSP; Cache-Control is public+revalidate for shared files and private otherwise.
    • API/data: POST /:volume/public?path=... with { public: boolean } toggles files and dirs (folders publish their subtree). /stat, /list, and /recent include effectivePublic (own OR inherited) with batched queries. Optimistic toggle updates both readPublic and effectivePublic, then invalidates listing/recent; visibility changes don’t bump seq. In-place overwrites preserve the flag; delete+recreate resets it to private (files and folders).
  • Migration

    • Adds read_public boolean NOT NULL DEFAULT false to org_fs_entry (120-org-fs-read-public), applied via the existing migration flow.

Written for commit 0997ba5. Summary will update on new commits.

Review in cubic

viktormarinho and others added 5 commits June 24, 2026 12:13
Add a per-file `read_public` flag to the org filesystem so a member can
share a single file with the open internet over the same `/fs/:volume/read`
proxy URL the org already uses. The Library file preview gains a Share
popover (copy link + a public/org-only switch). When a file is public, the
read route streams it with no auth or membership, and the org-membership
middleware defers that one route to it so the link works for everyone —
anonymous viewers, external embeds, and signed-in non-members alike.
Publishing is gated on ORG_FS_WRITE; private files are unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Resolve conflicts from main's Library preview refactor + new migrations:
- Renumber the read_public migration 115 -> 120 (main took 115-119); register
  it after main's entries in migrations/index.ts.
- Re-apply the FileShareButton into the new shared preview-content.tsx
  (LibraryFilePreview), where main consolidated the panel/dialog toolbars;
  take main's versions of preview-panel.tsx and preview-dialog.tsx.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Extend public sharing to folders: read_public is now settable on dir
entries, and the read route serves a file publicly when its own flag is
set OR a published ancestor folder covers it (isPubliclyReadable +
hasPublicAncestorDir). Publishing a folder thus publishes its whole
subtree — current and future contents — with no byte moves and no seq bump.

UI: a shared ShareControls body (live-state visibility switch + copy link)
reused by the preview-toolbar FileShareButton popover and a new ShareDialog
opened from Library cards. Cards (file, folder, skill, recent) gain a Share
menu item and a "public" globe badge; read-only public-set volumes are
excluded. useOrgFsSetPublic invalidates the listing + recent feed so badges
refresh.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…brary

Return effectivePublic (own flag OR a published ancestor folder) from
/stat, /list and /recent so the UI can reflect inherited visibility:
- stat: one ancestor query; list: one query for the whole listing;
  recent: batched one query per volume (OrgFs.inheritsPublic /
  childrenInheritPublic / recentWithEffectivePublic + storage.publicDirPaths).

Library cards now show a globe badge for any effective-public entry, in two
tiers — solid (published here) vs muted (inherited from a parent folder).
The share dialog reflects effective state, and when public-via-parent it
shows an explanatory note and locks the switch (manage it on the folder).

Also fix the share dialog URL row overflowing the rounded edge: the grid
DialogContent left its item at min-width:auto, so ShareControls needed
min-w-0 for the long URL to truncate.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…, docs

- Delete + recreate now resets read_public to false for files AND folders
  (was fails-open: a regenerated deck at a stable path silently re-published).
  putFile/putDir use a CASE so reviving a tombstone clears the flag while an
  in-place overwrite preserves it. Note: putDir's `.where(deleted_at is not
  null)` is an ON CONFLICT index-predicate, not an update guard, so the SET
  fires for live dirs too — the CASE is what gates the reset, and a naive
  `read_public=false` would have unpublished a folder on every child write.
- Optimistic share toggle flips effectivePublic alongside readPublic, so
  unpublish no longer transiently reads as inherited-public.
- Refresh stale migration/types comments (the flag is meaningful on dirs;
  folder publish inherits across the subtree).
- Add 5 regression tests: publish/revert, overwrite preserves, file & folder
  delete+recreate reset to private, folder inheritance incl. later writes.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@viktormarinho
viktormarinho enabled auto-merge (squash) June 24, 2026 20:01
@viktormarinho
viktormarinho merged commit 51f0e19 into main Jun 24, 2026
15 checks passed
@viktormarinho
viktormarinho deleted the viktormarinho/file-public-share branch June 24, 2026 20:04
decocms Bot pushed a commit that referenced this pull request Jun 24, 2026
PR: #4125 feat(org-fs): public file sharing via read_public flag
Bump type: minor

- decocms (apps/mesh/package.json): 3.54.1 -> 3.55.0

Deploy-Scope: both
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant