Workspace admins create groups of members, and space admins grant a role to a whole group. A member's space role is now the highest of their own grant and their groups' grants. Leaving a workspace drops its group memberships, and deleting a group removes its space grants (they are not a real relation, so PocketBase cannot cascade them). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
1.9 KiB
JavaScript
52 lines
1.9 KiB
JavaScript
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
/// <reference path="../pb_data/types.d.ts" />
|
|
|
|
// Groups of workspace members. A space can grant a role to a group
|
|
// (space_members.principal_type = "group"); members get the highest of their
|
|
// own and their groups' roles.
|
|
|
|
migrate(
|
|
(app) => {
|
|
const users = app.findCollectionByNameOrId("users");
|
|
const workspaces = app.findCollectionByNameOrId("workspaces");
|
|
|
|
const groups = new Collection({
|
|
type: "base",
|
|
name: "groups",
|
|
fields: [
|
|
{ name: "workspace", type: "relation", collectionId: workspaces.id, maxSelect: 1, required: true, cascadeDelete: true },
|
|
{ name: "name", type: "text", required: true, max: 120 },
|
|
{ name: "description", type: "text", max: 500 },
|
|
{ name: "created", type: "autodate", onCreate: true, onUpdate: false },
|
|
{ name: "updated", type: "autodate", onCreate: true, onUpdate: true },
|
|
],
|
|
indexes: ["CREATE UNIQUE INDEX idx_groups_name ON groups (workspace, name COLLATE NOCASE)"],
|
|
});
|
|
app.save(groups);
|
|
|
|
const members = new Collection({
|
|
type: "base",
|
|
name: "group_members",
|
|
fields: [
|
|
{ name: "group", type: "relation", collectionId: groups.id, maxSelect: 1, required: true, cascadeDelete: true },
|
|
{ name: "user", type: "relation", collectionId: users.id, maxSelect: 1, required: true, cascadeDelete: true },
|
|
{ name: "created", type: "autodate", onCreate: true, onUpdate: false },
|
|
{ name: "updated", type: "autodate", onCreate: true, onUpdate: true },
|
|
],
|
|
indexes: [
|
|
"CREATE UNIQUE INDEX idx_group_members_unique ON group_members (`group`, user)",
|
|
"CREATE INDEX idx_group_members_user ON group_members (user)",
|
|
],
|
|
});
|
|
app.save(members);
|
|
},
|
|
(app) => {
|
|
for (const name of ["group_members", "groups"]) {
|
|
try {
|
|
app.delete(app.findCollectionByNameOrId(name));
|
|
} catch (_) {}
|
|
}
|
|
},
|
|
);
|