Files
Docwell/Database/pb_migrations/1762600000_share_links.js
T
tajniak81andClaude Opus 5.5 dac6d6da63 Add public share links and the share dialog
Editors can give a page a public link that anyone can read without an
account, optionally with the pages under it. The link is the stored
token, so editors can copy it again later; turning sharing off deletes
it and the URL stops working. Reads through a link never reach trashed
pages, pages outside the shared subtree, or their attachments, and are
marked noindex.

The page header gets a Share button: the dialog explains who can open
the page through its space, lists the space's people and groups, copies
the page link and manages the public link. Shared pages open at
/share/<token> in a read-only view with a tree of the shared subpages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 17:09:07 +01:00

42 lines
1.6 KiB
JavaScript

// SPDX-License-Identifier: AGPL-3.0-or-later
/// <reference path="../pb_data/types.d.ts" />
// Public share links: anyone with the link can read the page (and, if
// include_subpages, the pages under it) without signing in. The token is the
// link itself, so it is stored as is and shown to editors again; deleting the
// record revokes the link.
migrate(
(app) => {
const users = app.findCollectionByNameOrId("users");
const pages = app.findCollectionByNameOrId("pages");
const workspaces = app.findCollectionByNameOrId("workspaces");
app.save(
new Collection({
type: "base",
name: "share_links",
fields: [
{ name: "page", type: "relation", collectionId: pages.id, maxSelect: 1, required: true, cascadeDelete: true },
{ name: "workspace", type: "relation", collectionId: workspaces.id, maxSelect: 1, required: true, cascadeDelete: true },
{ name: "token", type: "text", required: true, min: 24, max: 64 },
{ name: "include_subpages", type: "bool" },
{ name: "created_by", type: "relation", collectionId: users.id, maxSelect: 1, cascadeDelete: false },
{ name: "created", type: "autodate", onCreate: true, onUpdate: false },
{ name: "updated", type: "autodate", onCreate: true, onUpdate: true },
],
indexes: [
"CREATE UNIQUE INDEX idx_share_links_token ON share_links (token)",
"CREATE UNIQUE INDEX idx_share_links_page ON share_links (page)",
],
}),
);
},
(app) => {
try {
app.delete(app.findCollectionByNameOrId("share_links"));
} catch (_) {}
},
);