@aglyn/aglyn 1.0.0-beta.287 → 1.0.0-beta.288
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -11
- package/src/lib/app-utils/business-profile-values.d.ts +15 -3
- package/src/lib/app-utils/business-profile-values.js +19 -3
- package/src/lib/app-utils/business-profile-values.js.map +1 -1
- package/src/lib/app-utils/business-profile.d.ts +5 -3
- package/src/lib/app-utils/business-profile.js +2 -1
- package/src/lib/app-utils/business-profile.js.map +1 -1
- package/src/lib/app-utils/docs-index.generated.js +16 -16
- package/src/lib/app-utils/docs-index.generated.js.map +1 -1
- package/src/lib/app-utils/host-permissions.d.ts +31 -1
- package/src/lib/app-utils/host-permissions.js +45 -5
- package/src/lib/app-utils/host-permissions.js.map +1 -1
- package/src/lib/app-utils/org-permissions.d.ts +8 -0
- package/src/lib/app-utils/org-permissions.js +2 -0
- package/src/lib/app-utils/org-permissions.js.map +1 -1
- package/src/lib/app-utils/org-role-grants.js +3 -3
- package/src/lib/app-utils/org-role-grants.js.map +1 -1
- package/src/lib/plugin-manager/plugin-entitlements.d.ts +12 -0
- package/src/lib/plugin-manager/plugin-entitlements.js +4 -2
- package/src/lib/plugin-manager/plugin-entitlements.js.map +1 -1
|
@@ -42,7 +42,12 @@ import { type AglynOrgCustomRole } from './org-permissions';
|
|
|
42
42
|
* plugins declare.
|
|
43
43
|
*/
|
|
44
44
|
export declare function hostPermissionKeys(): HostPermissionKey[];
|
|
45
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* What a host role grants a site collaborator for every per-site key, before
|
|
47
|
+
* any toggle. A key whose site-role preset holds for members of the whole
|
|
48
|
+
* workspace only (`workspaceMembersOnly`, AGL-4047) grants a collaborator
|
|
49
|
+
* nothing, whatever their site role.
|
|
50
|
+
*/
|
|
46
51
|
export declare function hostRolePermissionDefaults(role: HostAccessRole): Record<HostPermissionKey, boolean>;
|
|
47
52
|
/**
|
|
48
53
|
* A collaborator's verdict on ONE site for every per-site key, or null where
|
|
@@ -89,6 +94,23 @@ export declare function hostStampedSitePermission(host: {
|
|
|
89
94
|
memberPermissions?: unknown;
|
|
90
95
|
memberRoles?: unknown;
|
|
91
96
|
} | null | undefined, uid: string, permission: string, presetFor: Readonly<Partial<Record<HostAccessRole, boolean>>>): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* The same for a key whose preset holds for members of the whole workspace
|
|
99
|
+
* only (`workspaceMembersOnly`, AGL-4047), which `memberRoles` alone cannot
|
|
100
|
+
* answer: an admin of one site and an admin of the whole workspace project
|
|
101
|
+
* the same `'admin'` there. The site's stamp when the projection wrote one;
|
|
102
|
+
* else the preset of the role `memberRoles` holds for them AND of the role
|
|
103
|
+
* the fresh resolution gives them on the site, for a member of the whole
|
|
104
|
+
* workspace only. Exactly the gate these keys replaced: the projection's
|
|
105
|
+
* role, `orgWide` and the fresh site role, all three.
|
|
106
|
+
*/
|
|
107
|
+
export declare function hostStampedWorkspaceSitePermission(host: {
|
|
108
|
+
memberPermissions?: unknown;
|
|
109
|
+
memberRoles?: unknown;
|
|
110
|
+
} | null | undefined, uid: string, permission: string, presetFor: Readonly<Partial<Record<HostAccessRole, boolean>>>, membership: {
|
|
111
|
+
orgWide: boolean;
|
|
112
|
+
hostRole: string | null | undefined;
|
|
113
|
+
}): boolean;
|
|
92
114
|
/** How one site narrows a workspace-wide member: the access they hold there, the site's verdicts, and which keys follow it. */
|
|
93
115
|
export interface SiteNarrowing {
|
|
94
116
|
/** Their role on the site, narrower than their workspace role. */
|
|
@@ -195,6 +217,14 @@ export type HostDocumentLike = {
|
|
|
195
217
|
* the host document already; it costs no read.
|
|
196
218
|
*/
|
|
197
219
|
export declare function holdsSiteKey(hostDoc: HostDocumentLike, uid: string, key: CoreSiteKey): boolean;
|
|
220
|
+
/**
|
|
221
|
+
* The same for a plugin's key whose preset is the site role (AGL-4047): the
|
|
222
|
+
* site's `memberPermissions` stamp, else `presetFor` read for the member's
|
|
223
|
+
* `memberRoles` entry. `presetFor` is the declaring plugin's own table, so the
|
|
224
|
+
* answer does not depend on which plugins this process loaded. For the doors
|
|
225
|
+
* and the cards that hold the host document already; it costs no read.
|
|
226
|
+
*/
|
|
227
|
+
export declare function holdsStampedSiteKey(hostDoc: HostDocumentLike, uid: string | null | undefined, key: string, presetFor: Readonly<Partial<Record<HostAccessRole, boolean>>>): boolean;
|
|
198
228
|
/**
|
|
199
229
|
* The refusal a door answers when a member does not hold a site key
|
|
200
230
|
* (AGL-4047): it names the permission and who can change it, never a role.
|
|
@@ -45,11 +45,16 @@ import { orgRoleTier } from "./org-roles.js";
|
|
|
45
45
|
*/ export function hostPermissionKeys() {
|
|
46
46
|
return ORG_PERMISSIONS.filter((definition)=>definition.hostRoleDefaults !== undefined).map((definition)=>definition.key);
|
|
47
47
|
}
|
|
48
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* What a host role grants a site collaborator for every per-site key, before
|
|
50
|
+
* any toggle. A key whose site-role preset holds for members of the whole
|
|
51
|
+
* workspace only (`workspaceMembersOnly`, AGL-4047) grants a collaborator
|
|
52
|
+
* nothing, whatever their site role.
|
|
53
|
+
*/ export function hostRolePermissionDefaults(role) {
|
|
49
54
|
const defaults = {};
|
|
50
55
|
for (const definition of ORG_PERMISSIONS){
|
|
51
56
|
if (!definition.hostRoleDefaults) continue;
|
|
52
|
-
defaults[definition.key] = definition.hostRoleDefaults[role] === true;
|
|
57
|
+
defaults[definition.key] = !definition.workspaceMembersOnly && definition.hostRoleDefaults[role] === true;
|
|
53
58
|
}
|
|
54
59
|
return defaults;
|
|
55
60
|
}
|
|
@@ -115,6 +120,12 @@ import { orgRoleTier } from "./org-roles.js";
|
|
|
115
120
|
* workspace standing to refine, so only the site's toggle moves their
|
|
116
121
|
* verdict, as for every other per-site key.
|
|
117
122
|
*
|
|
123
|
+
* A key declared `workspaceMembersOnly` replaces a gate that asked for an
|
|
124
|
+
* admin of the whole workspace who is also this site's admin: its preset at
|
|
125
|
+
* 2 is the site role's for a member of the whole workspace and refusal for a
|
|
126
|
+
* collaborator, whose site role (even Admin) never carried it. The site's
|
|
127
|
+
* toggle at 4 still grants it to them.
|
|
128
|
+
*
|
|
118
129
|
* These keys narrow nothing (`narrowsPerSite` is dropped): the site role is
|
|
119
130
|
* already their preset. With no site named, the org catalog's verdict
|
|
120
131
|
* (`roleDefaults`, then the layers) stands, which is the same answer for a
|
|
@@ -142,7 +153,8 @@ import { orgRoleTier } from "./org-roles.js";
|
|
|
142
153
|
]));
|
|
143
154
|
}
|
|
144
155
|
const toggles = (_member_hostPermissions = member.hostPermissions) == null ? void 0 : _member_hostPermissions[hostId];
|
|
145
|
-
const
|
|
156
|
+
const workspaceMember = isOrgWideMember(member);
|
|
157
|
+
const layers = workspaceMember ? [
|
|
146
158
|
member.roleId ? customRole == null ? void 0 : customRole.permissions : undefined,
|
|
147
159
|
member.permissions,
|
|
148
160
|
toggles
|
|
@@ -152,7 +164,7 @@ import { orgRoleTier } from "./org-roles.js";
|
|
|
152
164
|
const out = {};
|
|
153
165
|
for (const definition of definitions){
|
|
154
166
|
var _definition_hostRoleDefaults;
|
|
155
|
-
let verdict = ((_definition_hostRoleDefaults = definition.hostRoleDefaults) == null ? void 0 : _definition_hostRoleDefaults[role]) === true;
|
|
167
|
+
let verdict = (workspaceMember || !definition.workspaceMembersOnly) && ((_definition_hostRoleDefaults = definition.hostRoleDefaults) == null ? void 0 : _definition_hostRoleDefaults[role]) === true;
|
|
156
168
|
for (const layer of layers){
|
|
157
169
|
const value = layer == null ? void 0 : layer[definition.key];
|
|
158
170
|
if (typeof value === 'boolean') verdict = value;
|
|
@@ -188,6 +200,25 @@ import { orgRoleTier } from "./org-roles.js";
|
|
|
188
200
|
const role = host == null ? void 0 : (_host_memberRoles = host.memberRoles) == null ? void 0 : _host_memberRoles[uid];
|
|
189
201
|
return typeof role === 'string' && presetFor[role] === true;
|
|
190
202
|
}
|
|
203
|
+
/**
|
|
204
|
+
* The same for a key whose preset holds for members of the whole workspace
|
|
205
|
+
* only (`workspaceMembersOnly`, AGL-4047), which `memberRoles` alone cannot
|
|
206
|
+
* answer: an admin of one site and an admin of the whole workspace project
|
|
207
|
+
* the same `'admin'` there. The site's stamp when the projection wrote one;
|
|
208
|
+
* else the preset of the role `memberRoles` holds for them AND of the role
|
|
209
|
+
* the fresh resolution gives them on the site, for a member of the whole
|
|
210
|
+
* workspace only. Exactly the gate these keys replaced: the projection's
|
|
211
|
+
* role, `orgWide` and the fresh site role, all three.
|
|
212
|
+
*/ export function hostStampedWorkspaceSitePermission(host, uid, permission, presetFor, membership) {
|
|
213
|
+
var _host_memberPermissions_uid, _host_memberPermissions;
|
|
214
|
+
const stamped = host == null ? void 0 : (_host_memberPermissions = host.memberPermissions) == null ? void 0 : (_host_memberPermissions_uid = _host_memberPermissions[uid]) == null ? void 0 : _host_memberPermissions_uid[permission];
|
|
215
|
+
if (typeof stamped === 'boolean') return stamped;
|
|
216
|
+
if (membership.orgWide !== true) return false;
|
|
217
|
+
const fresh = membership.hostRole;
|
|
218
|
+
return typeof fresh === 'string' && presetFor[fresh] === true && hostStampedSitePermission({
|
|
219
|
+
memberRoles: host == null ? void 0 : host.memberRoles
|
|
220
|
+
}, uid, permission, presetFor);
|
|
221
|
+
}
|
|
191
222
|
/*
|
|
192
223
|
* A SITE NARROWS A WORKSPACE-WIDE MEMBER (AGL-4047).
|
|
193
224
|
*
|
|
@@ -432,6 +463,15 @@ import { orgRoleTier } from "./org-roles.js";
|
|
|
432
463
|
* the host document already; it costs no read.
|
|
433
464
|
*/ export function holdsSiteKey(hostDoc, uid, key) {
|
|
434
465
|
var _CORE_SITE_ROLE_PRESETS_key;
|
|
466
|
+
return holdsStampedSiteKey(hostDoc, uid, key, (_CORE_SITE_ROLE_PRESETS_key = CORE_SITE_ROLE_PRESETS[key]) != null ? _CORE_SITE_ROLE_PRESETS_key : {});
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* The same for a plugin's key whose preset is the site role (AGL-4047): the
|
|
470
|
+
* site's `memberPermissions` stamp, else `presetFor` read for the member's
|
|
471
|
+
* `memberRoles` entry. `presetFor` is the declaring plugin's own table, so the
|
|
472
|
+
* answer does not depend on which plugins this process loaded. For the doors
|
|
473
|
+
* and the cards that hold the host document already; it costs no read.
|
|
474
|
+
*/ export function holdsStampedSiteKey(hostDoc, uid, key, presetFor) {
|
|
435
475
|
if (!hostDoc || !uid) return false;
|
|
436
476
|
// `hostDoc`, not `host`: the host-field deny guard reads every `host.…`
|
|
437
477
|
// in this folder as a field of the host document, and `get` is none.
|
|
@@ -439,7 +479,7 @@ import { orgRoleTier } from "./org-roles.js";
|
|
|
439
479
|
return hostStampedSitePermission({
|
|
440
480
|
memberPermissions: read('memberPermissions'),
|
|
441
481
|
memberRoles: read('memberRoles')
|
|
442
|
-
}, uid, key,
|
|
482
|
+
}, uid, key, presetFor);
|
|
443
483
|
}
|
|
444
484
|
/**
|
|
445
485
|
* The refusal a door answers when a member does not hold a site key
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/host-permissions.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n AglynOrgMember,\n HostAccessRole,\n HostPermissionKey,\n HostUid,\n OrgRole,\n} from '../foundation'\nimport { refinePermissionMap, type PermissionRefinement } from '../plugin-manager/plugin-permissions'\nimport { hostRoleFor, isOrgWideMember } from './organizations'\nimport { CORE_SITE_ROLE_PRESETS } from './org-role-grants'\nimport {\n permissionRefusalText,\n ORG_PERMISSION_REFINEMENTS,\n ORG_PERMISSIONS,\n resolveOrgPermissions,\n type AglynOrgCustomRole,\n type OrgPermissionDefinition,\n} from './org-permissions'\nimport { orgRoleTier } from './org-roles'\n\n/**\n * Catalog keys a site collaborator holds PER SITE (AGL-2984), resolved on one\n * of two axes.\n *\n * A plugin that declares a catalog key with `hostRoleDefaults` makes it a\n * per-site key. For the people whose membership spans the workspace, the key\n * is an ordinary catalog key: their org role's default, refined by a custom\n * role and by per-member overrides, the same on every site. A site\n * collaborator has no org standing to refine — their membership exists only\n * to carry access to named sites — so for them the key is decided PER SITE,\n * from the host role they hold there, refined by `hostPermissions[hostId]` on\n * their member document.\n *\n * Which axis applies is `isOrgWideMember`, the predicate the rules projection\n * and the scope resolver already share. A collaborator asked about a site\n * they were never granted resolves to nothing, and so does one whose request\n * names no site at all: there is no host role to read a default from, and\n * guessing one would let a request reach around the per-site toggle by\n * omitting the site.\n */\n\n/**\n * The catalog keys a collaborator can hold per site, in catalog order: every\n * key with host-role defaults, the core's site keys (AGL-4047) and the ones\n * plugins declare.\n */\nexport function hostPermissionKeys(): HostPermissionKey[] {\n return ORG_PERMISSIONS.filter((definition) => definition.hostRoleDefaults !== undefined).map(\n (definition) => definition.key,\n )\n}\n\n/** What a host role grants for every per-site key, before any toggle. */\nexport function hostRolePermissionDefaults(\n role: HostAccessRole,\n): Record<HostPermissionKey, boolean> {\n const defaults: Record<HostPermissionKey, boolean> = {}\n for (const definition of ORG_PERMISSIONS) {\n if (!definition.hostRoleDefaults) continue\n defaults[definition.key] = definition.hostRoleDefaults[role] === true\n }\n return defaults\n}\n\n/** Every per-site key, refused. */\nfunction noHostPermissions(): Record<HostPermissionKey, boolean> {\n return Object.fromEntries(hostPermissionKeys().map((key) => [key, false]))\n}\n\n/**\n * The catalog's refinements whose key and broader key are both in `map`\n * (AGL-4047): the links a per-site map can settle on its own. A link to a\n * key the map does not carry would read that key as refused and add it.\n */\nfunction refinementsWithin(map: Readonly<Record<string, boolean>>): PermissionRefinement[] {\n return ORG_PERMISSION_REFINEMENTS.filter(([key, parent]) => key in map && parent in map)\n}\n\n/**\n * A collaborator's verdict on ONE site for every per-site key, or null where\n * they have no access to that site at all. An absent toggle reads as the host\n * role's default, which is what makes a member document written before\n * `hostPermissions` existed resolve exactly as it did before.\n */\nexport function resolveCollaboratorHostPermissions(\n member: Partial<AglynOrgMember> | null | undefined,\n hostId: HostUid | null | undefined,\n): Record<HostPermissionKey, boolean> | null {\n if (!member || !hostId) return null\n const role = hostRoleFor(member, hostId)\n if (!role) return null\n const merged = hostRolePermissionDefaults(role)\n const toggles = member.hostPermissions?.[hostId]\n if (toggles) {\n for (const key of Object.keys(merged)) {\n const value = toggles[key]\n if (typeof value === 'boolean') merged[key] = value\n }\n }\n // A per-site key that follows or refines another per-site key (AGL-4047)\n // takes its verdict from that key on this site where the site sets nothing\n // for it, as the org catalog's resolver does with a custom role.\n return refinePermissionMap(merged, refinementsWithin(merged), [toggles])\n}\n\n/*\n * KEYS WHOSE PRESET IS THE SITE ROLE (AGL-4047).\n *\n * Some checks were written against the member's role on a site: who may book\n * a walk-in, change a stay or edit a site's reservations asked whether their\n * `memberRoles` entry was Admin, Editor or Author. Roles are only presets of\n * permissions, so those checks became keys, and a key that replaces a gate\n * on the site role keeps that role as its preset (`presetFromSiteRole`):\n *\n * 1. the member's role ON THE SITE (`hostRoleFor`): Admin for the owner and\n * admins, a workspace-wide editor's or viewer's own role unless the site\n * gives them other access there, narrower or wider, and a collaborator's\n * site role; no access to the site holds nothing;\n * 2. that role's `hostRoleDefaults` verdict for the key;\n * 3. then, for a workspace-wide member, their custom role's verdict and\n * their own permissions' verdict, when either sets the key;\n * 4. then the site's own toggle for them (`hostPermissions[hostId][key]`).\n *\n * With nothing set at 3 or 4, the verdict is exactly what the role gate\n * answered, for every member on every site, which is how the built-in roles\n * keep the access they had. A collaborator has no custom role and no\n * workspace standing to refine, so only the site's toggle moves their\n * verdict, as for every other per-site key.\n *\n * These keys narrow nothing (`narrowsPerSite` is dropped): the site role is\n * already their preset. With no site named, the org catalog's verdict\n * (`roleDefaults`, then the layers) stands, which is the same answer for a\n * workspace-wide member on a site where their access is their workspace role.\n */\n\n/** The catalog keys whose preset is the member's role on the site, in catalog order. */\nexport function siteRolePresetPermissionKeys(): string[] {\n return ORG_PERMISSIONS.filter((definition) => definition.presetFromSiteRole).map(\n (definition) => definition.key,\n )\n}\n\n/** Is this a key whose preset is the member's role on the site? */\nexport function isSiteRolePresetPermission(permission: string): boolean {\n return ORG_PERMISSIONS.some(\n (definition) => definition.key === permission && definition.presetFromSiteRole === true,\n )\n}\n\n/**\n * A member's verdict on ONE site for every key whose preset is their role\n * there (see above). `customRole` is their custom role document when they\n * carry a `roleId` and the caller has it, and is ignored for a collaborator.\n * No site named, or no access to it, refuses every such key.\n */\nexport function resolveSiteRolePresetPermissions(\n member: (Partial<AglynOrgMember> & { roleId?: string | null }) | null | undefined,\n hostId: HostUid | null | undefined,\n customRole?: Pick<AglynOrgCustomRole, 'permissions'> | null,\n): Record<string, boolean> {\n const definitions = ORG_PERMISSIONS.filter((definition) => definition.presetFromSiteRole)\n if (!definitions.length) return {}\n const role = member && hostId ? hostRoleFor(member, hostId) : null\n if (!member || !hostId || !role) {\n return Object.fromEntries(definitions.map((definition) => [definition.key, false]))\n }\n const toggles = member.hostPermissions?.[hostId]\n const layers: ReadonlyArray<Readonly<Partial<Record<string, unknown>>> | null | undefined> =\n isOrgWideMember(member)\n ? [member.roleId ? customRole?.permissions : undefined, member.permissions, toggles]\n : [toggles]\n const out: Record<string, boolean> = {}\n for (const definition of definitions) {\n let verdict = definition.hostRoleDefaults?.[role] === true\n for (const layer of layers) {\n const value = layer?.[definition.key]\n if (typeof value === 'boolean') verdict = value\n }\n out[definition.key] = verdict\n }\n return refinePermissionMap(out, refinementsWithin(out), layers)\n}\n\n/**\n * `granted` with every key whose preset is the site role decided for this\n * site. With no site named it is `granted` as given, so a resolver can call\n * it unconditionally.\n */\nexport function applySiteRolePresets<T extends Record<string, boolean>>(\n granted: T,\n member: (Partial<AglynOrgMember> & { roleId?: string | null }) | null | undefined,\n hostId: HostUid | null | undefined,\n customRole?: Pick<AglynOrgCustomRole, 'permissions'> | null,\n): T {\n if (!hostId) return granted\n return { ...granted, ...resolveSiteRolePresetPermissions(member, hostId, customRole) }\n}\n\n/**\n * The verdict the site's own stamp gives a member for one key whose preset\n * is the site role, as the Firestore rules read it (AGL-4047): the site's\n * `memberPermissions[uid][key]` when the projection wrote one, else the\n * preset of the role the site's `memberRoles` projection holds for them.\n *\n * For a door that has the host document in hand and asks what the rules\n * ask, so the two cannot disagree: the stamp is written beside\n * `memberRoles` by the same projection, with every layer applied, and a\n * site the projection has not reached since the key existed answers exactly\n * as the role gate it replaced. `presetFor` is the declaring plugin's own\n * table, so the answer does not depend on which plugins this process loaded.\n */\nexport function hostStampedSitePermission(\n host: { memberPermissions?: unknown; memberRoles?: unknown } | null | undefined,\n uid: string,\n permission: string,\n presetFor: Readonly<Partial<Record<HostAccessRole, boolean>>>,\n): boolean {\n const stamped = (host?.memberPermissions as Record<string, Record<string, unknown> | undefined> | undefined)?.[uid]?.[\n permission\n ]\n if (typeof stamped === 'boolean') return stamped\n const role = (host?.memberRoles as Record<string, unknown> | undefined)?.[uid]\n return typeof role === 'string' && presetFor[role as HostAccessRole] === true\n}\n\n/*\n * A SITE NARROWS A WORKSPACE-WIDE MEMBER (AGL-4047).\n *\n * An editor who works across the workspace can be given Viewer or Author\n * access to one site (`hostAccess[hostId]`, which `hostRoleFor` reads ahead\n * of `allHosts`). That narrowed their content rights there and nothing else,\n * so a key the workspace grants an editor, such as working a site's\n * register, still held on the site they were narrowed on.\n *\n * A plugin marks the keys a site CAN narrow with `narrowsPerSite`, and\n * whether each one does is a control with three layers, the nearest set one\n * winning (`siteNarrowingChoices`):\n *\n * - the member's own choice (`member.siteNarrowing[key]`);\n * - else their custom role's (`customRole.siteNarrowing[key]`);\n * - else the built-in role's default the declaration names.\n *\n * `true` is \"Follow the site role\", `false` is \"Keep this permission\". On a\n * site that narrows the member, each key that follows the site role is\n * decided for that site:\n *\n * 1. the site's own verdict for the key (`hostPermissions[hostId][key]`),\n * when the site set one;\n * 2. else, for a key that refines another key that also follows the site\n * role, that key's verdict on this site, never more than the workspace\n * grants;\n * 3. else the narrower access's default for the key, never more than the\n * workspace grants;\n *\n * and a key they keep is the workspace's verdict, as everywhere else. A finer\n * key they hold on the site (one the site grants, or one they keep and the\n * workspace grants) brings the key it refines on this site with it, unless\n * the site refuses that key, because a refining key is never held without\n * it. The other finer keys do not follow that implied grant: allowing \"sell\"\n * on a site is not allowing refunds.\n *\n * A member whose access to every site matches their workspace role (the\n * owner and admins always do), one who keeps every key a site can narrow,\n * and a site collaborator, whose keys come from their site role already, all\n * resolve exactly as before.\n */\n\n/** Host roles from the widest down, for \"is this site's access narrower?\". */\nconst HOST_ROLE_RANK: Readonly<Record<HostAccessRole, number>> = {\n admin: 3,\n editor: 2,\n author: 1,\n viewer: 0,\n}\n\n/** How one site narrows a workspace-wide member: the access they hold there, the site's verdicts, and which keys follow it. */\nexport interface SiteNarrowing {\n /** Their role on the site, narrower than their workspace role. */\n role: HostAccessRole\n /** `hostPermissions[hostId]`: the verdicts the site set for them. */\n grants: Readonly<Partial<Record<string, unknown>>>\n /**\n * Every key a site can narrow, `true` where it follows the site role for\n * this member and `false` where they keep it (`siteNarrowingChoices`).\n */\n narrows: Readonly<Record<string, boolean>>\n}\n\n/** The catalog keys a site CAN narrow (`narrowsPerSite`), in catalog order. */\nexport function siteNarrowedPermissionKeys(): string[] {\n return ORG_PERMISSIONS.filter((definition) => definition.narrowsPerSite).map(\n (definition) => definition.key,\n )\n}\n\n/**\n * Could any site narrow a member of this org role? Not the owner or an\n * admin, who are admins of every site, and not a role whose site access has\n * nothing narrower below it (a viewer). The editors' control is the one that\n * changes anything; the role editor says so beside it.\n */\nexport function roleCanBeNarrowed(role: string | null | undefined): boolean {\n if (role === 'owner' || role === 'admin') return false\n return HOST_ROLE_RANK[orgRoleTier(role) as HostAccessRole] > 0\n}\n\n/**\n * Whether each key a site can narrow follows the site role for this member\n * (`true`) or is kept (`false`): their own choice, else their custom role's\n * (when they carry its id and it was supplied), else the built-in role's\n * default.\n */\nexport function siteNarrowingChoices(\n member: (Partial<AglynOrgMember> & { roleId?: string | null }) | null | undefined,\n customRole?: Pick<AglynOrgCustomRole, 'siteNarrowing'> | null,\n): Record<string, boolean> {\n const role = (member?.role ?? 'viewer') as OrgRole\n const own = member?.siteNarrowing ?? {}\n const fromRole = member?.roleId ? (customRole?.siteNarrowing ?? {}) : {}\n const out: Record<string, boolean> = {}\n for (const definition of ORG_PERMISSIONS) {\n if (!definition.narrowsPerSite) continue\n const key = definition.key\n const mine = own[key]\n const theirRole = fromRole[key]\n out[key] =\n typeof mine === 'boolean'\n ? mine\n : typeof theirRole === 'boolean'\n ? theirRole\n : definition.narrowsPerSite[role] === true\n }\n return out\n}\n\n/**\n * Is this member's access to this site narrower than their workspace role?\n * The cheap half of `siteNarrowingFor`, which needs no custom role: a caller\n * that has to read one asks this first, and reads nothing for everyone else.\n */\nexport function siteMayNarrow(\n member: Partial<AglynOrgMember> | null | undefined,\n hostId: HostUid | null | undefined,\n): HostAccessRole | null {\n if (!member || !hostId || !isOrgWideMember(member)) return null\n const role = hostRoleFor(member, hostId)\n if (!role) return null\n const workspaceRole = orgRoleTier(member.role) as HostAccessRole\n if (HOST_ROLE_RANK[role] >= HOST_ROLE_RANK[workspaceRole]) return null\n return role\n}\n\n/**\n * How this site narrows this member, or null where it does not: a member\n * who is not workspace-wide, has no access to the site, whose access there\n * is as wide as their workspace role (owners and admins always), or who\n * keeps every key a site can narrow. `customRole` is their custom role\n * document when they carry a `roleId`; without it, only their own choices\n * and the built-in defaults decide.\n */\nexport function siteNarrowingFor(\n member: Partial<AglynOrgMember> | null | undefined,\n hostId: HostUid | null | undefined,\n customRole?: Pick<AglynOrgCustomRole, 'siteNarrowing'> | null,\n): SiteNarrowing | null {\n const role = siteMayNarrow(member, hostId)\n if (!role) return null\n const narrows = siteNarrowingChoices(member, customRole)\n if (!Object.values(narrows).some(Boolean)) return null\n return { role, grants: member?.hostPermissions?.[hostId as HostUid] ?? {}, narrows }\n}\n\n/** The keys that follow the site role under a narrowing, in catalog order; none without one. */\nexport function narrowedPermissionKeysOf(narrowing: SiteNarrowing | null | undefined): string[] {\n if (!narrowing) return []\n return siteNarrowedPermissionKeys().filter((key) => narrowing.narrows[key] === true)\n}\n\n/** What a site access holds by default for a key: its site default, else its tier's (Author on the Viewer tier). */\nfunction narrowedDefault(definition: OrgPermissionDefinition, role: HostAccessRole): boolean {\n const site = definition.hostRoleDefaults?.[role]\n if (typeof site === 'boolean') return site\n return definition.roleDefaults[orgRoleTier(role)] === true\n}\n\n/**\n * A workspace-wide member's resolved map with the keys that follow the site\n * role decided for that site (see above). With no narrowing it is the map\n * as given, so every resolver can call it unconditionally.\n */\nexport function narrowPermissionsToSite<T extends Record<string, boolean>>(\n granted: T,\n narrowing: SiteNarrowing | null | undefined,\n): T {\n if (!narrowing) return granted\n const definitions = ORG_PERMISSIONS.filter((definition) => definition.narrowsPerSite)\n if (!definitions.length) return granted\n const narrowable = new Set(definitions.map((definition) => definition.key))\n const follows = (key: string): boolean => narrowing.narrows[key] === true\n // A finer key's broader key, among the keys a site can narrow.\n const broader = new Map<string, string>()\n for (const [key, parent, kind] of ORG_PERMISSION_REFINEMENTS) {\n if (kind !== 'follows' && narrowable.has(key) && narrowable.has(parent)) broader.set(key, parent)\n }\n const siteVerdict = (key: string): boolean | undefined => {\n const value = narrowing.grants[key]\n return typeof value === 'boolean' ? value : undefined\n }\n const depth = (key: string): number => {\n const seen = new Set<string>()\n let steps = 0\n for (let current = key; broader.has(current) && !seen.has(current); steps += 1) {\n seen.add(current)\n current = broader.get(current) as string\n }\n return steps\n }\n const out: Record<string, boolean> = { ...granted }\n for (const definition of [...definitions].sort((a, b) => depth(a.key) - depth(b.key))) {\n const key = definition.key\n const workspace = granted[key] === true\n // Kept: the workspace's verdict, as on every other site.\n if (!follows(key)) {\n out[key] = workspace\n continue\n }\n const own = siteVerdict(key)\n const parent = broader.get(key)\n if (own !== undefined) out[key] = own\n else if (parent && follows(parent)) out[key] = out[parent] === true && workspace\n else out[key] = workspace && narrowedDefault(definition, narrowing.role)\n }\n for (const definition of definitions) {\n const key = definition.key\n const held = follows(key) ? siteVerdict(key) === true : granted[key] === true\n if (!held) continue\n const seen = new Set<string>()\n for (let parent = broader.get(key); parent && !seen.has(parent); parent = broader.get(parent)) {\n seen.add(parent)\n // A kept broader key is the workspace's verdict already.\n if (!follows(parent) || siteVerdict(parent) === false) break\n out[parent] = true\n }\n }\n return refinePermissionMap(out, ORG_PERMISSION_REFINEMENTS) as T\n}\n\n/**\n * A member's verdict for every per-site key, on whichever axis their\n * membership is on.\n *\n * `customRole` is the member's custom role document when they carry a\n * `roleId` and the caller has it in hand, and is ignored for a collaborator,\n * whose org role is a seat-accounting fact rather than a grant. `hostId` is\n * the site the request is about; an org-wide member resolves the same on\n * every site and with none named, except on a site that narrows them.\n *\n * An org-wide member's map also carries every key a site can narrow\n * (AGL-4047), decided for `hostId`, so the site's `memberPermissions`\n * projection answers the rules what the server answers. A collaborator's\n * map does not: their register and waivers keys come from their site role\n * and their own overrides, which the rules read from their member document\n * as before.\n */\nexport function resolveMemberHostPermissions(options: {\n member: Partial<AglynOrgMember> | null | undefined\n customRole?: AglynOrgCustomRole | null\n hostId?: HostUid | null\n}): Record<HostPermissionKey, boolean> {\n const { member, customRole, hostId } = options\n if (!member) return noHostPermissions()\n if (isOrgWideMember(member)) {\n // The keys whose preset is the site role (AGL-4047) are decided for this\n // site last; they narrow nothing, so the narrowing pass leaves them be.\n const granted = applySiteRolePresets(\n narrowPermissionsToSite(\n resolveOrgPermissions(member, customRole ?? null),\n siteNarrowingFor(member, hostId, customRole ?? null),\n ),\n member,\n hostId,\n customRole ?? null,\n )\n return Object.fromEntries(\n [...hostPermissionKeys(), ...siteNarrowedPermissionKeys()].map((key) => [key, granted[key] === true]),\n )\n }\n return resolveCollaboratorHostPermissions(member, hostId) ?? noHostPermissions()\n}\n\n/**\n * The `memberPermissions` projection stamped on a host document beside\n * `memberRoles`: every member who can reach the site, with the verdict for\n * every per-site key they hold ON it. Org-wide members are resolved against\n * the custom roles the caller loaded (one read per distinct role, as\n * `syncOrgAuthProjections` already does for `resolvedPermissions`);\n * collaborators against their host role. A member who cannot reach the site\n * has no entry, matching `projectHostMemberRoles`.\n */\nexport function projectHostMemberPermissions(\n members: ReadonlyArray<Partial<AglynOrgMember> & { $id: string }>,\n hostId: HostUid,\n customRoles: ReadonlyMap<string, AglynOrgCustomRole | null>,\n): Record<string, Record<HostPermissionKey, boolean>> {\n const projection: Record<string, Record<HostPermissionKey, boolean>> = {}\n for (const member of members) {\n if (!hostRoleFor(member, hostId)) continue\n projection[member.$id] = resolveMemberHostPermissions({\n member,\n customRole: member.roleId ? (customRoles.get(member.roleId) ?? null) : null,\n hostId,\n })\n }\n return projection\n}\n\n/** The core's site keys (AGL-4047): `CORE_SITE_ROLE_PRESETS`. */\nexport type CoreSiteKey = 'site.edit' | 'site.publish' | 'site.sensitive' | 'site.manage'\n\n/** A host document, as a snapshot (`get`) or as its data. */\nexport type HostDocumentLike =\n | { get(field: string): unknown }\n | { memberPermissions?: unknown; memberRoles?: unknown }\n | null\n | undefined\n\n/**\n * Does this member hold one of the core's site keys on this site (AGL-4047)?\n * The door's twin of the rules' `canWriteHostContent`,\n * `canPublishHostContent`, `canReadHostSensitive` and site-settings checks:\n * the site's `memberPermissions` stamp, else the preset of the member's\n * `memberRoles` entry (`hostStampedSitePermission`), so a route that asks it\n * answers what the rules answer for the same write. For the routes that read\n * the host document already; it costs no read.\n */\nexport function holdsSiteKey(hostDoc: HostDocumentLike, uid: string, key: CoreSiteKey): boolean {\n if (!hostDoc || !uid) return false\n // `hostDoc`, not `host`: the host-field deny guard reads every `host.…`\n // in this folder as a field of the host document, and `get` is none.\n const read = (field: string): unknown =>\n typeof (hostDoc as { get?: unknown }).get === 'function'\n ? (hostDoc as { get(field: string): unknown }).get(field)\n : (hostDoc as Record<string, unknown>)[field]\n return hostStampedSitePermission(\n { memberPermissions: read('memberPermissions'), memberRoles: read('memberRoles') },\n uid,\n key,\n CORE_SITE_ROLE_PRESETS[key] ?? {},\n )\n}\n\n/**\n * The refusal a door answers when a member does not hold a site key\n * (AGL-4047): it names the permission and who can change it, never a role.\n */\nexport function siteKeyRefusal(key: string): string {\n return permissionRefusalText(key)\n}\n\n"],"names":["refinePermissionMap","hostRoleFor","isOrgWideMember","CORE_SITE_ROLE_PRESETS","permissionRefusalText","ORG_PERMISSION_REFINEMENTS","ORG_PERMISSIONS","resolveOrgPermissions","orgRoleTier","hostPermissionKeys","filter","definition","hostRoleDefaults","undefined","map","key","hostRolePermissionDefaults","role","defaults","noHostPermissions","Object","fromEntries","refinementsWithin","parent","resolveCollaboratorHostPermissions","member","hostId","merged","toggles","hostPermissions","keys","value","siteRolePresetPermissionKeys","presetFromSiteRole","isSiteRolePresetPermission","permission","some","resolveSiteRolePresetPermissions","customRole","definitions","length","layers","roleId","permissions","out","verdict","layer","applySiteRolePresets","granted","hostStampedSitePermission","host","uid","presetFor","stamped","memberPermissions","memberRoles","HOST_ROLE_RANK","admin","editor","author","viewer","siteNarrowedPermissionKeys","narrowsPerSite","roleCanBeNarrowed","siteNarrowingChoices","own","siteNarrowing","fromRole","mine","theirRole","siteMayNarrow","workspaceRole","siteNarrowingFor","narrows","values","Boolean","grants","narrowedPermissionKeysOf","narrowing","narrowedDefault","site","roleDefaults","narrowPermissionsToSite","narrowable","Set","follows","broader","Map","kind","has","set","siteVerdict","depth","seen","steps","current","add","get","sort","a","b","workspace","held","resolveMemberHostPermissions","options","projectHostMemberPermissions","members","customRoles","projection","$id","holdsSiteKey","hostDoc","read","field","siteKeyRefusal"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AASD,SAASA,mBAAmB,QAAmC,0CAAsC;AACrG,SAASC,WAAW,EAAEC,eAA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AQC,GACD,OAAO,SAASsF,6BACdC,OAAiE,EACjEhF,MAAe,EACfiF,WAA2D;IAE3D,MAAMC,aAAiE,CAAC;IACxE,KAAK,MAAMnF,UAAUiF,QAAS;YAIGC;QAH/B,IAAI,CAAC1G,YAAYwB,QAAQC,SAAS;QAClCkF,UAAU,CAACnF,OAAOoF,GAAG,CAAC,GAAGN,6BAA6B;YACpD9E;YACAa,YAAYb,OAAOiB,MAAM,IAAIiE,mBAAAA,YAAYV,GAAG,CAACxE,OAAOiB,MAAM,aAA7BiE,mBAAkC,OAAQ;YACvEjF;QACF;IACF;IACA,OAAOkF;AACT;AAYA;;;;;;;;CAQC,GACD,OAAO,SAASE,aAAaC,OAAyB,EAAE5D,GAAW,EAAEpC,GAAgB;QAYjFZ;IAXF,IAAI,CAAC4G,WAAW,CAAC5D,KAAK,OAAO;IAC7B,wEAAwE;IACxE,qEAAqE;IACrE,MAAM6D,OAAO,CAACC,QACZ,OAAO,AAACF,QAA8Bd,GAAG,KAAK,aAC1C,AAACc,QAA4Cd,GAAG,CAACgB,SACjD,AAACF,OAAmC,CAACE,MAAM;IACjD,OAAOhE,0BACL;QAAEK,mBAAmB0D,KAAK;QAAsBzD,aAAayD,KAAK;IAAe,GACjF7D,KACApC,MACAZ,8BAAAA,sBAAsB,CAACY,IAAI,YAA3BZ,8BAA+B,CAAC;AAEpC;AAEA;;;CAGC,GACD,OAAO,SAAS+G,eAAenG,GAAW;IACxC,OAAOX,sBAAsBW;AAC/B"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/host-permissions.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n AglynOrgMember,\n HostAccessRole,\n HostPermissionKey,\n HostUid,\n OrgRole,\n} from '../foundation'\nimport { refinePermissionMap, type PermissionRefinement } from '../plugin-manager/plugin-permissions'\nimport { hostRoleFor, isOrgWideMember } from './organizations'\nimport { CORE_SITE_ROLE_PRESETS } from './org-role-grants'\nimport {\n permissionRefusalText,\n ORG_PERMISSION_REFINEMENTS,\n ORG_PERMISSIONS,\n resolveOrgPermissions,\n type AglynOrgCustomRole,\n type OrgPermissionDefinition,\n} from './org-permissions'\nimport { orgRoleTier } from './org-roles'\n\n/**\n * Catalog keys a site collaborator holds PER SITE (AGL-2984), resolved on one\n * of two axes.\n *\n * A plugin that declares a catalog key with `hostRoleDefaults` makes it a\n * per-site key. For the people whose membership spans the workspace, the key\n * is an ordinary catalog key: their org role's default, refined by a custom\n * role and by per-member overrides, the same on every site. A site\n * collaborator has no org standing to refine — their membership exists only\n * to carry access to named sites — so for them the key is decided PER SITE,\n * from the host role they hold there, refined by `hostPermissions[hostId]` on\n * their member document.\n *\n * Which axis applies is `isOrgWideMember`, the predicate the rules projection\n * and the scope resolver already share. A collaborator asked about a site\n * they were never granted resolves to nothing, and so does one whose request\n * names no site at all: there is no host role to read a default from, and\n * guessing one would let a request reach around the per-site toggle by\n * omitting the site.\n */\n\n/**\n * The catalog keys a collaborator can hold per site, in catalog order: every\n * key with host-role defaults, the core's site keys (AGL-4047) and the ones\n * plugins declare.\n */\nexport function hostPermissionKeys(): HostPermissionKey[] {\n return ORG_PERMISSIONS.filter((definition) => definition.hostRoleDefaults !== undefined).map(\n (definition) => definition.key,\n )\n}\n\n/**\n * What a host role grants a site collaborator for every per-site key, before\n * any toggle. A key whose site-role preset holds for members of the whole\n * workspace only (`workspaceMembersOnly`, AGL-4047) grants a collaborator\n * nothing, whatever their site role.\n */\nexport function hostRolePermissionDefaults(\n role: HostAccessRole,\n): Record<HostPermissionKey, boolean> {\n const defaults: Record<HostPermissionKey, boolean> = {}\n for (const definition of ORG_PERMISSIONS) {\n if (!definition.hostRoleDefaults) continue\n defaults[definition.key] = !definition.workspaceMembersOnly && definition.hostRoleDefaults[role] === true\n }\n return defaults\n}\n\n/** Every per-site key, refused. */\nfunction noHostPermissions(): Record<HostPermissionKey, boolean> {\n return Object.fromEntries(hostPermissionKeys().map((key) => [key, false]))\n}\n\n/**\n * The catalog's refinements whose key and broader key are both in `map`\n * (AGL-4047): the links a per-site map can settle on its own. A link to a\n * key the map does not carry would read that key as refused and add it.\n */\nfunction refinementsWithin(map: Readonly<Record<string, boolean>>): PermissionRefinement[] {\n return ORG_PERMISSION_REFINEMENTS.filter(([key, parent]) => key in map && parent in map)\n}\n\n/**\n * A collaborator's verdict on ONE site for every per-site key, or null where\n * they have no access to that site at all. An absent toggle reads as the host\n * role's default, which is what makes a member document written before\n * `hostPermissions` existed resolve exactly as it did before.\n */\nexport function resolveCollaboratorHostPermissions(\n member: Partial<AglynOrgMember> | null | undefined,\n hostId: HostUid | null | undefined,\n): Record<HostPermissionKey, boolean> | null {\n if (!member || !hostId) return null\n const role = hostRoleFor(member, hostId)\n if (!role) return null\n const merged = hostRolePermissionDefaults(role)\n const toggles = member.hostPermissions?.[hostId]\n if (toggles) {\n for (const key of Object.keys(merged)) {\n const value = toggles[key]\n if (typeof value === 'boolean') merged[key] = value\n }\n }\n // A per-site key that follows or refines another per-site key (AGL-4047)\n // takes its verdict from that key on this site where the site sets nothing\n // for it, as the org catalog's resolver does with a custom role.\n return refinePermissionMap(merged, refinementsWithin(merged), [toggles])\n}\n\n/*\n * KEYS WHOSE PRESET IS THE SITE ROLE (AGL-4047).\n *\n * Some checks were written against the member's role on a site: who may book\n * a walk-in, change a stay or edit a site's reservations asked whether their\n * `memberRoles` entry was Admin, Editor or Author. Roles are only presets of\n * permissions, so those checks became keys, and a key that replaces a gate\n * on the site role keeps that role as its preset (`presetFromSiteRole`):\n *\n * 1. the member's role ON THE SITE (`hostRoleFor`): Admin for the owner and\n * admins, a workspace-wide editor's or viewer's own role unless the site\n * gives them other access there, narrower or wider, and a collaborator's\n * site role; no access to the site holds nothing;\n * 2. that role's `hostRoleDefaults` verdict for the key;\n * 3. then, for a workspace-wide member, their custom role's verdict and\n * their own permissions' verdict, when either sets the key;\n * 4. then the site's own toggle for them (`hostPermissions[hostId][key]`).\n *\n * With nothing set at 3 or 4, the verdict is exactly what the role gate\n * answered, for every member on every site, which is how the built-in roles\n * keep the access they had. A collaborator has no custom role and no\n * workspace standing to refine, so only the site's toggle moves their\n * verdict, as for every other per-site key.\n *\n * A key declared `workspaceMembersOnly` replaces a gate that asked for an\n * admin of the whole workspace who is also this site's admin: its preset at\n * 2 is the site role's for a member of the whole workspace and refusal for a\n * collaborator, whose site role (even Admin) never carried it. The site's\n * toggle at 4 still grants it to them.\n *\n * These keys narrow nothing (`narrowsPerSite` is dropped): the site role is\n * already their preset. With no site named, the org catalog's verdict\n * (`roleDefaults`, then the layers) stands, which is the same answer for a\n * workspace-wide member on a site where their access is their workspace role.\n */\n\n/** The catalog keys whose preset is the member's role on the site, in catalog order. */\nexport function siteRolePresetPermissionKeys(): string[] {\n return ORG_PERMISSIONS.filter((definition) => definition.presetFromSiteRole).map(\n (definition) => definition.key,\n )\n}\n\n/** Is this a key whose preset is the member's role on the site? */\nexport function isSiteRolePresetPermission(permission: string): boolean {\n return ORG_PERMISSIONS.some(\n (definition) => definition.key === permission && definition.presetFromSiteRole === true,\n )\n}\n\n/**\n * A member's verdict on ONE site for every key whose preset is their role\n * there (see above). `customRole` is their custom role document when they\n * carry a `roleId` and the caller has it, and is ignored for a collaborator.\n * No site named, or no access to it, refuses every such key.\n */\nexport function resolveSiteRolePresetPermissions(\n member: (Partial<AglynOrgMember> & { roleId?: string | null }) | null | undefined,\n hostId: HostUid | null | undefined,\n customRole?: Pick<AglynOrgCustomRole, 'permissions'> | null,\n): Record<string, boolean> {\n const definitions = ORG_PERMISSIONS.filter((definition) => definition.presetFromSiteRole)\n if (!definitions.length) return {}\n const role = member && hostId ? hostRoleFor(member, hostId) : null\n if (!member || !hostId || !role) {\n return Object.fromEntries(definitions.map((definition) => [definition.key, false]))\n }\n const toggles = member.hostPermissions?.[hostId]\n const workspaceMember = isOrgWideMember(member)\n const layers: ReadonlyArray<Readonly<Partial<Record<string, unknown>>> | null | undefined> =\n workspaceMember\n ? [member.roleId ? customRole?.permissions : undefined, member.permissions, toggles]\n : [toggles]\n const out: Record<string, boolean> = {}\n for (const definition of definitions) {\n let verdict =\n (workspaceMember || !definition.workspaceMembersOnly) && definition.hostRoleDefaults?.[role] === true\n for (const layer of layers) {\n const value = layer?.[definition.key]\n if (typeof value === 'boolean') verdict = value\n }\n out[definition.key] = verdict\n }\n return refinePermissionMap(out, refinementsWithin(out), layers)\n}\n\n/**\n * `granted` with every key whose preset is the site role decided for this\n * site. With no site named it is `granted` as given, so a resolver can call\n * it unconditionally.\n */\nexport function applySiteRolePresets<T extends Record<string, boolean>>(\n granted: T,\n member: (Partial<AglynOrgMember> & { roleId?: string | null }) | null | undefined,\n hostId: HostUid | null | undefined,\n customRole?: Pick<AglynOrgCustomRole, 'permissions'> | null,\n): T {\n if (!hostId) return granted\n return { ...granted, ...resolveSiteRolePresetPermissions(member, hostId, customRole) }\n}\n\n/**\n * The verdict the site's own stamp gives a member for one key whose preset\n * is the site role, as the Firestore rules read it (AGL-4047): the site's\n * `memberPermissions[uid][key]` when the projection wrote one, else the\n * preset of the role the site's `memberRoles` projection holds for them.\n *\n * For a door that has the host document in hand and asks what the rules\n * ask, so the two cannot disagree: the stamp is written beside\n * `memberRoles` by the same projection, with every layer applied, and a\n * site the projection has not reached since the key existed answers exactly\n * as the role gate it replaced. `presetFor` is the declaring plugin's own\n * table, so the answer does not depend on which plugins this process loaded.\n */\nexport function hostStampedSitePermission(\n host: { memberPermissions?: unknown; memberRoles?: unknown } | null | undefined,\n uid: string,\n permission: string,\n presetFor: Readonly<Partial<Record<HostAccessRole, boolean>>>,\n): boolean {\n const stamped = (host?.memberPermissions as Record<string, Record<string, unknown> | undefined> | undefined)?.[uid]?.[\n permission\n ]\n if (typeof stamped === 'boolean') return stamped\n const role = (host?.memberRoles as Record<string, unknown> | undefined)?.[uid]\n return typeof role === 'string' && presetFor[role as HostAccessRole] === true\n}\n\n/**\n * The same for a key whose preset holds for members of the whole workspace\n * only (`workspaceMembersOnly`, AGL-4047), which `memberRoles` alone cannot\n * answer: an admin of one site and an admin of the whole workspace project\n * the same `'admin'` there. The site's stamp when the projection wrote one;\n * else the preset of the role `memberRoles` holds for them AND of the role\n * the fresh resolution gives them on the site, for a member of the whole\n * workspace only. Exactly the gate these keys replaced: the projection's\n * role, `orgWide` and the fresh site role, all three.\n */\nexport function hostStampedWorkspaceSitePermission(\n host: { memberPermissions?: unknown; memberRoles?: unknown } | null | undefined,\n uid: string,\n permission: string,\n presetFor: Readonly<Partial<Record<HostAccessRole, boolean>>>,\n membership: { orgWide: boolean; hostRole: string | null | undefined },\n): boolean {\n const stamped = (host?.memberPermissions as Record<string, Record<string, unknown> | undefined> | undefined)?.[uid]?.[\n permission\n ]\n if (typeof stamped === 'boolean') return stamped\n if (membership.orgWide !== true) return false\n const fresh = membership.hostRole\n return (\n typeof fresh === 'string' &&\n presetFor[fresh as HostAccessRole] === true &&\n hostStampedSitePermission({ memberRoles: host?.memberRoles }, uid, permission, presetFor)\n )\n}\n\n/*\n * A SITE NARROWS A WORKSPACE-WIDE MEMBER (AGL-4047).\n *\n * An editor who works across the workspace can be given Viewer or Author\n * access to one site (`hostAccess[hostId]`, which `hostRoleFor` reads ahead\n * of `allHosts`). That narrowed their content rights there and nothing else,\n * so a key the workspace grants an editor, such as working a site's\n * register, still held on the site they were narrowed on.\n *\n * A plugin marks the keys a site CAN narrow with `narrowsPerSite`, and\n * whether each one does is a control with three layers, the nearest set one\n * winning (`siteNarrowingChoices`):\n *\n * - the member's own choice (`member.siteNarrowing[key]`);\n * - else their custom role's (`customRole.siteNarrowing[key]`);\n * - else the built-in role's default the declaration names.\n *\n * `true` is \"Follow the site role\", `false` is \"Keep this permission\". On a\n * site that narrows the member, each key that follows the site role is\n * decided for that site:\n *\n * 1. the site's own verdict for the key (`hostPermissions[hostId][key]`),\n * when the site set one;\n * 2. else, for a key that refines another key that also follows the site\n * role, that key's verdict on this site, never more than the workspace\n * grants;\n * 3. else the narrower access's default for the key, never more than the\n * workspace grants;\n *\n * and a key they keep is the workspace's verdict, as everywhere else. A finer\n * key they hold on the site (one the site grants, or one they keep and the\n * workspace grants) brings the key it refines on this site with it, unless\n * the site refuses that key, because a refining key is never held without\n * it. The other finer keys do not follow that implied grant: allowing \"sell\"\n * on a site is not allowing refunds.\n *\n * A member whose access to every site matches their workspace role (the\n * owner and admins always do), one who keeps every key a site can narrow,\n * and a site collaborator, whose keys come from their site role already, all\n * resolve exactly as before.\n */\n\n/** Host roles from the widest down, for \"is this site's access narrower?\". */\nconst HOST_ROLE_RANK: Readonly<Record<HostAccessRole, number>> = {\n admin: 3,\n editor: 2,\n author: 1,\n viewer: 0,\n}\n\n/** How one site narrows a workspace-wide member: the access they hold there, the site's verdicts, and which keys follow it. */\nexport interface SiteNarrowing {\n /** Their role on the site, narrower than their workspace role. */\n role: HostAccessRole\n /** `hostPermissions[hostId]`: the verdicts the site set for them. */\n grants: Readonly<Partial<Record<string, unknown>>>\n /**\n * Every key a site can narrow, `true` where it follows the site role for\n * this member and `false` where they keep it (`siteNarrowingChoices`).\n */\n narrows: Readonly<Record<string, boolean>>\n}\n\n/** The catalog keys a site CAN narrow (`narrowsPerSite`), in catalog order. */\nexport function siteNarrowedPermissionKeys(): string[] {\n return ORG_PERMISSIONS.filter((definition) => definition.narrowsPerSite).map(\n (definition) => definition.key,\n )\n}\n\n/**\n * Could any site narrow a member of this org role? Not the owner or an\n * admin, who are admins of every site, and not a role whose site access has\n * nothing narrower below it (a viewer). The editors' control is the one that\n * changes anything; the role editor says so beside it.\n */\nexport function roleCanBeNarrowed(role: string | null | undefined): boolean {\n if (role === 'owner' || role === 'admin') return false\n return HOST_ROLE_RANK[orgRoleTier(role) as HostAccessRole] > 0\n}\n\n/**\n * Whether each key a site can narrow follows the site role for this member\n * (`true`) or is kept (`false`): their own choice, else their custom role's\n * (when they carry its id and it was supplied), else the built-in role's\n * default.\n */\nexport function siteNarrowingChoices(\n member: (Partial<AglynOrgMember> & { roleId?: string | null }) | null | undefined,\n customRole?: Pick<AglynOrgCustomRole, 'siteNarrowing'> | null,\n): Record<string, boolean> {\n const role = (member?.role ?? 'viewer') as OrgRole\n const own = member?.siteNarrowing ?? {}\n const fromRole = member?.roleId ? (customRole?.siteNarrowing ?? {}) : {}\n const out: Record<string, boolean> = {}\n for (const definition of ORG_PERMISSIONS) {\n if (!definition.narrowsPerSite) continue\n const key = definition.key\n const mine = own[key]\n const theirRole = fromRole[key]\n out[key] =\n typeof mine === 'boolean'\n ? mine\n : typeof theirRole === 'boolean'\n ? theirRole\n : definition.narrowsPerSite[role] === true\n }\n return out\n}\n\n/**\n * Is this member's access to this site narrower than their workspace role?\n * The cheap half of `siteNarrowingFor`, which needs no custom role: a caller\n * that has to read one asks this first, and reads nothing for everyone else.\n */\nexport function siteMayNarrow(\n member: Partial<AglynOrgMember> | null | undefined,\n hostId: HostUid | null | undefined,\n): HostAccessRole | null {\n if (!member || !hostId || !isOrgWideMember(member)) return null\n const role = hostRoleFor(member, hostId)\n if (!role) return null\n const workspaceRole = orgRoleTier(member.role) as HostAccessRole\n if (HOST_ROLE_RANK[role] >= HOST_ROLE_RANK[workspaceRole]) return null\n return role\n}\n\n/**\n * How this site narrows this member, or null where it does not: a member\n * who is not workspace-wide, has no access to the site, whose access there\n * is as wide as their workspace role (owners and admins always), or who\n * keeps every key a site can narrow. `customRole` is their custom role\n * document when they carry a `roleId`; without it, only their own choices\n * and the built-in defaults decide.\n */\nexport function siteNarrowingFor(\n member: Partial<AglynOrgMember> | null | undefined,\n hostId: HostUid | null | undefined,\n customRole?: Pick<AglynOrgCustomRole, 'siteNarrowing'> | null,\n): SiteNarrowing | null {\n const role = siteMayNarrow(member, hostId)\n if (!role) return null\n const narrows = siteNarrowingChoices(member, customRole)\n if (!Object.values(narrows).some(Boolean)) return null\n return { role, grants: member?.hostPermissions?.[hostId as HostUid] ?? {}, narrows }\n}\n\n/** The keys that follow the site role under a narrowing, in catalog order; none without one. */\nexport function narrowedPermissionKeysOf(narrowing: SiteNarrowing | null | undefined): string[] {\n if (!narrowing) return []\n return siteNarrowedPermissionKeys().filter((key) => narrowing.narrows[key] === true)\n}\n\n/** What a site access holds by default for a key: its site default, else its tier's (Author on the Viewer tier). */\nfunction narrowedDefault(definition: OrgPermissionDefinition, role: HostAccessRole): boolean {\n const site = definition.hostRoleDefaults?.[role]\n if (typeof site === 'boolean') return site\n return definition.roleDefaults[orgRoleTier(role)] === true\n}\n\n/**\n * A workspace-wide member's resolved map with the keys that follow the site\n * role decided for that site (see above). With no narrowing it is the map\n * as given, so every resolver can call it unconditionally.\n */\nexport function narrowPermissionsToSite<T extends Record<string, boolean>>(\n granted: T,\n narrowing: SiteNarrowing | null | undefined,\n): T {\n if (!narrowing) return granted\n const definitions = ORG_PERMISSIONS.filter((definition) => definition.narrowsPerSite)\n if (!definitions.length) return granted\n const narrowable = new Set(definitions.map((definition) => definition.key))\n const follows = (key: string): boolean => narrowing.narrows[key] === true\n // A finer key's broader key, among the keys a site can narrow.\n const broader = new Map<string, string>()\n for (const [key, parent, kind] of ORG_PERMISSION_REFINEMENTS) {\n if (kind !== 'follows' && narrowable.has(key) && narrowable.has(parent)) broader.set(key, parent)\n }\n const siteVerdict = (key: string): boolean | undefined => {\n const value = narrowing.grants[key]\n return typeof value === 'boolean' ? value : undefined\n }\n const depth = (key: string): number => {\n const seen = new Set<string>()\n let steps = 0\n for (let current = key; broader.has(current) && !seen.has(current); steps += 1) {\n seen.add(current)\n current = broader.get(current) as string\n }\n return steps\n }\n const out: Record<string, boolean> = { ...granted }\n for (const definition of [...definitions].sort((a, b) => depth(a.key) - depth(b.key))) {\n const key = definition.key\n const workspace = granted[key] === true\n // Kept: the workspace's verdict, as on every other site.\n if (!follows(key)) {\n out[key] = workspace\n continue\n }\n const own = siteVerdict(key)\n const parent = broader.get(key)\n if (own !== undefined) out[key] = own\n else if (parent && follows(parent)) out[key] = out[parent] === true && workspace\n else out[key] = workspace && narrowedDefault(definition, narrowing.role)\n }\n for (const definition of definitions) {\n const key = definition.key\n const held = follows(key) ? siteVerdict(key) === true : granted[key] === true\n if (!held) continue\n const seen = new Set<string>()\n for (let parent = broader.get(key); parent && !seen.has(parent); parent = broader.get(parent)) {\n seen.add(parent)\n // A kept broader key is the workspace's verdict already.\n if (!follows(parent) || siteVerdict(parent) === false) break\n out[parent] = true\n }\n }\n return refinePermissionMap(out, ORG_PERMISSION_REFINEMENTS) as T\n}\n\n/**\n * A member's verdict for every per-site key, on whichever axis their\n * membership is on.\n *\n * `customRole` is the member's custom role document when they carry a\n * `roleId` and the caller has it in hand, and is ignored for a collaborator,\n * whose org role is a seat-accounting fact rather than a grant. `hostId` is\n * the site the request is about; an org-wide member resolves the same on\n * every site and with none named, except on a site that narrows them.\n *\n * An org-wide member's map also carries every key a site can narrow\n * (AGL-4047), decided for `hostId`, so the site's `memberPermissions`\n * projection answers the rules what the server answers. A collaborator's\n * map does not: their register and waivers keys come from their site role\n * and their own overrides, which the rules read from their member document\n * as before.\n */\nexport function resolveMemberHostPermissions(options: {\n member: Partial<AglynOrgMember> | null | undefined\n customRole?: AglynOrgCustomRole | null\n hostId?: HostUid | null\n}): Record<HostPermissionKey, boolean> {\n const { member, customRole, hostId } = options\n if (!member) return noHostPermissions()\n if (isOrgWideMember(member)) {\n // The keys whose preset is the site role (AGL-4047) are decided for this\n // site last; they narrow nothing, so the narrowing pass leaves them be.\n const granted = applySiteRolePresets(\n narrowPermissionsToSite(\n resolveOrgPermissions(member, customRole ?? null),\n siteNarrowingFor(member, hostId, customRole ?? null),\n ),\n member,\n hostId,\n customRole ?? null,\n )\n return Object.fromEntries(\n [...hostPermissionKeys(), ...siteNarrowedPermissionKeys()].map((key) => [key, granted[key] === true]),\n )\n }\n return resolveCollaboratorHostPermissions(member, hostId) ?? noHostPermissions()\n}\n\n/**\n * The `memberPermissions` projection stamped on a host document beside\n * `memberRoles`: every member who can reach the site, with the verdict for\n * every per-site key they hold ON it. Org-wide members are resolved against\n * the custom roles the caller loaded (one read per distinct role, as\n * `syncOrgAuthProjections` already does for `resolvedPermissions`);\n * collaborators against their host role. A member who cannot reach the site\n * has no entry, matching `projectHostMemberRoles`.\n */\nexport function projectHostMemberPermissions(\n members: ReadonlyArray<Partial<AglynOrgMember> & { $id: string }>,\n hostId: HostUid,\n customRoles: ReadonlyMap<string, AglynOrgCustomRole | null>,\n): Record<string, Record<HostPermissionKey, boolean>> {\n const projection: Record<string, Record<HostPermissionKey, boolean>> = {}\n for (const member of members) {\n if (!hostRoleFor(member, hostId)) continue\n projection[member.$id] = resolveMemberHostPermissions({\n member,\n customRole: member.roleId ? (customRoles.get(member.roleId) ?? null) : null,\n hostId,\n })\n }\n return projection\n}\n\n/** The core's site keys (AGL-4047): `CORE_SITE_ROLE_PRESETS`. */\nexport type CoreSiteKey = 'site.edit' | 'site.publish' | 'site.sensitive' | 'site.manage'\n\n/** A host document, as a snapshot (`get`) or as its data. */\nexport type HostDocumentLike =\n | { get(field: string): unknown }\n | { memberPermissions?: unknown; memberRoles?: unknown }\n | null\n | undefined\n\n/**\n * Does this member hold one of the core's site keys on this site (AGL-4047)?\n * The door's twin of the rules' `canWriteHostContent`,\n * `canPublishHostContent`, `canReadHostSensitive` and site-settings checks:\n * the site's `memberPermissions` stamp, else the preset of the member's\n * `memberRoles` entry (`hostStampedSitePermission`), so a route that asks it\n * answers what the rules answer for the same write. For the routes that read\n * the host document already; it costs no read.\n */\nexport function holdsSiteKey(hostDoc: HostDocumentLike, uid: string, key: CoreSiteKey): boolean {\n return holdsStampedSiteKey(hostDoc, uid, key, CORE_SITE_ROLE_PRESETS[key] ?? {})\n}\n\n/**\n * The same for a plugin's key whose preset is the site role (AGL-4047): the\n * site's `memberPermissions` stamp, else `presetFor` read for the member's\n * `memberRoles` entry. `presetFor` is the declaring plugin's own table, so the\n * answer does not depend on which plugins this process loaded. For the doors\n * and the cards that hold the host document already; it costs no read.\n */\nexport function holdsStampedSiteKey(\n hostDoc: HostDocumentLike,\n uid: string | null | undefined,\n key: string,\n presetFor: Readonly<Partial<Record<HostAccessRole, boolean>>>,\n): boolean {\n if (!hostDoc || !uid) return false\n // `hostDoc`, not `host`: the host-field deny guard reads every `host.…`\n // in this folder as a field of the host document, and `get` is none.\n const read = (field: string): unknown =>\n typeof (hostDoc as { get?: unknown }).get === 'function'\n ? (hostDoc as { get(field: string): unknown }).get(field)\n : (hostDoc as Record<string, unknown>)[field]\n return hostStampedSitePermission(\n { memberPermissions: read('memberPermissions'), memberRoles: read('memberRoles') },\n uid,\n key,\n presetFor,\n )\n}\n\n/**\n * The refusal a door answers when a member does not hold a site key\n * (AGL-4047): it names the permission and who can change it, never a role.\n */\nexport function siteKeyRefusal(key: string): string {\n return permissionRefusalText(key)\n}\n\n"],"names":["refinePermissionMap","hostRoleFor","isOrgWideMember","CORE_SITE_ROLE_PRESETS","permissionRefusalText","ORG_PERMISSION_REFINEMENTS","ORG_PERMISSIONS","resolveOrgPermissions","orgRoleTier","hostPermissionKeys","filter","definition","hostRoleDefaults","undefined","map","key","hostRolePermissionDefaults","role","defaults","workspaceMembersOnly","noHostPermissions","Object","fromEntries","refinementsWithin","parent","resolveCollaboratorHostPermissions","member","hostId","merged","toggles","hostPermissions","keys","value","siteRolePresetPermissionKeys","presetFromSiteRole","isSiteRolePresetPermission","permission","some","resolveSiteRolePresetPermissions","customRole","definitions","length","workspaceMember","layers","roleId","permissions","out","verdict","layer","applySiteRolePresets","granted","hostStampedSitePermission","host","uid","presetFor","stamped","memberPermissions","memberRoles","hostStampedWorkspaceSitePermission","membership","orgWide","fresh","hostRole","HOST_ROLE_RANK","admin","editor","author","viewer","siteNarrowedPermissionKeys","narrowsPerSite","roleCanBeNarrowed","siteNarrowingChoices","own","siteNarrowing","fromRole","mine","theirRole","siteMayNarrow","workspaceRole","siteNarrowingFor","narrows","values","Boolean","grants","narrowedPermissionKeysOf","narrowing","narrowedDefault","site","roleDefaults","narrowPermissionsToSite","narrowable","Set","follows","broader","Map","kind","has","set","siteVerdict","depth","seen","steps","current","add","get","sort","a","b","workspace","held","resolveMemberHostPermissions","options","projectHostMemberPermissions","members","customRoles","projection","$id","holdsSiteKey","hostDoc","holdsStampedSiteKey","read","field","siteKeyRefusal"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AASD,SAASA,mBAAmB,QAAmC,0CAAsC;AACrG,SAASC,WAAW,EAAEC,eAAe,QAAQ,qBAAiB;AAC9D,SAASC,sBAAsB,QAAQ,uBAAmB;AAC1D,SACEC,qBAAqB,EACrBC,0BAA0B,EAC1BC,eAAe,EACfC,qBAAqB,QAGhB,uBAAmB;AAC1B,SAASC,WAAW,QAAQ,iBAAa;AAEzC;;;;;;;;;;;;;;;;;;;CAmBC,GAED;;;;CAIC,GACD,OAAO,SAASC;IACd,OAAOH,gBAAgBI,MAAM,CAAC,CAACC,aAAeA,WAAWC,gBAAgB,KAAKC,WAAWC,GAAG,CAC1F,CAACH,aAAeA,WAAWI,GAAG;AAElC;AAEA;;;;;CAKC,GACD,OAAO,SAASC,2BACdC,IAAoB;IAEpB,MAAMC,WAA+C,CAAC;IACtD,KAAK,MAAMP,cAAcL,gBAAiB;QACxC,IAAI,CAACK,WAAWC,gBAAgB,EAAE;QAClCM,QAAQ,CAACP,WAAWI,GAAG,CAAC,GAAG,CAACJ,WAAWQ,oBAAoB,IAAIR,WAAWC,gBAAgB,CAACK,KAAK,KAAK;IACvG;IACA,OAAOC;AACT;AAEA,iCAAiC,GACjC,SAASE;IACP,OAAOC,OAAOC,WAAW,CAACb,qBAAqBK,GAAG,CAAC,CAACC,MAAQ;YAACA;YAAK;SAAM;AAC1E;AAEA;;;;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AI,CAACjH,YAAYyB,QAAQC,SAAS;QAClCwF,UAAU,CAACzF,OAAO0F,GAAG,CAAC,GAAGN,6BAA6B;YACpDpF;YACAa,YAAYb,OAAOkB,MAAM,IAAIsE,mBAAAA,YAAYV,GAAG,CAAC9E,OAAOkB,MAAM,aAA7BsE,mBAAkC,OAAQ;YACvEvF;QACF;IACF;IACA,OAAOwF;AACT;AAYA;;;;;;;;CAQC,GACD,OAAO,SAASE,aAAaC,OAAyB,EAAEjE,GAAW,EAAEtC,GAAgB;QACrCZ;IAA9C,OAAOoH,oBAAoBD,SAASjE,KAAKtC,MAAKZ,8BAAAA,sBAAsB,CAACY,IAAI,YAA3BZ,8BAA+B,CAAC;AAChF;AAEA;;;;;;CAMC,GACD,OAAO,SAASoH,oBACdD,OAAyB,EACzBjE,GAA8B,EAC9BtC,GAAW,EACXuC,SAA6D;IAE7D,IAAI,CAACgE,WAAW,CAACjE,KAAK,OAAO;IAC7B,wEAAwE;IACxE,qEAAqE;IACrE,MAAMmE,OAAO,CAACC,QACZ,OAAO,AAACH,QAA8Bd,GAAG,KAAK,aAC1C,AAACc,QAA4Cd,GAAG,CAACiB,SACjD,AAACH,OAAmC,CAACG,MAAM;IACjD,OAAOtE,0BACL;QAAEK,mBAAmBgE,KAAK;QAAsB/D,aAAa+D,KAAK;IAAe,GACjFnE,KACAtC,KACAuC;AAEJ;AAEA;;;CAGC,GACD,OAAO,SAASoE,eAAe3G,GAAW;IACxC,OAAOX,sBAAsBW;AAC/B"}
|
|
@@ -94,6 +94,14 @@ export interface OrgPermissionDefinition {
|
|
|
94
94
|
* (`CORE_SITE_ROLE_PRESETS`) and a plugin's key with `hostRoleDefaults`.
|
|
95
95
|
*/
|
|
96
96
|
presetFromSiteRole?: true;
|
|
97
|
+
/**
|
|
98
|
+
* With `presetFromSiteRole`: the site role is the preset only for a member
|
|
99
|
+
* of the whole workspace (AGL-4047). A site collaborator's preset is
|
|
100
|
+
* refusal, whatever their site role, and only the site's toggle grants it
|
|
101
|
+
* to them. A plugin's key that replaces a gate asking for an admin of the
|
|
102
|
+
* whole workspace who is also the site's admin.
|
|
103
|
+
*/
|
|
104
|
+
workspaceMembersOnly?: true;
|
|
97
105
|
}
|
|
98
106
|
/**
|
|
99
107
|
* Every permission, in display order for role editors: the core keys, then
|
|
@@ -158,6 +158,8 @@ function replaceEntries(target, entries) {
|
|
|
158
158
|
narrowsPerSite: _extends({}, declared.narrowsPerSite)
|
|
159
159
|
} : {}, declared.presetFromSiteRole && declared.hostRoleDefaults ? {
|
|
160
160
|
presetFromSiteRole: true
|
|
161
|
+
} : {}, declared.presetFromSiteRole && declared.hostRoleDefaults && declared.workspaceMembersOnly ? {
|
|
162
|
+
workspaceMembersOnly: true
|
|
161
163
|
} : {}));
|
|
162
164
|
if (declared.source === 'tier') tierKeys.push(declared.key);
|
|
163
165
|
if (!groups.some((group)=>group.id === declared.group)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/org-permissions.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AglynOrgMember, OrgRole } from '../foundation'\nimport {\n listPluginCatalogPermissions,\n subscribePluginEntitlements,\n} from '../plugin-manager/plugin-entitlements'\nimport {\n permissionRefinementOf,\n refinePermissionMap,\n subscribePluginPermissions,\n type PermissionRefinement,\n} from '../plugin-manager/plugin-permissions'\nimport { ORG_ROLE_PERMISSION_KEYS } from './org-roles'\nimport {\n CORE_ORG_PERMISSION_ENTRIES,\n CORE_ORG_PERMISSION_GROUPS,\n CORE_ORG_ROLE_GRANTS,\n CORE_SITE_ROLE_PRESETS,\n type OrgPermissionGroup,\n type OrgPermissionScope,\n} from './org-role-grants'\n\nexport type { OrgPermissionGroup, OrgPermissionScope }\n\n/**\n * Granular org permissions (AGL-243) layered on the 4 org roles: each\n * role maps to a default permission set; custom roles\n * (`orgs/{orgId}/roles/{roleId}`) and per-member overrides refine it, so\n * e.g. an editor restricted to one host can also be granted billing\n * visibility — or an admin stripped of it — without inventing new roles.\n * The console hides unpermitted surfaces; the org API routes are the\n * enforcement point.\n */\nexport type CoreOrgPermission =\n | 'org.settings'\n | 'org.auditLog'\n | 'org.apiKeys'\n | 'org.privacy'\n | 'org.holds'\n | 'org.export'\n | 'org.sendingDomains'\n | 'org.businessProfile'\n | 'org.media'\n | 'org.eraseRecords'\n | 'billing.view'\n | 'billing.manage'\n | 'members.manage'\n | 'hosts.create'\n | 'hosts.delete'\n | 'data.manage'\n | 'marketplace.publish'\n | 'plugins.install'\n | 'site.edit'\n | 'site.publish'\n | 'site.sensitive'\n | 'site.manage'\n\n/**\n * A key of the catalog: a core key above, or a key a plugin declares into\n * the catalog through `registerPluginEntitlements` (AGL-2984). A declared key\n * is stored on custom roles and member overrides, layered and resolved\n * exactly like a core key.\n */\nexport type OrgPermission = CoreOrgPermission | (string & {})\n\n/**\n * Legacy boolean permission map derived from the granular `OrgPermission`\n * set (AGL-243). Kept for the console surfaces that predate the granular\n * model; lives here so relocated feature plugins can accept it as a prop\n * (AGL-395).\n */\nexport interface OrgPermissions {\n createHosts: boolean\n editHosts: boolean\n editBilling: boolean\n publishToMarketplace: boolean\n installPlugins: boolean\n manageMembers: boolean\n}\n\nexport interface OrgPermissionDefinition {\n key: OrgPermission\n label: string\n description: string\n /** The plugin that declared the key; absent for a core key. */\n pluginId?: string\n /** The `ORG_PERMISSION_GROUPS` id the role editor files it under (AGL-4047). */\n group: string\n /** Where it is decided: `org`, or `site` for a key a site collaborator holds per site. */\n scope: OrgPermissionScope\n /** Each org role's verdict when nothing refines it (`DEFAULT_ROLE_PERMISSIONS`). */\n roleDefaults: Readonly<Record<OrgRole, boolean>>\n /** Each host role's verdict, for a `site` key. */\n hostRoleDefaults?: Readonly<Record<string, boolean>>\n /**\n * The broader key this one is a finer part of (AGL-4047): never granted\n * without it, and following it where no custom role or override sets this\n * key. Only a plugin's key refines, and only a key the catalog holds.\n */\n refines?: OrgPermission\n /**\n * The key this one follows where no custom role or override sets it,\n * without needing it (AGL-4047): granted on its own, it holds while that\n * key is refused. Only a plugin's key follows, and only a key the catalog\n * holds; a key that refines does not also follow.\n */\n follows?: OrgPermission\n /**\n * Present when a site can narrow the key (AGL-4047): where a member who\n * works across the workspace has narrower access to one site than their\n * workspace role, whether the key follows that site role there is a\n * control, set per key on a custom role (`siteNarrowing`) and per member\n * (`AglynOrgMember.siteNarrowing`), and this is each built-in role's\n * default for it. `narrowPermissionsToSite` applies it. Only a plugin's key.\n */\n narrowsPerSite?: Readonly<Record<OrgRole, boolean>>\n /**\n * The key's preset is the member's role ON THE SITE a request names, for\n * every member (AGL-4047): `hostRoleDefaults` read for the access they hold\n * there, then their custom role, their own permissions and that site's\n * toggle. `roleDefaults` is the answer with no site named.\n * `resolveSiteRolePresetPermissions` decides it. The core's site keys\n * (`CORE_SITE_ROLE_PRESETS`) and a plugin's key with `hostRoleDefaults`.\n */\n presetFromSiteRole?: true\n}\n\n/**\n * The core keys, in display order for role editors.\n *\n * ⚠️ **EVERY KEY HERE MUST BE ENFORCED SERVER-SIDE.** A permission a customer\n * can tick that changes nothing is worse than its absence, because it implies\n * a control that does not exist — an owner unticks \"delete sites\", hands the\n * role out, and the member deletes sites while the console does not even dim\n * the button. Three of the eleven were in exactly that state (AGL-2444).\n *\n * `marketing.manage` was removed rather than wired, and the reason is worth\n * keeping: announcement bars, popups and campaigns live at\n * `hosts/{hostId}/overlays|campaigns|experiments` and are written\n * client-direct against the security rules, which gate on the HOST role.\n * There is no org-level boundary for it to sit on, and the action it named is\n * not org-scoped at all. Wiring it would have meant inventing one and\n * producing a second permission that looks enforced and is not. If a granular\n * marketing permission is wanted it belongs in the plugin-declared mechanism\n * (AGL-435), scoped to a host — a product decision, not this repair.\n *\n * `apps/console/specs/org-permissions-are-enforced.spec.ts` fails the build if\n * a key here, or a key a plugin declares, gains no server-side consumer.\n */\nconst CORE_ORG_PERMISSIONS: readonly OrgPermissionDefinition[] =\n // One table, shared with the native apps through the contracts (AGL-3950).\n CORE_ORG_PERMISSION_ENTRIES.map((entry) => ({\n ...entry,\n key: entry.key as CoreOrgPermission,\n group: entry.group ?? 'organization',\n scope: entry.scope ?? 'org',\n // A site key's preset is the member's role on the site (AGL-4047).\n ...(CORE_SITE_ROLE_PRESETS[entry.key]\n ? { hostRoleDefaults: { ...CORE_SITE_ROLE_PRESETS[entry.key] }, presetFromSiteRole: true as const }\n : {}),\n roleDefaults: {\n owner: CORE_ORG_ROLE_GRANTS.owner.includes(entry.key),\n admin: CORE_ORG_ROLE_GRANTS.admin.includes(entry.key),\n editor: CORE_ORG_ROLE_GRANTS.editor.includes(entry.key),\n viewer: CORE_ORG_ROLE_GRANTS.viewer.includes(entry.key),\n },\n }))\n\n/** The core keys: a plugin may add keys beside them and never redefine one. */\nconst CORE_ORG_PERMISSION_KEYS: ReadonlySet<string> = new Set(\n CORE_ORG_PERMISSIONS.map((definition) => definition.key),\n)\n\n/** The legacy camelCase projection's keys, which no declaration may take either. */\nconst LEGACY_PERMISSION_KEYS: ReadonlySet<string> = new Set<string>(\n ORG_ROLE_PERMISSION_KEYS,\n)\n\n/** The org roles, in the order `DEFAULT_ROLE_PERMISSIONS` lists them. */\nconst ORG_ROLES: readonly OrgRole[] = ['owner', 'admin', 'editor', 'viewer']\n\n/**\n * Every permission, in display order for role editors: the core keys, then\n * the keys plugins declare through `registerPluginEntitlements`, in the\n * plugins' catalog order (AGL-2984).\n *\n * LIVE, and kept in step in place. A plugin's declarations register at\n * module scope — at boot on the server, before the first paint in the\n * console — which can be after a module holding this binding was evaluated.\n * So this array, the key list, the role defaults and the empty map below are\n * rewritten in place on every registration instead of being computed once\n * when this module loads, and whoever holds the binding reads the declared\n * keys with the core ones.\n */\nexport const ORG_PERMISSIONS: readonly OrgPermissionDefinition[] = []\n\nexport const ORG_PERMISSION_KEYS: readonly OrgPermission[] = []\n\n/**\n * The groups the catalog's keys are filed under, in display order (AGL-4047):\n * the core groups, then one per plugin group a declaration names. Live, like\n * `ORG_PERMISSIONS`; a group with no key is left out.\n */\nexport const ORG_PERMISSION_GROUPS: readonly OrgPermissionGroup[] = []\n\n/**\n * The catalog keys that came through `registerPluginPermissions` (AGL-4047):\n * the keys the per-tier resolver (`resolveRolePermissions`) also answers,\n * which a caller holding a catalog-resolved map lays over that resolver's\n * answer so a custom role reaches them. Live.\n */\nexport const TIER_PERMISSION_KEYS: readonly OrgPermission[] = []\n\n/**\n * Every catalog key that refines a broader one, with that key (AGL-4047),\n * and every key that only follows one, marked `'follows'`. Live, like\n * `ORG_PERMISSIONS`. A resolver lays it over its map with\n * `refinePermissionMap`.\n */\nexport const ORG_PERMISSION_REFINEMENTS: readonly PermissionRefinement[] = []\n\nconst NO_PERMISSIONS = {} as Record<OrgPermission, boolean>\n\n/**\n * Role → default permission set. Owner/admin hold everything (owner-only\n * actions like org deletion stay role-checked, not permission-checked);\n * editors work on content but see no money or roster controls; viewers read\n * only. A declared key's default for each role is the one its declaration\n * names.\n */\nexport const DEFAULT_ROLE_PERMISSIONS: Record<\n OrgRole,\n Record<OrgPermission, boolean>\n> = {\n owner: {} as Record<OrgPermission, boolean>,\n admin: {} as Record<OrgPermission, boolean>,\n editor: {} as Record<OrgPermission, boolean>,\n viewer: {} as Record<OrgPermission, boolean>,\n}\n\n/** Refused declarations already logged, so a refusal is reported once. */\nconst reportedRefusals = new Set<string>()\n\nfunction replaceItems<T>(target: readonly T[], items: readonly T[]): void {\n const list = target as T[]\n list.length = 0\n list.push(...items)\n}\n\nfunction replaceEntries(\n target: Record<string, boolean>,\n entries: Record<string, boolean>,\n): void {\n for (const key of Object.keys(target)) delete target[key]\n Object.assign(target, entries)\n}\n\n/**\n * Rebuilds the live catalog: the core keys, then every key a plugin declared\n * through either declaration API (`listPluginCatalogPermissions`, AGL-4047).\n * A declaration naming a core or legacy key is refused — that key keeps its\n * own meaning and defaults — and logged once.\n */\nfunction syncCatalog(): void {\n const definitions: OrgPermissionDefinition[] = [...CORE_ORG_PERMISSIONS]\n const tierKeys: string[] = []\n const groups: OrgPermissionGroup[] = CORE_ORG_PERMISSION_GROUPS.map((group) => ({ ...group }))\n for (const declared of listPluginCatalogPermissions()) {\n if (\n CORE_ORG_PERMISSION_KEYS.has(declared.key) ||\n LEGACY_PERMISSION_KEYS.has(declared.key)\n ) {\n const refusal = `${declared.pluginId}\\x00${declared.key}`\n if (!reportedRefusals.has(refusal)) {\n reportedRefusals.add(refusal)\n console.error(\n `[plugins] refused catalog permission \"${declared.key}\" to ` +\n `\"${declared.pluginId}\": the key belongs to the core catalog`,\n )\n }\n continue\n }\n definitions.push({\n key: declared.key,\n label: declared.label,\n description: declared.description,\n pluginId: declared.pluginId,\n group: declared.group,\n scope: declared.hostRoleDefaults ? 'site' : 'org',\n roleDefaults: declared.roleDefaults,\n ...(declared.hostRoleDefaults ? { hostRoleDefaults: declared.hostRoleDefaults } : {}),\n ...(declared.refines ? { refines: declared.refines } : {}),\n ...(declared.follows && !declared.refines ? { follows: declared.follows } : {}),\n ...(declared.narrowsPerSite ? { narrowsPerSite: { ...declared.narrowsPerSite } } : {}),\n ...(declared.presetFromSiteRole && declared.hostRoleDefaults ? { presetFromSiteRole: true as const } : {}),\n })\n if (declared.source === 'tier') tierKeys.push(declared.key)\n if (!groups.some((group) => group.id === declared.group)) {\n groups.push({ id: declared.group, label: declared.groupLabel, pluginId: declared.pluginId })\n }\n }\n const keys = definitions.map((definition) => definition.key)\n const known = new Set<string>(keys)\n // A refinement of a key the catalog does not hold refines nothing, and is\n // dropped from the definition so no editor offers a link to nowhere.\n for (const definition of definitions) {\n if (definition.refines && (!known.has(definition.refines) || definition.refines === definition.key)) {\n delete definition.refines\n }\n if (definition.follows && (!known.has(definition.follows) || definition.follows === definition.key)) {\n delete definition.follows\n }\n }\n replaceItems(\n ORG_PERMISSION_REFINEMENTS,\n definitions.flatMap((definition) => {\n const refinement = permissionRefinementOf(definition)\n return refinement ? [refinement] : []\n }),\n )\n replaceItems(ORG_PERMISSIONS, definitions)\n replaceItems(ORG_PERMISSION_KEYS, keys)\n replaceItems(\n ORG_PERMISSION_GROUPS,\n groups.filter((group) => definitions.some((definition) => definition.group === group.id)),\n )\n replaceItems(TIER_PERMISSION_KEYS, tierKeys)\n replaceEntries(NO_PERMISSIONS, Object.fromEntries(keys.map((key) => [key, false])))\n for (const role of ORG_ROLES) {\n replaceEntries(\n DEFAULT_ROLE_PERMISSIONS[role],\n Object.fromEntries(\n definitions.map((definition) => [definition.key, definition.roleDefaults[role] === true]),\n ),\n )\n }\n CATALOG_AND_LEGACY_KEYS.clear()\n for (const key of [...keys, ...LEGACY_PERMISSION_KEYS]) {\n CATALOG_AND_LEGACY_KEYS.add(key)\n }\n}\n\n/**\n * The `registerPluginPermissions` keys of a catalog-resolved map (AGL-4047).\n *\n * Those keys are answered twice: by the per-tier resolver\n * (`resolveRolePermissions`, the role's tier default and the member's\n * override) and, now that they are catalog keys, by `resolveOrgPermissions`\n * with every layer — the custom role's included. A caller that builds its\n * map from the first spreads this over it, so the custom role a member\n * carries reaches `managePos` the way it reaches `hosts.create`.\n */\nexport function tierPermissionsOf(\n granted: Readonly<Record<string, boolean>> | null | undefined,\n): Record<string, boolean> {\n const picked: Record<string, boolean> = {}\n if (!granted) return picked\n for (const key of TIER_PERMISSION_KEYS) {\n if (typeof granted[key] === 'boolean') picked[key] = granted[key]\n }\n return picked\n}\n\n/** One catalog key by name, or undefined. */\nexport function orgPermissionDefinition(\n permission: OrgPermission,\n): OrgPermissionDefinition | undefined {\n return ORG_PERMISSIONS.find((definition) => definition.key === permission)\n}\n\n/** `orgs/{orgId}/roles/{roleId}` — a named custom permission set. */\nexport interface AglynOrgCustomRole {\n $id?: string\n name?: string\n description?: string\n /** Full permission map; missing keys read as false. */\n permissions?: Partial<Record<OrgPermission, boolean>>\n /**\n * Per key a site can narrow (AGL-4047): `true` follows the site role on a\n * site where the member's access is narrower than their workspace role,\n * `false` keeps the permission there. A key it leaves out follows the\n * built-in role's default (`OrgPermissionDefinition.narrowsPerSite`), and\n * a member's own `siteNarrowing` wins over it.\n */\n siteNarrowing?: Partial<Record<OrgPermission, boolean>>\n}\n\n/**\n * Effective permission map for a member: the org role's defaults, then\n * the custom role's map (when the member has `roleId` and the role doc\n * is supplied), then per-member overrides — later layers win key-by-key.\n */\nexport function resolveOrgPermissions(\n member:\n | (Partial<AglynOrgMember> & {\n roleId?: string\n permissions?: Partial<Record<OrgPermission, boolean>>\n })\n | null\n | undefined,\n customRole?: AglynOrgCustomRole | null,\n): Record<OrgPermission, boolean> {\n if (!member) return NO_PERMISSIONS\n const role = (member.role ?? 'viewer') as OrgRole\n const base = DEFAULT_ROLE_PERMISSIONS[role] ?? NO_PERMISSIONS\n const merged: Record<OrgPermission, boolean> = { ...base }\n if (member.roleId && customRole?.permissions) {\n for (const key of ORG_PERMISSION_KEYS) {\n const value = customRole.permissions[key]\n if (typeof value === 'boolean') merged[key] = value\n }\n }\n if (member.permissions) {\n for (const key of ORG_PERMISSION_KEYS) {\n const value = member.permissions[key]\n if (typeof value === 'boolean') merged[key] = value\n }\n }\n // A key that refines a broader one (AGL-4047) follows it where neither\n // layer set the key, and is never held without it; a key that only follows\n // one takes its verdict where neither layer set the key, and nothing more.\n return refinePermissionMap(merged, ORG_PERMISSION_REFINEMENTS, [\n member.roleId ? customRole?.permissions : undefined,\n member.permissions,\n ])\n}\n\n/**\n * The values a custom role and a per-member override set EXPLICITLY for\n * permission keys outside this catalog — the keys plugins declare through\n * `registerPluginPermissions` (AGL-2974).\n *\n * `resolveOrgPermissions` walks the catalog alone, so a plugin key stored on\n * a custom role or a member document never reached the `resolvedPermissions`\n * stamp the Firestore rules read. A rule gating on one could then honor\n * neither a grant to an editor nor a revocation from an admin. This carries\n * exactly those stored decisions, custom role first and the per-member\n * override over it, which is the precedence the resolver applies.\n *\n * Tier DEFAULTS are deliberately absent. They live in the plugin registry,\n * which is populated per process by whichever plugin bundles that process\n * loaded, and a stamp computed from it would differ by which route happened\n * to write it. A rule supplies the default itself from the member's role,\n * the way `memberResolves` is always conjoined with a role gate.\n *\n * The legacy six camelCase keys are excluded as well: they are the catalog's\n * older projection, not plugin keys, and no rule reads them.\n */\nexport function explicitPluginPermissionValues(\n member:\n | {\n roleId?: string\n permissions?: Partial<Record<string, unknown>> | null\n }\n | null\n | undefined,\n customRole?: { permissions?: Partial<Record<string, unknown>> | null } | null,\n): Record<string, boolean> {\n const values: Record<string, boolean> = {}\n if (!member) return values\n const layers = [\n member.roleId ? customRole?.permissions : undefined,\n member.permissions,\n ]\n for (const layer of layers) {\n for (const [key, value] of Object.entries(layer ?? {})) {\n if (typeof value !== 'boolean') continue\n if (CATALOG_AND_LEGACY_KEYS.has(key)) continue\n values[key] = value\n }\n }\n return values\n}\n\n/**\n * Keys {@link explicitPluginPermissionValues} leaves to the catalog: every\n * catalog key, declared ones included, and the legacy six. Kept in step by\n * `syncCatalog`.\n */\nconst CATALOG_AND_LEGACY_KEYS = new Set<string>()\n\n/**\n * The `resolvedPermissions` map stamped on a member document for the\n * Firestore rules: the catalog verdict with every layer applied, and beside\n * it the plugin keys a custom role or an override set explicitly.\n *\n * One function for every writer of the stamp, so the org-create transaction\n * and `syncOrgAuthProjections` cannot project different maps. The catalog\n * spreads last; the two key spaces do not overlap, and the order keeps it\n * true that nothing but the resolver decides a catalog key.\n */\nexport function projectMemberResolvedPermissions(\n member: Parameters<typeof resolveOrgPermissions>[0],\n customRole?: AglynOrgCustomRole | null,\n): Record<string, boolean> {\n return {\n ...explicitPluginPermissionValues(member, customRole),\n ...resolveOrgPermissions(member, customRole),\n }\n}\n\n/** Single-permission convenience over `resolveOrgPermissions`. */\nexport function hasOrgPermission(\n member: Parameters<typeof resolveOrgPermissions>[0],\n permission: OrgPermission,\n customRole?: AglynOrgCustomRole | null,\n): boolean {\n return resolveOrgPermissions(member, customRole)[permission]\n}\n\n/** The catalog label for a key — the words a refusal names — or the key itself. */\nexport function orgPermissionLabel(permission: OrgPermission): string {\n return (\n ORG_PERMISSIONS.find((definition) => definition.key === permission)?.label ??\n permission\n )\n}\n\n/**\n * The sentence a door answers when a member does not hold a key (AGL-4047):\n * it names the permission by its catalog label and who can change it, never\n * a role.\n */\nexport function permissionRefusalText(permission: OrgPermission): string {\n return `Your role does not include \"${orgPermissionLabel(permission)}\" — ask an organization admin`\n}\n\n/** The keys plugins declared into the catalog, in catalog order. */\nexport function pluginOrgPermissionKeys(): OrgPermission[] {\n return ORG_PERMISSIONS.filter((definition) => definition.pluginId).map(\n (definition) => definition.key,\n )\n}\n\n/** One declared catalog key that moved, and the direction it moved in. */\nexport interface PluginPermissionChange {\n permission: string\n granted: boolean\n}\n\n/**\n * The keys PLUGINS declared into the catalog whose value moved between two\n * maps, in the new map's order — what a member, role or collaborator write\n * raises `org.permissions.changed` for, once per key, so the plugin that owns\n * a key can record who moved it.\n *\n * A key the new map leaves unset is not a change: on a role it defers to the\n * base role, on a site toggle to the host role, and neither is a grant or a\n * revocation of its own. A key set for the first time is a change, because\n * the verdict it produces is no longer the default's. The core keys and the\n * legacy six raise nothing; their writes are recorded by the routes' own\n * activity sentences.\n */\nexport function pluginPermissionChanges(\n before: Partial<Record<string, unknown>> | null | undefined,\n after: Partial<Record<string, unknown>> | null | undefined,\n): PluginPermissionChange[] {\n const changes: PluginPermissionChange[] = []\n for (const [key, next] of Object.entries(after ?? {})) {\n if (typeof next !== 'boolean') continue\n if (CORE_ORG_PERMISSION_KEYS.has(key) || LEGACY_PERMISSION_KEYS.has(key)) continue\n if (before?.[key] === next) continue\n changes.push({ permission: key, granted: next })\n }\n return changes\n}\n\n/**\n * The granular (dotted) set projected onto the legacy boolean map\n * (AGL-2350).\n *\n * ## Why this lives here rather than in the console hook\n *\n * It was a private function in `apps/console/hooks/use-org-permissions.ts`,\n * which meant the CLIENT translated the stored permission model into the\n * legacy flags and the SERVER did not translate at all — it derived the\n * legacy flags straight from the built-in role tier and dropped custom roles\n * and per-member overrides on the floor. The two disagreed exactly on the\n * feature `custom-roles.md` sells, in both directions: a permission granted\n * by a custom role showed in the UI and 403'd on POST, and one revoked by an\n * override was hidden in the UI and still succeeded on POST.\n *\n * One exported copy is what stops them drifting again.\n *\n * ## The key spaces are NOT interchangeable, and that is the trap\n *\n * Two permission vocabularies exist. The stored one is DOTTED\n * (`plugins.install`) — `apps/console/app/api/orgs/roles/route.ts` sanitizes\n * against `ORG_PERMISSION_KEYS` before writing, and `AglynOrgMember`\n * `permissions` is typed to it. The legacy one is camelCase\n * (`installPlugins`).\n *\n * `resolveRolePermissions` in `org-roles.ts` accepts `overrides` and\n * `customRoles` arguments keyed by the CAMELCASE space. Feeding it the real\n * stored documents therefore matches no key and changes nothing — it looks\n * like wiring the feature up while doing precisely nothing. Those two\n * parameters are used by nothing but that module's own spec. Translate\n * through here instead.\n *\n * `editHosts` is derived from the ROLE, not from a dotted key: it has no\n * counterpart in the granular catalog and never had one.\n */\nexport function toLegacyPermissions(\n granted: Record<OrgPermission, boolean>,\n role: OrgRole | null | undefined,\n): OrgPermissions {\n return {\n createHosts: granted['hosts.create'],\n editHosts: role !== 'viewer',\n editBilling: granted['billing.manage'],\n publishToMarketplace: granted['marketplace.publish'],\n installPlugins: granted['plugins.install'],\n manageMembers: granted['members.manage'],\n }\n}\n\nsyncCatalog()\nsubscribePluginEntitlements(syncCatalog)\n// The second declaration API feeds the same catalog (AGL-4047).\nsubscribePluginPermissions(syncCatalog)\n"],"names":["listPluginCatalogPermissions","subscribePluginEntitlements","permissionRefinementOf","refinePermissionMap","subscribePluginPermissions","ORG_ROLE_PERMISSION_KEYS","CORE_ORG_PERMISSION_ENTRIES","CORE_ORG_PERMISSION_GROUPS","CORE_ORG_ROLE_GRANTS","CORE_SITE_ROLE_PRESETS","CORE_ORG_PERMISSIONS","map","entry","key","group","scope","hostRoleDefaults","presetFromSiteRole","roleDefaults","owner","includes","admin","editor","viewer","CORE_ORG_PERMISSION_KEYS","Set","definition","LEGACY_PERMISSION_KEYS","ORG_ROLES","ORG_PERMISSIONS","ORG_PERMISSION_KEYS","ORG_PERMISSION_GROUPS","TIER_PERMISSION_KEYS","ORG_PERMISSION_REFINEMENTS","NO_PERMISSIONS","DEFAULT_ROLE_PERMISSIONS","reportedRefusals","replaceItems","target","items","list","length","push","replaceEntries","entries","Object","keys","assign","syncCatalog","definitions","tierKeys","groups","declared","has","refusal","pluginId","add","console","error","label","description","refines","follows","narrowsPerSite","source","some","id","groupLabel","known","flatMap","refinement","filter","fromEntries","role","CATALOG_AND_LEGACY_KEYS","clear","tierPermissionsOf","granted","picked","orgPermissionDefinition","permission","find","resolveOrgPermissions","member","customRole","base","merged","roleId","permissions","value","undefined","explicitPluginPermissionValues","values","layers","layer","projectMemberResolvedPermissions","hasOrgPermission","orgPermissionLabel","permissionRefusalText","pluginOrgPermissionKeys","pluginPermissionChanges","before","after","changes","next","toLegacyPermissions","createHosts","editHosts","editBilling","publishToMarketplace","installPlugins","manageMembers"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SACEA,4BAA4B,EAC5BC,2BAA2B,QACtB,2CAAuC;AAC9C,SACEC,sBAAsB,EACtBC,mBAAmB,EACnBC,0BAA0B,QAErB,0CAAsC;AAC7C,SAASC,wBAAwB,QAAQ,iBAAa;AACtD,SACEC,2BAA2B,EAC3BC,0BAA0B,EAC1BC,oBAAoB,EACpBC,sBAAsB,QAGjB,uBAAmB;AA2G1B;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,MAAMC,uBACJ,2EAA2E;AAC3EJ,4BAA4BK,GAAG,CAAC,CAACC;QAGxBA,cACAA;WAJmC,aACvCA;QACHC,KAAKD,MAAMC,GAA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;;;;;;;;;;;;;;;;;;;;;CAkCC,GACD,OAAO,SAASE,oBACd5B,OAAuC,EACvCJ,IAAgC;IAEhC,OAAO;QACLiC,aAAa7B,OAAO,CAAC,eAAe;QACpC8B,WAAWlC,SAAS;QACpBmC,aAAa/B,OAAO,CAAC,iBAAiB;QACtCgC,sBAAsBhC,OAAO,CAAC,sBAAsB;QACpDiC,gBAAgBjC,OAAO,CAAC,kBAAkB;QAC1CkC,eAAelC,OAAO,CAAC,iBAAiB;IAC1C;AACF;AAEA7B;AACA/C,4BAA4B+C;AAC5B,gEAAgE;AAChE5C,2BAA2B4C"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../libs/aglyn/src/lib/app-utils/org-permissions.ts"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AglynOrgMember, OrgRole } from '../foundation'\nimport {\n listPluginCatalogPermissions,\n subscribePluginEntitlements,\n} from '../plugin-manager/plugin-entitlements'\nimport {\n permissionRefinementOf,\n refinePermissionMap,\n subscribePluginPermissions,\n type PermissionRefinement,\n} from '../plugin-manager/plugin-permissions'\nimport { ORG_ROLE_PERMISSION_KEYS } from './org-roles'\nimport {\n CORE_ORG_PERMISSION_ENTRIES,\n CORE_ORG_PERMISSION_GROUPS,\n CORE_ORG_ROLE_GRANTS,\n CORE_SITE_ROLE_PRESETS,\n type OrgPermissionGroup,\n type OrgPermissionScope,\n} from './org-role-grants'\n\nexport type { OrgPermissionGroup, OrgPermissionScope }\n\n/**\n * Granular org permissions (AGL-243) layered on the 4 org roles: each\n * role maps to a default permission set; custom roles\n * (`orgs/{orgId}/roles/{roleId}`) and per-member overrides refine it, so\n * e.g. an editor restricted to one host can also be granted billing\n * visibility — or an admin stripped of it — without inventing new roles.\n * The console hides unpermitted surfaces; the org API routes are the\n * enforcement point.\n */\nexport type CoreOrgPermission =\n | 'org.settings'\n | 'org.auditLog'\n | 'org.apiKeys'\n | 'org.privacy'\n | 'org.holds'\n | 'org.export'\n | 'org.sendingDomains'\n | 'org.businessProfile'\n | 'org.media'\n | 'org.eraseRecords'\n | 'billing.view'\n | 'billing.manage'\n | 'members.manage'\n | 'hosts.create'\n | 'hosts.delete'\n | 'data.manage'\n | 'marketplace.publish'\n | 'plugins.install'\n | 'site.edit'\n | 'site.publish'\n | 'site.sensitive'\n | 'site.manage'\n\n/**\n * A key of the catalog: a core key above, or a key a plugin declares into\n * the catalog through `registerPluginEntitlements` (AGL-2984). A declared key\n * is stored on custom roles and member overrides, layered and resolved\n * exactly like a core key.\n */\nexport type OrgPermission = CoreOrgPermission | (string & {})\n\n/**\n * Legacy boolean permission map derived from the granular `OrgPermission`\n * set (AGL-243). Kept for the console surfaces that predate the granular\n * model; lives here so relocated feature plugins can accept it as a prop\n * (AGL-395).\n */\nexport interface OrgPermissions {\n createHosts: boolean\n editHosts: boolean\n editBilling: boolean\n publishToMarketplace: boolean\n installPlugins: boolean\n manageMembers: boolean\n}\n\nexport interface OrgPermissionDefinition {\n key: OrgPermission\n label: string\n description: string\n /** The plugin that declared the key; absent for a core key. */\n pluginId?: string\n /** The `ORG_PERMISSION_GROUPS` id the role editor files it under (AGL-4047). */\n group: string\n /** Where it is decided: `org`, or `site` for a key a site collaborator holds per site. */\n scope: OrgPermissionScope\n /** Each org role's verdict when nothing refines it (`DEFAULT_ROLE_PERMISSIONS`). */\n roleDefaults: Readonly<Record<OrgRole, boolean>>\n /** Each host role's verdict, for a `site` key. */\n hostRoleDefaults?: Readonly<Record<string, boolean>>\n /**\n * The broader key this one is a finer part of (AGL-4047): never granted\n * without it, and following it where no custom role or override sets this\n * key. Only a plugin's key refines, and only a key the catalog holds.\n */\n refines?: OrgPermission\n /**\n * The key this one follows where no custom role or override sets it,\n * without needing it (AGL-4047): granted on its own, it holds while that\n * key is refused. Only a plugin's key follows, and only a key the catalog\n * holds; a key that refines does not also follow.\n */\n follows?: OrgPermission\n /**\n * Present when a site can narrow the key (AGL-4047): where a member who\n * works across the workspace has narrower access to one site than their\n * workspace role, whether the key follows that site role there is a\n * control, set per key on a custom role (`siteNarrowing`) and per member\n * (`AglynOrgMember.siteNarrowing`), and this is each built-in role's\n * default for it. `narrowPermissionsToSite` applies it. Only a plugin's key.\n */\n narrowsPerSite?: Readonly<Record<OrgRole, boolean>>\n /**\n * The key's preset is the member's role ON THE SITE a request names, for\n * every member (AGL-4047): `hostRoleDefaults` read for the access they hold\n * there, then their custom role, their own permissions and that site's\n * toggle. `roleDefaults` is the answer with no site named.\n * `resolveSiteRolePresetPermissions` decides it. The core's site keys\n * (`CORE_SITE_ROLE_PRESETS`) and a plugin's key with `hostRoleDefaults`.\n */\n presetFromSiteRole?: true\n /**\n * With `presetFromSiteRole`: the site role is the preset only for a member\n * of the whole workspace (AGL-4047). A site collaborator's preset is\n * refusal, whatever their site role, and only the site's toggle grants it\n * to them. A plugin's key that replaces a gate asking for an admin of the\n * whole workspace who is also the site's admin.\n */\n workspaceMembersOnly?: true\n}\n\n/**\n * The core keys, in display order for role editors.\n *\n * ⚠️ **EVERY KEY HERE MUST BE ENFORCED SERVER-SIDE.** A permission a customer\n * can tick that changes nothing is worse than its absence, because it implies\n * a control that does not exist — an owner unticks \"delete sites\", hands the\n * role out, and the member deletes sites while the console does not even dim\n * the button. Three of the eleven were in exactly that state (AGL-2444).\n *\n * `marketing.manage` was removed rather than wired, and the reason is worth\n * keeping: announcement bars, popups and campaigns live at\n * `hosts/{hostId}/overlays|campaigns|experiments` and are written\n * client-direct against the security rules, which gate on the HOST role.\n * There is no org-level boundary for it to sit on, and the action it named is\n * not org-scoped at all. Wiring it would have meant inventing one and\n * producing a second permission that looks enforced and is not. If a granular\n * marketing permission is wanted it belongs in the plugin-declared mechanism\n * (AGL-435), scoped to a host — a product decision, not this repair.\n *\n * `apps/console/specs/org-permissions-are-enforced.spec.ts` fails the build if\n * a key here, or a key a plugin declares, gains no server-side consumer.\n */\nconst CORE_ORG_PERMISSIONS: readonly OrgPermissionDefinition[] =\n // One table, shared with the native apps through the contracts (AGL-3950).\n CORE_ORG_PERMISSION_ENTRIES.map((entry) => ({\n ...entry,\n key: entry.key as CoreOrgPermission,\n group: entry.group ?? 'organization',\n scope: entry.scope ?? 'org',\n // A site key's preset is the member's role on the site (AGL-4047).\n ...(CORE_SITE_ROLE_PRESETS[entry.key]\n ? { hostRoleDefaults: { ...CORE_SITE_ROLE_PRESETS[entry.key] }, presetFromSiteRole: true as const }\n : {}),\n roleDefaults: {\n owner: CORE_ORG_ROLE_GRANTS.owner.includes(entry.key),\n admin: CORE_ORG_ROLE_GRANTS.admin.includes(entry.key),\n editor: CORE_ORG_ROLE_GRANTS.editor.includes(entry.key),\n viewer: CORE_ORG_ROLE_GRANTS.viewer.includes(entry.key),\n },\n }))\n\n/** The core keys: a plugin may add keys beside them and never redefine one. */\nconst CORE_ORG_PERMISSION_KEYS: ReadonlySet<string> = new Set(\n CORE_ORG_PERMISSIONS.map((definition) => definition.key),\n)\n\n/** The legacy camelCase projection's keys, which no declaration may take either. */\nconst LEGACY_PERMISSION_KEYS: ReadonlySet<string> = new Set<string>(\n ORG_ROLE_PERMISSION_KEYS,\n)\n\n/** The org roles, in the order `DEFAULT_ROLE_PERMISSIONS` lists them. */\nconst ORG_ROLES: readonly OrgRole[] = ['owner', 'admin', 'editor', 'viewer']\n\n/**\n * Every permission, in display order for role editors: the core keys, then\n * the keys plugins declare through `registerPluginEntitlements`, in the\n * plugins' catalog order (AGL-2984).\n *\n * LIVE, and kept in step in place. A plugin's declarations register at\n * module scope — at boot on the server, before the first paint in the\n * console — which can be after a module holding this binding was evaluated.\n * So this array, the key list, the role defaults and the empty map below are\n * rewritten in place on every registration instead of being computed once\n * when this module loads, and whoever holds the binding reads the declared\n * keys with the core ones.\n */\nexport const ORG_PERMISSIONS: readonly OrgPermissionDefinition[] = []\n\nexport const ORG_PERMISSION_KEYS: readonly OrgPermission[] = []\n\n/**\n * The groups the catalog's keys are filed under, in display order (AGL-4047):\n * the core groups, then one per plugin group a declaration names. Live, like\n * `ORG_PERMISSIONS`; a group with no key is left out.\n */\nexport const ORG_PERMISSION_GROUPS: readonly OrgPermissionGroup[] = []\n\n/**\n * The catalog keys that came through `registerPluginPermissions` (AGL-4047):\n * the keys the per-tier resolver (`resolveRolePermissions`) also answers,\n * which a caller holding a catalog-resolved map lays over that resolver's\n * answer so a custom role reaches them. Live.\n */\nexport const TIER_PERMISSION_KEYS: readonly OrgPermission[] = []\n\n/**\n * Every catalog key that refines a broader one, with that key (AGL-4047),\n * and every key that only follows one, marked `'follows'`. Live, like\n * `ORG_PERMISSIONS`. A resolver lays it over its map with\n * `refinePermissionMap`.\n */\nexport const ORG_PERMISSION_REFINEMENTS: readonly PermissionRefinement[] = []\n\nconst NO_PERMISSIONS = {} as Record<OrgPermission, boolean>\n\n/**\n * Role → default permission set. Owner/admin hold everything (owner-only\n * actions like org deletion stay role-checked, not permission-checked);\n * editors work on content but see no money or roster controls; viewers read\n * only. A declared key's default for each role is the one its declaration\n * names.\n */\nexport const DEFAULT_ROLE_PERMISSIONS: Record<\n OrgRole,\n Record<OrgPermission, boolean>\n> = {\n owner: {} as Record<OrgPermission, boolean>,\n admin: {} as Record<OrgPermission, boolean>,\n editor: {} as Record<OrgPermission, boolean>,\n viewer: {} as Record<OrgPermission, boolean>,\n}\n\n/** Refused declarations already logged, so a refusal is reported once. */\nconst reportedRefusals = new Set<string>()\n\nfunction replaceItems<T>(target: readonly T[], items: readonly T[]): void {\n const list = target as T[]\n list.length = 0\n list.push(...items)\n}\n\nfunction replaceEntries(\n target: Record<string, boolean>,\n entries: Record<string, boolean>,\n): void {\n for (const key of Object.keys(target)) delete target[key]\n Object.assign(target, entries)\n}\n\n/**\n * Rebuilds the live catalog: the core keys, then every key a plugin declared\n * through either declaration API (`listPluginCatalogPermissions`, AGL-4047).\n * A declaration naming a core or legacy key is refused — that key keeps its\n * own meaning and defaults — and logged once.\n */\nfunction syncCatalog(): void {\n const definitions: OrgPermissionDefinition[] = [...CORE_ORG_PERMISSIONS]\n const tierKeys: string[] = []\n const groups: OrgPermissionGroup[] = CORE_ORG_PERMISSION_GROUPS.map((group) => ({ ...group }))\n for (const declared of listPluginCatalogPermissions()) {\n if (\n CORE_ORG_PERMISSION_KEYS.has(declared.key) ||\n LEGACY_PERMISSION_KEYS.has(declared.key)\n ) {\n const refusal = `${declared.pluginId}\\x00${declared.key}`\n if (!reportedRefusals.has(refusal)) {\n reportedRefusals.add(refusal)\n console.error(\n `[plugins] refused catalog permission \"${declared.key}\" to ` +\n `\"${declared.pluginId}\": the key belongs to the core catalog`,\n )\n }\n continue\n }\n definitions.push({\n key: declared.key,\n label: declared.label,\n description: declared.description,\n pluginId: declared.pluginId,\n group: declared.group,\n scope: declared.hostRoleDefaults ? 'site' : 'org',\n roleDefaults: declared.roleDefaults,\n ...(declared.hostRoleDefaults ? { hostRoleDefaults: declared.hostRoleDefaults } : {}),\n ...(declared.refines ? { refines: declared.refines } : {}),\n ...(declared.follows && !declared.refines ? { follows: declared.follows } : {}),\n ...(declared.narrowsPerSite ? { narrowsPerSite: { ...declared.narrowsPerSite } } : {}),\n ...(declared.presetFromSiteRole && declared.hostRoleDefaults ? { presetFromSiteRole: true as const } : {}),\n ...(declared.presetFromSiteRole && declared.hostRoleDefaults && declared.workspaceMembersOnly\n ? { workspaceMembersOnly: true as const }\n : {}),\n })\n if (declared.source === 'tier') tierKeys.push(declared.key)\n if (!groups.some((group) => group.id === declared.group)) {\n groups.push({ id: declared.group, label: declared.groupLabel, pluginId: declared.pluginId })\n }\n }\n const keys = definitions.map((definition) => definition.key)\n const known = new Set<string>(keys)\n // A refinement of a key the catalog does not hold refines nothing, and is\n // dropped from the definition so no editor offers a link to nowhere.\n for (const definition of definitions) {\n if (definition.refines && (!known.has(definition.refines) || definition.refines === definition.key)) {\n delete definition.refines\n }\n if (definition.follows && (!known.has(definition.follows) || definition.follows === definition.key)) {\n delete definition.follows\n }\n }\n replaceItems(\n ORG_PERMISSION_REFINEMENTS,\n definitions.flatMap((definition) => {\n const refinement = permissionRefinementOf(definition)\n return refinement ? [refinement] : []\n }),\n )\n replaceItems(ORG_PERMISSIONS, definitions)\n replaceItems(ORG_PERMISSION_KEYS, keys)\n replaceItems(\n ORG_PERMISSION_GROUPS,\n groups.filter((group) => definitions.some((definition) => definition.group === group.id)),\n )\n replaceItems(TIER_PERMISSION_KEYS, tierKeys)\n replaceEntries(NO_PERMISSIONS, Object.fromEntries(keys.map((key) => [key, false])))\n for (const role of ORG_ROLES) {\n replaceEntries(\n DEFAULT_ROLE_PERMISSIONS[role],\n Object.fromEntries(\n definitions.map((definition) => [definition.key, definition.roleDefaults[role] === true]),\n ),\n )\n }\n CATALOG_AND_LEGACY_KEYS.clear()\n for (const key of [...keys, ...LEGACY_PERMISSION_KEYS]) {\n CATALOG_AND_LEGACY_KEYS.add(key)\n }\n}\n\n/**\n * The `registerPluginPermissions` keys of a catalog-resolved map (AGL-4047).\n *\n * Those keys are answered twice: by the per-tier resolver\n * (`resolveRolePermissions`, the role's tier default and the member's\n * override) and, now that they are catalog keys, by `resolveOrgPermissions`\n * with every layer — the custom role's included. A caller that builds its\n * map from the first spreads this over it, so the custom role a member\n * carries reaches `managePos` the way it reaches `hosts.create`.\n */\nexport function tierPermissionsOf(\n granted: Readonly<Record<string, boolean>> | null | undefined,\n): Record<string, boolean> {\n const picked: Record<string, boolean> = {}\n if (!granted) return picked\n for (const key of TIER_PERMISSION_KEYS) {\n if (typeof granted[key] === 'boolean') picked[key] = granted[key]\n }\n return picked\n}\n\n/** One catalog key by name, or undefined. */\nexport function orgPermissionDefinition(\n permission: OrgPermission,\n): OrgPermissionDefinition | undefined {\n return ORG_PERMISSIONS.find((definition) => definition.key === permission)\n}\n\n/** `orgs/{orgId}/roles/{roleId}` — a named custom permission set. */\nexport interface AglynOrgCustomRole {\n $id?: string\n name?: string\n description?: string\n /** Full permission map; missing keys read as false. */\n permissions?: Partial<Record<OrgPermission, boolean>>\n /**\n * Per key a site can narrow (AGL-4047): `true` follows the site role on a\n * site where the member's access is narrower than their workspace role,\n * `false` keeps the permission there. A key it leaves out follows the\n * built-in role's default (`OrgPermissionDefinition.narrowsPerSite`), and\n * a member's own `siteNarrowing` wins over it.\n */\n siteNarrowing?: Partial<Record<OrgPermission, boolean>>\n}\n\n/**\n * Effective permission map for a member: the org role's defaults, then\n * the custom role's map (when the member has `roleId` and the role doc\n * is supplied), then per-member overrides — later layers win key-by-key.\n */\nexport function resolveOrgPermissions(\n member:\n | (Partial<AglynOrgMember> & {\n roleId?: string\n permissions?: Partial<Record<OrgPermission, boolean>>\n })\n | null\n | undefined,\n customRole?: AglynOrgCustomRole | null,\n): Record<OrgPermission, boolean> {\n if (!member) return NO_PERMISSIONS\n const role = (member.role ?? 'viewer') as OrgRole\n const base = DEFAULT_ROLE_PERMISSIONS[role] ?? NO_PERMISSIONS\n const merged: Record<OrgPermission, boolean> = { ...base }\n if (member.roleId && customRole?.permissions) {\n for (const key of ORG_PERMISSION_KEYS) {\n const value = customRole.permissions[key]\n if (typeof value === 'boolean') merged[key] = value\n }\n }\n if (member.permissions) {\n for (const key of ORG_PERMISSION_KEYS) {\n const value = member.permissions[key]\n if (typeof value === 'boolean') merged[key] = value\n }\n }\n // A key that refines a broader one (AGL-4047) follows it where neither\n // layer set the key, and is never held without it; a key that only follows\n // one takes its verdict where neither layer set the key, and nothing more.\n return refinePermissionMap(merged, ORG_PERMISSION_REFINEMENTS, [\n member.roleId ? customRole?.permissions : undefined,\n member.permissions,\n ])\n}\n\n/**\n * The values a custom role and a per-member override set EXPLICITLY for\n * permission keys outside this catalog — the keys plugins declare through\n * `registerPluginPermissions` (AGL-2974).\n *\n * `resolveOrgPermissions` walks the catalog alone, so a plugin key stored on\n * a custom role or a member document never reached the `resolvedPermissions`\n * stamp the Firestore rules read. A rule gating on one could then honor\n * neither a grant to an editor nor a revocation from an admin. This carries\n * exactly those stored decisions, custom role first and the per-member\n * override over it, which is the precedence the resolver applies.\n *\n * Tier DEFAULTS are deliberately absent. They live in the plugin registry,\n * which is populated per process by whichever plugin bundles that process\n * loaded, and a stamp computed from it would differ by which route happened\n * to write it. A rule supplies the default itself from the member's role,\n * the way `memberResolves` is always conjoined with a role gate.\n *\n * The legacy six camelCase keys are excluded as well: they are the catalog's\n * older projection, not plugin keys, and no rule reads them.\n */\nexport function explicitPluginPermissionValues(\n member:\n | {\n roleId?: string\n permissions?: Partial<Record<string, unknown>> | null\n }\n | null\n | undefined,\n customRole?: { permissions?: Partial<Record<string, unknown>> | null } | null,\n): Record<string, boolean> {\n const values: Record<string, boolean> = {}\n if (!member) return values\n const layers = [\n member.roleId ? customRole?.permissions : undefined,\n member.permissions,\n ]\n for (const layer of layers) {\n for (const [key, value] of Object.entries(layer ?? {})) {\n if (typeof value !== 'boolean') continue\n if (CATALOG_AND_LEGACY_KEYS.has(key)) continue\n values[key] = value\n }\n }\n return values\n}\n\n/**\n * Keys {@link explicitPluginPermissionValues} leaves to the catalog: every\n * catalog key, declared ones included, and the legacy six. Kept in step by\n * `syncCatalog`.\n */\nconst CATALOG_AND_LEGACY_KEYS = new Set<string>()\n\n/**\n * The `resolvedPermissions` map stamped on a member document for the\n * Firestore rules: the catalog verdict with every layer applied, and beside\n * it the plugin keys a custom role or an override set explicitly.\n *\n * One function for every writer of the stamp, so the org-create transaction\n * and `syncOrgAuthProjections` cannot project different maps. The catalog\n * spreads last; the two key spaces do not overlap, and the order keeps it\n * true that nothing but the resolver decides a catalog key.\n */\nexport function projectMemberResolvedPermissions(\n member: Parameters<typeof resolveOrgPermissions>[0],\n customRole?: AglynOrgCustomRole | null,\n): Record<string, boolean> {\n return {\n ...explicitPluginPermissionValues(member, customRole),\n ...resolveOrgPermissions(member, customRole),\n }\n}\n\n/** Single-permission convenience over `resolveOrgPermissions`. */\nexport function hasOrgPermission(\n member: Parameters<typeof resolveOrgPermissions>[0],\n permission: OrgPermission,\n customRole?: AglynOrgCustomRole | null,\n): boolean {\n return resolveOrgPermissions(member, customRole)[permission]\n}\n\n/** The catalog label for a key — the words a refusal names — or the key itself. */\nexport function orgPermissionLabel(permission: OrgPermission): string {\n return (\n ORG_PERMISSIONS.find((definition) => definition.key === permission)?.label ??\n permission\n )\n}\n\n/**\n * The sentence a door answers when a member does not hold a key (AGL-4047):\n * it names the permission by its catalog label and who can change it, never\n * a role.\n */\nexport function permissionRefusalText(permission: OrgPermission): string {\n return `Your role does not include \"${orgPermissionLabel(permission)}\" — ask an organization admin`\n}\n\n/** The keys plugins declared into the catalog, in catalog order. */\nexport function pluginOrgPermissionKeys(): OrgPermission[] {\n return ORG_PERMISSIONS.filter((definition) => definition.pluginId).map(\n (definition) => definition.key,\n )\n}\n\n/** One declared catalog key that moved, and the direction it moved in. */\nexport interface PluginPermissionChange {\n permission: string\n granted: boolean\n}\n\n/**\n * The keys PLUGINS declared into the catalog whose value moved between two\n * maps, in the new map's order — what a member, role or collaborator write\n * raises `org.permissions.changed` for, once per key, so the plugin that owns\n * a key can record who moved it.\n *\n * A key the new map leaves unset is not a change: on a role it defers to the\n * base role, on a site toggle to the host role, and neither is a grant or a\n * revocation of its own. A key set for the first time is a change, because\n * the verdict it produces is no longer the default's. The core keys and the\n * legacy six raise nothing; their writes are recorded by the routes' own\n * activity sentences.\n */\nexport function pluginPermissionChanges(\n before: Partial<Record<string, unknown>> | null | undefined,\n after: Partial<Record<string, unknown>> | null | undefined,\n): PluginPermissionChange[] {\n const changes: PluginPermissionChange[] = []\n for (const [key, next] of Object.entries(after ?? {})) {\n if (typeof next !== 'boolean') continue\n if (CORE_ORG_PERMISSION_KEYS.has(key) || LEGACY_PERMISSION_KEYS.has(key)) continue\n if (before?.[key] === next) continue\n changes.push({ permission: key, granted: next })\n }\n return changes\n}\n\n/**\n * The granular (dotted) set projected onto the legacy boolean map\n * (AGL-2350).\n *\n * ## Why this lives here rather than in the console hook\n *\n * It was a private function in `apps/console/hooks/use-org-permissions.ts`,\n * which meant the CLIENT translated the stored permission model into the\n * legacy flags and the SERVER did not translate at all — it derived the\n * legacy flags straight from the built-in role tier and dropped custom roles\n * and per-member overrides on the floor. The two disagreed exactly on the\n * feature `custom-roles.md` sells, in both directions: a permission granted\n * by a custom role showed in the UI and 403'd on POST, and one revoked by an\n * override was hidden in the UI and still succeeded on POST.\n *\n * One exported copy is what stops them drifting again.\n *\n * ## The key spaces are NOT interchangeable, and that is the trap\n *\n * Two permission vocabularies exist. The stored one is DOTTED\n * (`plugins.install`) — `apps/console/app/api/orgs/roles/route.ts` sanitizes\n * against `ORG_PERMISSION_KEYS` before writing, and `AglynOrgMember`\n * `permissions` is typed to it. The legacy one is camelCase\n * (`installPlugins`).\n *\n * `resolveRolePermissions` in `org-roles.ts` accepts `overrides` and\n * `customRoles` arguments keyed by the CAMELCASE space. Feeding it the real\n * stored documents therefore matches no key and changes nothing — it looks\n * like wiring the feature up while doing precisely nothing. Those two\n * parameters are used by nothing but that module's own spec. Translate\n * through here instead.\n *\n * `editHosts` is derived from the ROLE, not from a dotted key: it has no\n * counterpart in the granular catalog and never had one.\n */\nexport function toLegacyPermissions(\n granted: Record<OrgPermission, boolean>,\n role: OrgRole | null | undefined,\n): OrgPermissions {\n return {\n createHosts: granted['hosts.create'],\n editHosts: role !== 'viewer',\n editBilling: granted['billing.manage'],\n publishToMarketplace: granted['marketplace.publish'],\n installPlugins: granted['plugins.install'],\n manageMembers: granted['members.manage'],\n }\n}\n\nsyncCatalog()\nsubscribePluginEntitlements(syncCatalog)\n// The second declaration API feeds the same catalog (AGL-4047).\nsubscribePluginPermissions(syncCatalog)\n"],"names":["listPluginCatalogPermissions","subscribePluginEntitlements","permissionRefinementOf","refinePermissionMap","subscribePluginPermissions","ORG_ROLE_PERMISSION_KEYS","CORE_ORG_PERMISSION_ENTRIES","CORE_ORG_PERMISSION_GROUPS","CORE_ORG_ROLE_GRANTS","CORE_SITE_ROLE_PRESETS","CORE_ORG_PERMISSIONS","map","entry","key","group","scope","hostRoleDefaults","presetFromSiteRole","roleDefaults","owner","includes","admin","editor","viewer","CORE_ORG_PERMISSION_KEYS","Set","definition","LEGACY_PERMISSION_KEYS","ORG_ROLES","ORG_PERMISSIONS","ORG_PERMISSION_KEYS","ORG_PERMISSION_GROUPS","TIER_PERMISSION_KEYS","ORG_PERMISSION_REFINEMENTS","NO_PERMISSIONS","DEFAULT_ROLE_PERMISSIONS","reportedRefusals","replaceItems","target","items","list","length","push","replaceEntries","entries","Object","keys","assign","syncCatalog","definitions","tierKeys","groups","declared","has","refusal","pluginId","add","console","error","label","description","refines","follows","narrowsPerSite","workspaceMembersOnly","source","some","id","groupLabel","known","flatMap","refinement","filter","fromEntries","role","CATALOG_AND_LEGACY_KEYS","clear","tierPermissionsOf","granted","picked","orgPermissionDefinition","permission","find","resolveOrgPermissions","member","customRole","base","merged","roleId","permissions","value","undefined","explicitPluginPermissionValues","values","layers","layer","projectMemberResolvedPermissions","hasOrgPermission","orgPermissionLabel","permissionRefusalText","pluginOrgPermissionKeys","pluginPermissionChanges","before","after","changes","next","toLegacyPermissions","createHosts","editHosts","editBilling","publishToMarketplace","installPlugins","manageMembers"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC;AAGD,SACEA,4BAA4B,EAC5BC,2BAA2B,QACtB,2CAAuC;AAC9C,SACEC,sBAAsB,EACtBC,mBAAmB,EACnBC,0BAA0B,QAErB,0CAAsC;AAC7C,SAASC,wBAAwB,QAAQ,iBAAa;AACtD,SACEC,2BAA2B,EAC3BC,0BAA0B,EAC1BC,oBAAoB,EACpBC,sBAAsB,QAGjB,uBAAmB;AAmH1B;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,MAAMC,uBACJ,2EAA2E;AAC3EJ,4BA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CAACxC,MAAM;QAC1E,IAAIyF,CAAAA,0BAAAA,MAAQ,CAACzF,IAAI,MAAK4F,MAAM;QAC5BD,QAAQ9D,IAAI,CAAC;YAAEuC,YAAYpE;YAAKiE,SAAS2B;QAAK;IAChD;IACA,OAAOD;AACT;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCC,GACD,OAAO,SAASE,oBACd5B,OAAuC,EACvCJ,IAAgC;IAEhC,OAAO;QACLiC,aAAa7B,OAAO,CAAC,eAAe;QACpC8B,WAAWlC,SAAS;QACpBmC,aAAa/B,OAAO,CAAC,iBAAiB;QACtCgC,sBAAsBhC,OAAO,CAAC,sBAAsB;QACpDiC,gBAAgBjC,OAAO,CAAC,kBAAkB;QAC1CkC,eAAelC,OAAO,CAAC,iBAAiB;IAC1C;AACF;AAEA9B;AACA/C,4BAA4B+C;AAC5B,gEAAgE;AAChE5C,2BAA2B4C"}
|
|
@@ -187,21 +187,21 @@ export const ORG_ROLE_NAMES = [
|
|
|
187
187
|
group: 'sites',
|
|
188
188
|
scope: 'site',
|
|
189
189
|
label: 'Publish site content',
|
|
190
|
-
description: 'Make pages and content live, take them down or schedule them, and change
|
|
190
|
+
description: 'Make pages and content live, take them down or schedule them, change redirects and change the site’s fonts.'
|
|
191
191
|
},
|
|
192
192
|
{
|
|
193
193
|
key: 'site.sensitive',
|
|
194
194
|
group: 'sites',
|
|
195
195
|
scope: 'site',
|
|
196
196
|
label: 'See orders and webhooks',
|
|
197
|
-
description: 'Read a site’s orders and
|
|
197
|
+
description: 'Read a site’s orders, returns and sending address, and set up its webhooks.'
|
|
198
198
|
},
|
|
199
199
|
{
|
|
200
200
|
key: 'site.manage',
|
|
201
201
|
group: 'sites',
|
|
202
202
|
scope: 'site',
|
|
203
203
|
label: 'Manage site settings',
|
|
204
|
-
description: 'Manage a site’s people, domain, address and plugins, change its plugin settings and security allow-lists, import, export and delete it.'
|
|
204
|
+
description: 'Manage a site’s people, domain, address and plugins, change its plugin settings (live chat, Zapier) and security allow-lists, import, export and delete it.'
|
|
205
205
|
},
|
|
206
206
|
{
|
|
207
207
|
key: 'data.manage',
|