Add page-level permissions and guests
Pages can now be shared with people and groups beyond their space, and restricted so that only those grants count. A grant covers the page and everything under it. Space admins always keep access, and an editor who restricts a page keeps editor through a grant of their own. Sharing a page with someone from the organization who is outside the workspace adds them as a guest. Anyone else gets a guest invite that carries the page grant, which is made when they accept. Guests see a "limited" space holding only the pages shared with them. The page tree, breadcrumbs, search, favorites, recents, trash and import all follow the page role. Public links skip restricted subtrees. Grants are cleaned up when a member leaves or a group is deleted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8aeebbff12
commit
7968e82cc2
29 files changed
+2277
-119
No files matched your search
@@ -0,0 +1,56 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
/// <reference path="../pb_data/types.d.ts" />
|
||||
|
||||
// Page-level permissions. A grant gives a user or group a role on a page and
|
||||
// its subtree (on top of their space role); pages.restricted makes a subtree
|
||||
// ignore the space role, so only its own grants count (see
|
||||
// Server/internal/access/pages.go). space is copied from the page so one
|
||||
// query finds a caller's grants in a space. Invites can carry a page grant:
|
||||
// sharing a page with someone outside the workspace invites them as a guest.
|
||||
|
||||
migrate(
|
||||
(app) => {
|
||||
const pages = app.findCollectionByNameOrId("pages");
|
||||
const spaces = app.findCollectionByNameOrId("spaces");
|
||||
pages.fields.add(new BoolField({ name: "restricted" }));
|
||||
app.save(pages);
|
||||
|
||||
app.save(
|
||||
new Collection({
|
||||
type: "base",
|
||||
name: "page_permissions",
|
||||
fields: [
|
||||
{ name: "page", type: "relation", collectionId: pages.id, maxSelect: 1, required: true, cascadeDelete: true },
|
||||
{ name: "space", type: "relation", collectionId: spaces.id, maxSelect: 1, required: true, cascadeDelete: true },
|
||||
{ name: "principal_type", type: "select", values: ["user", "group"], maxSelect: 1, required: true },
|
||||
{ name: "principal_id", type: "text", required: true },
|
||||
{ name: "role", type: "select", values: ["editor", "commenter", "viewer"], maxSelect: 1, required: true },
|
||||
{ name: "created", type: "autodate", onCreate: true, onUpdate: false },
|
||||
{ name: "updated", type: "autodate", onCreate: true, onUpdate: true },
|
||||
],
|
||||
indexes: [
|
||||
"CREATE UNIQUE INDEX idx_pp_unique ON page_permissions (page, principal_type, principal_id)",
|
||||
"CREATE INDEX idx_pp_space ON page_permissions (space, principal_type, principal_id)",
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
const invites = app.findCollectionByNameOrId("invites");
|
||||
invites.fields.add(new RelationField({ name: "page", collectionId: pages.id, maxSelect: 1, cascadeDelete: true }));
|
||||
invites.fields.add(new SelectField({ name: "page_role", values: ["editor", "commenter", "viewer"], maxSelect: 1 }));
|
||||
app.save(invites);
|
||||
},
|
||||
(app) => {
|
||||
const invites = app.findCollectionByNameOrId("invites");
|
||||
invites.fields.removeByName("page_role");
|
||||
invites.fields.removeByName("page");
|
||||
app.save(invites);
|
||||
try {
|
||||
app.delete(app.findCollectionByNameOrId("page_permissions"));
|
||||
} catch (_) {}
|
||||
const pages = app.findCollectionByNameOrId("pages");
|
||||
pages.fields.removeByName("restricted");
|
||||
app.save(pages);
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user