@foundrykit/permissions-plugin 0.1.2 → 0.1.4
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/README.md +10 -5
- package/dist/access.js.map +1 -1
- package/dist/activePlugins.d.ts +10 -0
- package/dist/activePlugins.js +27 -0
- package/dist/activePlugins.js.map +1 -0
- package/dist/audit.js +1 -1
- package/dist/audit.js.map +1 -1
- package/dist/collections/PermissionOverrides.js.map +1 -1
- package/dist/collections/Roles.js +1 -1
- package/dist/collections/Roles.js.map +1 -1
- package/dist/components/NavLinks.js +0 -1
- package/dist/components/NavLinks.js.map +1 -1
- package/dist/components/PublishButtonGate.js +0 -1
- package/dist/components/PublishButtonGate.js.map +1 -1
- package/dist/components/RolesMatrix.d.ts +1 -1
- package/dist/components/RolesMatrix.js +1 -1
- package/dist/components/RolesMatrix.js.map +1 -1
- package/dist/components/UsersTable.js +2 -2
- package/dist/components/UsersTable.js.map +1 -1
- package/dist/components/api.js.map +1 -1
- package/dist/components/index.scss +4 -4
- package/dist/endpoints/resetToRole.js.map +1 -1
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/rsc.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/registry.js.map +1 -1
- package/dist/resolve.js.map +1 -1
- package/dist/rules.js.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/users.js +1 -1
- package/dist/users.js.map +1 -1
- package/dist/views/PermissionsLayout.d.ts +1 -1
- package/dist/views/PermissionsLayout.js +0 -1
- package/dist/views/PermissionsLayout.js.map +1 -1
- package/dist/views/RolesView.js +0 -1
- package/dist/views/RolesView.js.map +1 -1
- package/dist/views/UsersView.js +0 -1
- package/dist/views/UsersView.js.map +1 -1
- package/dist/views/data.js +1 -1
- package/dist/views/data.js.map +1 -1
- package/package.json +28 -44
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/api.ts"],"sourcesContent":["/** JSON request against the Payload REST API, throwing the server's own error message. */\nexport const api = async (url: string, method: string, body?: unknown) => {\n const res = await fetch(url, {\n body: body === undefined ? undefined : JSON.stringify(body),\n credentials: 'include',\n headers: { 'Content-Type': 'application/json' },\n method,\n })
|
|
1
|
+
{"version":3,"sources":["../../src/components/api.ts"],"sourcesContent":["/** JSON request against the Payload REST API, throwing the server's own error message. */\nexport const api = async (url: string, method: string, body?: unknown) => {\n const res = await fetch(url, {\n body: body === undefined ? undefined : JSON.stringify(body),\n credentials: 'include',\n headers: { 'Content-Type': 'application/json' },\n method,\n });\n const json = await res.json().catch(() => ({}));\n if (!res.ok) {\n throw new Error(json.errors?.[0]?.message ?? res.statusText);\n }\n return json;\n};\n"],"names":["api","url","method","body","res","fetch","undefined","JSON","stringify","credentials","headers","json","catch","ok","Error","errors","message","statusText"],"mappings":"AAAA,wFAAwF,GACxF,OAAO,MAAMA,MAAM,OAAOC,KAAaC,QAAgBC;IACrD,MAAMC,MAAM,MAAMC,MAAMJ,KAAK;QAC3BE,MAAMA,SAASG,YAAYA,YAAYC,KAAKC,SAAS,CAACL;QACtDM,aAAa;QACbC,SAAS;YAAE,gBAAgB;QAAmB;QAC9CR;IACF;IACA,MAAMS,OAAO,MAAMP,IAAIO,IAAI,GAAGC,KAAK,CAAC,IAAO,CAAA,CAAC,CAAA;IAC5C,IAAI,CAACR,IAAIS,EAAE,EAAE;QACX,MAAM,IAAIC,MAAMH,KAAKI,MAAM,EAAE,CAAC,EAAE,EAAEC,WAAWZ,IAAIa,UAAU;IAC7D;IACA,OAAON;AACT,EAAE"}
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
font-size: 0.85em;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
input[type=
|
|
29
|
+
input[type="checkbox"] {
|
|
30
30
|
accent-color: var(--theme-success-500);
|
|
31
31
|
cursor: pointer;
|
|
32
32
|
height: 16px;
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
padding: calc(var(--base) * 0.5) 0;
|
|
77
77
|
text-decoration: none;
|
|
78
78
|
|
|
79
|
-
&[aria-current=
|
|
79
|
+
&[aria-current="page"] {
|
|
80
80
|
border-color: var(--theme-text);
|
|
81
81
|
color: var(--theme-text);
|
|
82
82
|
}
|
|
@@ -306,13 +306,13 @@
|
|
|
306
306
|
border-left: 1px solid var(--theme-elevation-150);
|
|
307
307
|
}
|
|
308
308
|
|
|
309
|
-
&[aria-pressed=
|
|
309
|
+
&[aria-pressed="true"] {
|
|
310
310
|
background: var(--theme-elevation-800);
|
|
311
311
|
color: var(--theme-elevation-0);
|
|
312
312
|
opacity: 1;
|
|
313
313
|
}
|
|
314
314
|
|
|
315
|
-
&:disabled:not([aria-pressed=
|
|
315
|
+
&:disabled:not([aria-pressed="true"]) {
|
|
316
316
|
cursor: not-allowed;
|
|
317
317
|
opacity: 0.4;
|
|
318
318
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/endpoints/resetToRole.ts"],"sourcesContent":["import type { CollectionSlug, PayloadHandler } from 'payload'
|
|
1
|
+
{"version":3,"sources":["../../src/endpoints/resetToRole.ts"],"sourcesContent":["import type { CollectionSlug, PayloadHandler } from 'payload';\n\nimport { commitTransaction, initTransaction, killTransaction } from 'payload';\n\nimport {\n getOverrides,\n getState,\n hasPermission,\n OVERRIDES_SLUG,\n} from '../access.js';\nimport { PART_OF_CHANGE, writeAudit } from '../audit.js';\nimport { MANAGE_PERMISSION } from '../registry.js';\nimport { assertCanGrant, assertNotSelf } from '../rules.js';\n\nexport const RESET_PATH = '/permissions/reset/:id';\n\n/** Clears every override on a user, logged as one \"Reset to role\" entry. */\nexport const resetToRoleHandler: PayloadHandler = async req => {\n if (!(await hasPermission(req, MANAGE_PERMISSION))) {\n return Response.json(\n { errors: [{ message: 'Forbidden' }] },\n { status: 403 }\n );\n }\n // Look the user up so the id has the database's type (a number on Postgres, not the URL string).\n const user = await req.payload\n .findByID({\n id: req.routeParams?.id as string,\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- a union once a site generates types\n collection: getState(req.payload).usersSlug as CollectionSlug,\n depth: 0,\n disableErrors: true,\n overrideAccess: true,\n req,\n })\n .catch(() => null);\n if (!user) {\n return Response.json(\n { errors: [{ message: 'Not Found' }] },\n { status: 404 }\n );\n }\n const id = user.id;\n assertNotSelf(req, id);\n\n const overrides = await getOverrides(req.payload, id, req);\n // Lifting a deny can hand the permission back, which counts as granting it.\n await assertCanGrant(\n req,\n overrides.filter(o => o.effect === 'deny').map(o => o.permission)\n );\n if (overrides.length) {\n // One transaction, so the overrides are never cleared without the audit entry.\n const ownsTransaction = await initTransaction(req);\n try {\n await req.payload.delete({\n collection: OVERRIDES_SLUG,\n context: { [PART_OF_CHANGE]: true },\n overrideAccess: true,\n req,\n where: { user: { equals: id } },\n });\n await writeAudit(req, {\n action: 'user.reset',\n after: [],\n before: overrides.map(({ effect, permission }) => ({\n effect,\n permission,\n })),\n summary: `Reset to role: ${overrides.length} override${overrides.length === 1 ? '' : 's'} cleared`,\n user: id,\n });\n if (ownsTransaction) {\n await commitTransaction(req);\n }\n } catch (err) {\n await killTransaction(req);\n throw err;\n }\n }\n return Response.json({ removed: overrides.length });\n};\n"],"names":["commitTransaction","initTransaction","killTransaction","getOverrides","getState","hasPermission","OVERRIDES_SLUG","PART_OF_CHANGE","writeAudit","MANAGE_PERMISSION","assertCanGrant","assertNotSelf","RESET_PATH","resetToRoleHandler","req","Response","json","errors","message","status","user","payload","findByID","id","routeParams","collection","usersSlug","depth","disableErrors","overrideAccess","catch","overrides","filter","o","effect","map","permission","length","ownsTransaction","delete","context","where","equals","action","after","before","summary","err","removed"],"mappings":"AAEA,SAASA,iBAAiB,EAAEC,eAAe,EAAEC,eAAe,QAAQ,UAAU;AAE9E,SACEC,YAAY,EACZC,QAAQ,EACRC,aAAa,EACbC,cAAc,QACT,eAAe;AACtB,SAASC,cAAc,EAAEC,UAAU,QAAQ,cAAc;AACzD,SAASC,iB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MAAM;wBAAEsB,QAAQnB;oBAAG;gBAAE;YAChC;YACA,MAAMf,WAAWM,KAAK;gBACpB6B,QAAQ;gBACRC,OAAO,EAAE;gBACTC,QAAQd,UAAUI,GAAG,CAAC,CAAC,EAAED,MAAM,EAAEE,UAAU,EAAE,GAAM,CAAA;wBACjDF;wBACAE;oBACF,CAAA;gBACAU,SAAS,CAAC,eAAe,EAAEf,UAAUM,MAAM,CAAC,SAAS,EAAEN,UAAUM,MAAM,KAAK,IAAI,KAAK,IAAI,QAAQ,CAAC;gBAClGjB,MAAMG;YACR;YACA,IAAIe,iBAAiB;gBACnB,MAAMtC,kBAAkBc;YAC1B;QACF,EAAE,OAAOiC,KAAK;YACZ,MAAM7C,gBAAgBY;YACtB,MAAMiC;QACR;IACF;IACA,OAAOhC,SAASC,IAAI,CAAC;QAAEgC,SAASjB,UAAUM,MAAM;IAAC;AACnD,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export {}
|
|
1
|
+
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export {};\n"],"names":[],"mappings":"AAAA,WAAU"}
|
package/dist/exports/rsc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/exports/rsc.ts"],"sourcesContent":["export { NavLinks } from '../components/NavLinks.js'
|
|
1
|
+
{"version":3,"sources":["../../src/exports/rsc.ts"],"sourcesContent":["export { NavLinks } from '../components/NavLinks.js';\nexport { PublishButtonGate } from '../components/PublishButtonGate.js';\nexport { RolesView } from '../views/RolesView.js';\nexport { UsersView } from '../views/UsersView.js';\n"],"names":["NavLinks","PublishButtonGate","RolesView","UsersView"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,4BAA4B;AACrD,SAASC,iBAAiB,QAAQ,qCAAqC;AACvE,SAASC,SAAS,QAAQ,wBAAwB;AAClD,SAASC,SAAS,QAAQ,wBAAwB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Config } from 'payload';
|
|
2
2
|
import type { PermissionsPluginConfig } from './types.js';
|
|
3
|
-
export { AUDIT_SLUG, computePermissions, getPermissions, hasPermission, OVERRIDES_SLUG,
|
|
3
|
+
export { AUDIT_SLUG, computePermissions, getPermissions, hasPermission, OVERRIDES_SLUG, ROLES_SLUG, requirePermission, userHasPermission, } from './access.js';
|
|
4
4
|
export { MANAGE_PERMISSION } from './registry.js';
|
|
5
|
-
export { redundantOverrides, resolvePermission, resolvePermissions } from './resolve.js';
|
|
5
|
+
export { redundantOverrides, resolvePermission, resolvePermissions, } from './resolve.js';
|
|
6
6
|
export type { Area, AreaConfig, Permission, PermissionsPluginConfig, StandardAction, } from './types.js';
|
|
7
7
|
export declare const permissionsPlugin: (pluginOptions?: PermissionsPluginConfig) => (config: Config) => Config;
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { APIError } from 'payload';
|
|
2
2
|
import { AUDIT_SLUG, gateAccess, hasPermission, isCMSUser, markActive, OVERRIDES_SLUG, ROLES_SLUG } from './access.js';
|
|
3
|
+
import { recordActivePlugin } from './activePlugins.js';
|
|
3
4
|
import { createAuditCollection } from './audit.js';
|
|
4
5
|
import { createOverridesCollection } from './collections/PermissionOverrides.js';
|
|
5
6
|
import { createRolesCollection } from './collections/Roles.js';
|
|
6
7
|
import { RESET_PATH, resetToRoleHandler } from './endpoints/resetToRole.js';
|
|
7
8
|
import { buildRegistry } from './registry.js';
|
|
8
9
|
import { extendUsersCollection } from './users.js';
|
|
9
|
-
export { AUDIT_SLUG, computePermissions, getPermissions, hasPermission, OVERRIDES_SLUG,
|
|
10
|
+
export { AUDIT_SLUG, computePermissions, getPermissions, hasPermission, OVERRIDES_SLUG, ROLES_SLUG, requirePermission, userHasPermission } from './access.js';
|
|
10
11
|
export { MANAGE_PERMISSION } from './registry.js';
|
|
11
12
|
export { redundantOverrides, resolvePermission, resolvePermissions } from './resolve.js';
|
|
12
13
|
/** Publishing (moving `_status` to published) needs `area.publish` on top of create/edit. */ const guardPublish = (key)=>async ({ data, originalDoc, req })=>{
|
|
@@ -189,7 +190,7 @@ export const permissionsPlugin = (pluginOptions = {})=>(config)=>{
|
|
|
189
190
|
path: RESET_PATH
|
|
190
191
|
}
|
|
191
192
|
];
|
|
192
|
-
return config;
|
|
193
|
+
return recordActivePlugin(config, '@foundrykit/permissions-plugin');
|
|
193
194
|
};
|
|
194
195
|
|
|
195
196
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n CollectionConfig,\n CollectionSlug,\n Config,\n GlobalConfig,\n PayloadRequest,\n} from 'payload'\n\nimport { APIError } from 'payload'\n\nimport type { Area, PermissionsPluginConfig } from './types.js'\n\nimport {\n AUDIT_SLUG,\n gateAccess,\n hasPermission,\n isCMSUser,\n markActive,\n OVERRIDES_SLUG,\n ROLES_SLUG,\n} from './access.js'\nimport { createAuditCollection } from './audit.js'\nimport { createOverridesCollection } from './collections/PermissionOverrides.js'\nimport { createRolesCollection } from './collections/Roles.js'\nimport { RESET_PATH, resetToRoleHandler } from './endpoints/resetToRole.js'\nimport { buildRegistry } from './registry.js'\nimport { extendUsersCollection } from './users.js'\n\nexport {\n AUDIT_SLUG,\n computePermissions,\n getPermissions,\n hasPermission,\n OVERRIDES_SLUG,\n requirePermission,\n ROLES_SLUG,\n userHasPermission,\n} from './access.js'\nexport { MANAGE_PERMISSION } from './registry.js'\nexport { redundantOverrides, resolvePermission, resolvePermissions } from './resolve.js'\nexport type {\n Area,\n AreaConfig,\n Permission,\n PermissionsPluginConfig,\n StandardAction,\n} from './types.js'\n\n/** Publishing (moving `_status` to published) needs `area.publish` on top of create/edit. */\nconst guardPublish =\n (key: string) =>\n async ({\n data,\n originalDoc,\n req,\n }: {\n data: Record<string, unknown>\n originalDoc?: Record<string, unknown>\n req: PayloadRequest\n }) => {\n // Payload marks every draft save `_status: 'draft'` before hooks run, so anything else that\n // asks to publish, or lands on a published document, changes what's live.\n const publishing =\n data._status !== 'draft' &&\n (data._status === 'published' || originalDoc?._status === 'published')\n // Draft saves also send `_status: 'draft'`; only REST and GraphQL say which is which.\n // REST parses `?draft=true` into a boolean before hooks run; GraphQL leaves the string.\n // ponytail: local API unpublishes aren't checked, since hooks can't tell them from draft saves\n const unpublishing =\n data._status === 'draft' &&\n originalDoc?._status === 'published' &&\n req.payloadAPI !== 'local' &&\n String(req.query?.draft) !== 'true'\n if (!publishing && !unpublishing) {\n return data\n }\n if (isCMSUser(req.payload, req.user) && !(await hasPermission(req, key))) {\n const verb = publishing ? 'publish' : 'unpublish'\n throw new APIError(`You don't have permission to ${verb} this.`, 403, undefined, true)\n }\n return data\n }\n\nconst hasKey = (area: Area, key: string) => area.permissions.some((p) => p.key === key)\n\nconst RSC = '@foundrykit/permissions-plugin/rsc'\n\n/** Server component that hides the (un)publish button from people without `key`. */\nconst publishButton = (key: string, kind: 'publish' | 'unpublish' = 'publish') => ({\n path: `${RSC}#PublishButtonGate`,\n serverProps: { kind, permission: key },\n})\n\nconst gateCollection = (collection: CollectionConfig, area: Area): CollectionConfig => ({\n ...collection,\n access: {\n ...collection.access,\n create: gateAccess(`${area.slug}.create`, collection.access?.create),\n delete: gateAccess(`${area.slug}.delete`, collection.access?.delete),\n read: gateAccess(`${area.slug}.read`, collection.access?.read),\n update: gateAccess(`${area.slug}.edit`, collection.access?.update),\n },\n admin: hasKey(area, `${area.slug}.publish`)\n ? {\n ...collection.admin,\n components: {\n ...collection.admin?.components,\n edit: {\n PublishButton: publishButton(`${area.slug}.publish`),\n UnpublishButton: publishButton(`${area.slug}.publish`, 'unpublish'),\n ...collection.admin?.components?.edit,\n },\n },\n }\n : collection.admin,\n hooks: {\n ...collection.hooks,\n afterChange: [...(collection.hooks?.afterChange ?? []), ({ req }) => markActive(req)],\n afterDelete: [...(collection.hooks?.afterDelete ?? []), ({ req }) => markActive(req)],\n beforeChange: hasKey(area, `${area.slug}.publish`)\n ? [...(collection.hooks?.beforeChange ?? []), guardPublish(`${area.slug}.publish`)]\n : collection.hooks?.beforeChange,\n },\n})\n\nconst gateGlobal = (global: GlobalConfig, area: Area): GlobalConfig => ({\n ...global,\n access: {\n ...global.access,\n read: gateAccess(`${area.slug}.read`, global.access?.read),\n update: gateAccess(`${area.slug}.edit`, global.access?.update),\n },\n admin: hasKey(area, `${area.slug}.publish`)\n ? {\n ...global.admin,\n components: {\n ...global.admin?.components,\n elements: {\n PublishButton: publishButton(`${area.slug}.publish`),\n UnpublishButton: publishButton(`${area.slug}.publish`, 'unpublish'),\n ...global.admin?.components?.elements,\n },\n },\n }\n : global.admin,\n hooks: {\n ...global.hooks,\n afterChange: [...(global.hooks?.afterChange ?? []), ({ req }) => markActive(req)],\n beforeChange: hasKey(area, `${area.slug}.publish`)\n ? [...(global.hooks?.beforeChange ?? []), guardPublish(`${area.slug}.publish`)]\n : global.hooks?.beforeChange,\n },\n})\n\nexport const permissionsPlugin =\n (pluginOptions: PermissionsPluginConfig = {}) =>\n (config: Config): Config => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- a union once a site generates types\n const usersSlug = (config.admin?.user ?? 'users') as CollectionSlug\n const collections = config.collections ?? []\n const globals = config.globals ?? []\n const areas = pluginOptions.areas ?? []\n\n if (!collections.some((c) => c.slug === usersSlug)) {\n throw new Error(`permissions: users collection \"${usersSlug}\" not found`)\n }\n for (const slug of [ROLES_SLUG, OVERRIDES_SLUG, AUDIT_SLUG]) {\n if (collections.some((c) => c.slug === slug)) {\n throw new Error(`permissions: a \"${slug}\" collection already exists`)\n }\n }\n\n const registry = buildRegistry(areas, collections, globals)\n const areaFor = (key: 'collection' | 'global', slug: string) => {\n const configured = areas.find((a) => a[key] === slug)\n return configured && registry.find((a) => a.slug === configured.slug)\n }\n\n config.custom = {\n ...config.custom,\n permissions: {\n isSuperAdmin: pluginOptions.isSuperAdmin ?? (() => false),\n keys: registry.flatMap((a) => a.permissions.map((p) => p.key)),\n registry,\n usersSlug,\n },\n }\n\n config.collections = [\n ...collections.map((collection) => {\n if (collection.slug === usersSlug) {\n return extendUsersCollection(collection)\n }\n const area = !pluginOptions.disabled && areaFor('collection', collection.slug)\n return area ? gateCollection(collection, area) : collection\n }),\n createRolesCollection({ registry, usersSlug }),\n createOverridesCollection({ registry, usersSlug }),\n createAuditCollection(usersSlug),\n ]\n\n if (pluginOptions.disabled) {\n return config\n }\n\n config.globals = globals.map((global) => {\n const area = areaFor('global', global.slug)\n return area ? gateGlobal(global, area) : global\n })\n\n config.admin = {\n ...config.admin,\n components: {\n ...config.admin?.components,\n afterNavLinks: [...(config.admin?.components?.afterNavLinks ?? []), `${RSC}#NavLinks`],\n views: {\n ...config.admin?.components?.views,\n permissionsRoles: { Component: `${RSC}#RolesView`, exact: true, path: '/permissions' },\n permissionsUsers: {\n Component: `${RSC}#UsersView`,\n exact: true,\n path: '/permissions/users',\n },\n },\n },\n }\n\n config.endpoints = [\n ...(config.endpoints ?? []),\n { handler: resetToRoleHandler, method: 'post', path: RESET_PATH },\n ]\n\n return config\n }\n"],"names":["APIError","AUDIT_SLUG","gateAccess","hasPermission","isCMSUser","markActive","OVERRIDES_SLUG","ROLES_SLUG","createAuditCollection","createOverridesCollection","createRolesCollection","RESET_PATH","resetToRoleHandler","buildRegistry","extendUsersCollection","computePermissions","getPermissions","requirePermission","userHasPermission","MANAGE_PERMISSION","redundantOverrides","resolvePermission","resolvePermissions","guardPublish","key","data","originalDoc","req","publishing","_status","unpublishing","payloadAPI","String","query","draft","payload","user","verb","undefined","hasKey","area","permissions","some","p","RSC","publishButton","kind","path","serverProps","permission","gateCollection","collection","access","create","slug","delete","read","update","admin","components","edit","PublishButton","UnpublishButton","hooks","afterChange","afterDelete","beforeChange","gateGlobal","global","elements","permissionsPlugin","pluginOptions","config","usersSlug","collections","globals","areas","c","Error","registry","areaFor","configured","find","a","custom","isSuperAdmin","keys","flatMap","map","disabled","afterNavLinks","views","permissionsRoles","Component","exact","permissionsUsers","endpoints","handler","method"],"mappings":"AAQA,SAASA,QAAQ,QAAQ,UAAS;AAIlC,SACEC,UAAU,EACVC,UAAU,EACVC,aAAa,EACbC,SAAS,EACTC,UAAU,EACVC,cAAc,EACdC,UAAU,QACL,cAAa;AACpB,SAASC,qBAAqB,QAAQ,aAAY;AAClD,SAASC,yBAAyB,QAAQ,uCAAsC;AAChF,SAASC,qBAAqB,QAAQ,yBAAwB;AAC9D,SAASC,UAAU,EAAEC,kBAAkB,QAAQ,6BAA4B;AAC3E,SAASC,aAAa,QAAQ,gBAAe;AAC7C,SAASC,qBAAqB,QAAQ,aAAY;AAElD,SACEb,UAAU,EACVc,kBAAkB,EAClBC,cAAc,EACdb,aAAa,EACbG,cAAc,EACdW,iBAAiB,EACjBV,UAAU,EACVW,iBAAiB,QACZ,cAAa;AACpB,SAASC,iBAAiB,QAAQ,gBAAe;AACjD,SAASC,kBAAkB,EAAEC,iBAAiB,EAAEC,kBAAkB,QAAQ,eAAc;AASxF,2FAA2F,GAC3F,MAAMC,eACJ,CAACC,MACD,OAAO,EACLC,IAAI,EACJC,WAAW,EACXC,GAAG,EAKJ;QACC,4FAA4F;QAC5F,0EAA0E;QAC1E,MAAMC,aACJH,KAAKI,OAAO,KAAK,WAChBJ,CAAAA,KAAKI,OAAO,KAAK,eAAeH,aAAaG,YAAY,WAAU;QACtE,sFAAsF;QACtF,wFAAwF;QACxF,+FAA+F;QAC/F,MAAMC,eACJL,KAAKI,OAAO,KAAK,WACjBH,aAAaG,YAAY,eACzBF,IAAII,UAAU,KAAK,WACnBC,OAAOL,IAAIM,KAAK,EAAEC,WAAW;QAC/B,IAAI,CAACN,cAAc,CAACE,cAAc;YAChC,OAAOL;QACT;QACA,IAAIrB,UAAUuB,IAAIQ,OAAO,EAAER,IAAIS,IAAI,KAAK,CAAE,MAAMjC,cAAcwB,KAAKH,MAAO;YACxE,MAAMa,O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C;wBAAEkD,OAAO;wBAAM/C,MAAM;oBAAe;oBACrFgD,kBAAkB;wBAChBF,WAAW,GAAGjD,IAAI,UAAU,CAAC;wBAC7BkD,OAAO;wBACP/C,MAAM;oBACR;gBACF;YACF;QACF;QAEAyB,OAAOwB,SAAS,GAAG;eACbxB,OAAOwB,SAAS,IAAI,EAAE;YAC1B;gBAAEC,SAASrF;gBAAoBsF,QAAQ;gBAAQnD,MAAMpC;YAAW;SACjE;QAED,OAAO6D;IACT,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n CollectionConfig,\n CollectionSlug,\n Config,\n GlobalConfig,\n PayloadRequest,\n} from 'payload';\n\nimport { APIError } from 'payload';\nimport {\n AUDIT_SLUG,\n gateAccess,\n hasPermission,\n isCMSUser,\n markActive,\n OVERRIDES_SLUG,\n ROLES_SLUG,\n} from './access.js';\nimport { recordActivePlugin } from './activePlugins.js';\nimport { createAuditCollection } from './audit.js';\nimport { createOverridesCollection } from './collections/PermissionOverrides.js';\nimport { createRolesCollection } from './collections/Roles.js';\nimport { RESET_PATH, resetToRoleHandler } from './endpoints/resetToRole.js';\nimport { buildRegistry } from './registry.js';\nimport type { Area, PermissionsPluginConfig } from './types.js';\nimport { extendUsersCollection } from './users.js';\n\nexport {\n AUDIT_SLUG,\n computePermissions,\n getPermissions,\n hasPermission,\n OVERRIDES_SLUG,\n ROLES_SLUG,\n requirePermission,\n userHasPermission,\n} from './access.js';\nexport { MANAGE_PERMISSION } from './registry.js';\nexport {\n redundantOverrides,\n resolvePermission,\n resolvePermissions,\n} from './resolve.js';\nexport type {\n Area,\n AreaConfig,\n Permission,\n PermissionsPluginConfig,\n StandardAction,\n} from './types.js';\n\n/** Publishing (moving `_status` to published) needs `area.publish` on top of create/edit. */\nconst guardPublish =\n (key: string) =>\n async ({\n data,\n originalDoc,\n req,\n }: {\n data: Record<string, unknown>;\n originalDoc?: Record<string, unknown>;\n req: PayloadRequest;\n }) => {\n // Payload marks every draft save `_status: 'draft'` before hooks run, so anything else that\n // asks to publish, or lands on a published document, changes what's live.\n const publishing =\n data._status !== 'draft' &&\n (data._status === 'published' || originalDoc?._status === 'published');\n // Draft saves also send `_status: 'draft'`; only REST and GraphQL say which is which.\n // REST parses `?draft=true` into a boolean before hooks run; GraphQL leaves the string.\n // ponytail: local API unpublishes aren't checked, since hooks can't tell them from draft saves\n const unpublishing =\n data._status === 'draft' &&\n originalDoc?._status === 'published' &&\n req.payloadAPI !== 'local' &&\n String(req.query?.draft) !== 'true';\n if (!publishing && !unpublishing) {\n return data;\n }\n if (isCMSUser(req.payload, req.user) && !(await hasPermission(req, key))) {\n const verb = publishing ? 'publish' : 'unpublish';\n throw new APIError(\n `You don't have permission to ${verb} this.`,\n 403,\n undefined,\n true\n );\n }\n return data;\n };\n\nconst hasKey = (area: Area, key: string) =>\n area.permissions.some(p => p.key === key);\n\nconst RSC = '@foundrykit/permissions-plugin/rsc';\n\n/** Server component that hides the (un)publish button from people without `key`. */\nconst publishButton = (\n key: string,\n kind: 'publish' | 'unpublish' = 'publish'\n) => ({\n path: `${RSC}#PublishButtonGate`,\n serverProps: { kind, permission: key },\n});\n\nconst gateCollection = (\n collection: CollectionConfig,\n area: Area\n): CollectionConfig => ({\n ...collection,\n access: {\n ...collection.access,\n create: gateAccess(`${area.slug}.create`, collection.access?.create),\n delete: gateAccess(`${area.slug}.delete`, collection.access?.delete),\n read: gateAccess(`${area.slug}.read`, collection.access?.read),\n update: gateAccess(`${area.slug}.edit`, collection.access?.update),\n },\n admin: hasKey(area, `${area.slug}.publish`)\n ? {\n ...collection.admin,\n components: {\n ...collection.admin?.components,\n edit: {\n PublishButton: publishButton(`${area.slug}.publish`),\n UnpublishButton: publishButton(`${area.slug}.publish`, 'unpublish'),\n ...collection.admin?.components?.edit,\n },\n },\n }\n : collection.admin,\n hooks: {\n ...collection.hooks,\n afterChange: [\n ...(collection.hooks?.afterChange ?? []),\n ({ req }) => markActive(req),\n ],\n afterDelete: [\n ...(collection.hooks?.afterDelete ?? []),\n ({ req }) => markActive(req),\n ],\n beforeChange: hasKey(area, `${area.slug}.publish`)\n ? [\n ...(collection.hooks?.beforeChange ?? []),\n guardPublish(`${area.slug}.publish`),\n ]\n : collection.hooks?.beforeChange,\n },\n});\n\nconst gateGlobal = (global: GlobalConfig, area: Area): GlobalConfig => ({\n ...global,\n access: {\n ...global.access,\n read: gateAccess(`${area.slug}.read`, global.access?.read),\n update: gateAccess(`${area.slug}.edit`, global.access?.update),\n },\n admin: hasKey(area, `${area.slug}.publish`)\n ? {\n ...global.admin,\n components: {\n ...global.admin?.components,\n elements: {\n PublishButton: publishButton(`${area.slug}.publish`),\n UnpublishButton: publishButton(`${area.slug}.publish`, 'unpublish'),\n ...global.admin?.components?.elements,\n },\n },\n }\n : global.admin,\n hooks: {\n ...global.hooks,\n afterChange: [\n ...(global.hooks?.afterChange ?? []),\n ({ req }) => markActive(req),\n ],\n beforeChange: hasKey(area, `${area.slug}.publish`)\n ? [\n ...(global.hooks?.beforeChange ?? []),\n guardPublish(`${area.slug}.publish`),\n ]\n : global.hooks?.beforeChange,\n },\n});\n\nexport const permissionsPlugin =\n (pluginOptions: PermissionsPluginConfig = {}) =>\n (config: Config): Config => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- a union once a site generates types\n const usersSlug = (config.admin?.user ?? 'users') as CollectionSlug;\n const collections = config.collections ?? [];\n const globals = config.globals ?? [];\n const areas = pluginOptions.areas ?? [];\n\n if (!collections.some(c => c.slug === usersSlug)) {\n throw new Error(`permissions: users collection \"${usersSlug}\" not found`);\n }\n for (const slug of [ROLES_SLUG, OVERRIDES_SLUG, AUDIT_SLUG]) {\n if (collections.some(c => c.slug === slug)) {\n throw new Error(`permissions: a \"${slug}\" collection already exists`);\n }\n }\n\n const registry = buildRegistry(areas, collections, globals);\n const areaFor = (key: 'collection' | 'global', slug: string) => {\n const configured = areas.find(a => a[key] === slug);\n return configured && registry.find(a => a.slug === configured.slug);\n };\n\n config.custom = {\n ...config.custom,\n permissions: {\n isSuperAdmin: pluginOptions.isSuperAdmin ?? (() => false),\n keys: registry.flatMap(a => a.permissions.map(p => p.key)),\n registry,\n usersSlug,\n },\n };\n\n config.collections = [\n ...collections.map(collection => {\n if (collection.slug === usersSlug) {\n return extendUsersCollection(collection);\n }\n const area =\n !pluginOptions.disabled && areaFor('collection', collection.slug);\n return area ? gateCollection(collection, area) : collection;\n }),\n createRolesCollection({ registry, usersSlug }),\n createOverridesCollection({ registry, usersSlug }),\n createAuditCollection(usersSlug),\n ];\n\n if (pluginOptions.disabled) {\n return config;\n }\n\n config.globals = globals.map(global => {\n const area = areaFor('global', global.slug);\n return area ? gateGlobal(global, area) : global;\n });\n\n config.admin = {\n ...config.admin,\n components: {\n ...config.admin?.components,\n afterNavLinks: [\n ...(config.admin?.components?.afterNavLinks ?? []),\n `${RSC}#NavLinks`,\n ],\n views: {\n ...config.admin?.components?.views,\n permissionsRoles: {\n Component: `${RSC}#RolesView`,\n exact: true,\n path: '/permissions',\n },\n permissionsUsers: {\n Component: `${RSC}#UsersView`,\n exact: true,\n path: '/permissions/users',\n },\n },\n },\n };\n\n config.endpoints = [\n ...(config.endpoints ?? []),\n { handler: resetToRoleHandler, method: 'post', path: RESET_PATH },\n ];\n\n return recordActivePlugin(config, '@foundrykit/permissions-plugin');\n };\n"],"names":["APIError","AUDIT_SLUG","gateAccess","hasPermission","isCMSUser","markActive","OVERRIDES_SLUG","ROLES_SLUG","recordActivePlugin","createAuditCollection","createOverridesCollection","createRolesCollection","RESET_PATH","resetToRoleHandler","buildRegistry","extendUsersCollection","computePermissions","getPermissions","requirePermission","userHasPermission","MANAGE_PERMISSION","redundantOverrides","resolvePermission","resolvePermissions","guardPublish","key","data","originalDoc","req","publishing","_status","unpublishing","payloadAPI","String","query","draft","payload","user","verb","undefined","hasKey","area","permissions","some","p","RSC","publishButton","kind","path","serverProps","permission","gateCollection","collection","access","create","slug","delete","read","update","admin","components","edit","PublishButton","UnpublishButton","hooks","afterChange","afterDelete","beforeChange","gateGlobal","global","elements","permissionsPlugin","pluginOptions","config","usersSlug","collections","globals","areas","c","Error","registry","areaFor","configured","find","a","custom","isSuperAdmin","keys","flatMap","map","disabled","afterNavLinks","views","permissionsRoles","Component","exact","permissionsUsers","endpoints","handler","method"],"mappings":"AAQA,SAASA,QAAQ,QAAQ,UAAU;AACnC,SACEC,UAAU,EACVC,UAAU,EACVC,aAAa,EACbC,SAAS,EACTC,UAAU,EACVC,cAAc,EACdC,UAAU,QACL,cAAc;AACrB,SAASC,kBAAkB,QAAQ,qBAAqB;AACxD,SAASC,qBAAqB,QAAQ,aAAa;AACnD,SAASC,yBAAyB,QAAQ,uCAAuC;AACjF,SAASC,qBAAqB,QAAQ,yBAAyB;AAC/D,SAASC,UAAU,EAAEC,kBAAkB,QAAQ,6BAA6B;AAC5E,SAASC,aAAa,QAAQ,gBAAgB;AAE9C,SAASC,qBAAqB,QAAQ,aAAa;AAEnD,SACEd,UAAU,EACVe,kBAAkB,EAClBC,cAAc,EACdd,aAAa,EACbG,cAAc,EACdC,UAAU,EACVW,iBAAiB,EACjBC,iBAAiB,QACZ,cAAc;AACrB,SAASC,iBAAiB,QAAQ,gBAAgB;AAClD,SACEC,kBAAkB,EAClBC,iBAAiB,EACjBC,kBAAkB,QACb,eAAe;AAStB,2FAA2F,GAC3F,MAAMC,eACJ,CAACC,MACD,OAAO,EACLC,IAAI,EACJC,WAAW,EACXC,GAAG,EAKJ;QACC,4FAA4F;QAC5F,0EAA0E;QAC1E,MAAMC,aACJH,KAAKI,OAAO,KAAK,WAChBJ,CAAAA,KAAKI,OAAO,KAAK,eAAeH,aAAaG,YAAY,WAAU;QACtE,sFAAsF;QACtF,wFAAwF;QACxF,+FAA+F;QAC/F,MAAMC,eACJL,KAAKI,OAAO,KAAK,WACjBH,aAAaG,YAAY,eACzBF,IAAII,UAAU,KAAK,WACnBC,OAAOL,IAAIM,KAAK,EAAEC,WAAW;QAC/B,IAAI,CA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SAAS,CAAC;iBAClB;gBACD+C,OAAO;oBACL,GAAGnB,OAAOd,KAAK,EAAEC,YAAYgC,KAAK;oBAClCC,kBAAkB;wBAChBC,WAAW,GAAGjD,IAAI,UAAU,CAAC;wBAC7BkD,OAAO;wBACP/C,MAAM;oBACR;oBACAgD,kBAAkB;wBAChBF,WAAW,GAAGjD,IAAI,UAAU,CAAC;wBAC7BkD,OAAO;wBACP/C,MAAM;oBACR;gBACF;YACF;QACF;QAEAyB,OAAOwB,SAAS,GAAG;eACbxB,OAAOwB,SAAS,IAAI,EAAE;YAC1B;gBAAEC,SAASrF;gBAAoBsF,QAAQ;gBAAQnD,MAAMpC;YAAW;SACjE;QAED,OAAOJ,mBAAmBiE,QAAQ;IACpC,EAAE"}
|
package/dist/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/registry.ts"],"sourcesContent":["import type { CollectionConfig, GlobalConfig } from 'payload'
|
|
1
|
+
{"version":3,"sources":["../src/registry.ts"],"sourcesContent":["import type { CollectionConfig, GlobalConfig } from 'payload';\n\nimport type { Area, AreaConfig, StandardAction } from './types.js';\n\nexport const MANAGE_PERMISSION = 'permissions.manage';\n\nconst STANDARD_LABELS: Record<StandardAction, string> = {\n create: 'Create',\n delete: 'Delete',\n edit: 'Edit',\n publish: 'Publish',\n read: 'Read',\n};\n\nconst hasDrafts = (entity: CollectionConfig | GlobalConfig) =>\n typeof entity.versions === 'object' && Boolean(entity.versions?.drafts);\n\nconst defaultActions = (\n area: AreaConfig,\n collections: CollectionConfig[],\n globals: GlobalConfig[]\n): StandardAction[] => {\n if (area.collection) {\n const collection = collections.find(c => c.slug === area.collection);\n if (!collection) {\n throw new Error(\n `permissions: area \"${area.slug}\" maps to unknown collection \"${area.collection}\"`\n );\n }\n const actions: StandardAction[] = ['read', 'create', 'edit', 'delete'];\n return hasDrafts(collection) ? [...actions, 'publish'] : actions;\n }\n if (area.global) {\n const global = globals.find(g => g.slug === area.global);\n if (!global) {\n throw new Error(\n `permissions: area \"${area.slug}\" maps to unknown global \"${area.global}\"`\n );\n }\n return hasDrafts(global) ? ['read', 'edit', 'publish'] : ['read', 'edit'];\n }\n return [];\n};\n\n/** Turn the site's area config into the full list of `area.action` permissions. */\nexport const buildRegistry = (\n areas: AreaConfig[],\n collections: CollectionConfig[],\n globals: GlobalConfig[]\n): Area[] => {\n const seen = new Set<string>();\n const registry = [\n ...areas,\n {\n slug: 'permissions',\n customActions: { manage: 'Manage roles and permissions' },\n label: 'Permissions',\n },\n ].map((area): Area => {\n if (area.slug.includes('.')) {\n throw new Error(\n `permissions: area slug \"${area.slug}\" can't contain \".\"`\n );\n }\n if (seen.has(area.slug)) {\n throw new Error(`permissions: area \"${area.slug}\" is registered twice`);\n }\n seen.add(area.slug);\n\n const standard = (\n area.actions ?? defaultActions(area, collections, globals)\n ).map(action => ({\n action,\n label: STANDARD_LABELS[action],\n }));\n const custom = Object.entries(area.customActions ?? {}).map(\n ([action, label]) => ({\n action,\n label,\n })\n );\n\n return {\n slug: area.slug,\n label: area.label ?? area.slug,\n permissions: [...standard, ...custom].map(({ action, label }) => ({\n action,\n area: area.slug,\n key: `${area.slug}.${action}`,\n label,\n })),\n };\n });\n return registry;\n};\n"],"names":["MANAGE_PERMISSION","STANDARD_LABELS","create","delete","edit","publish","read","hasDrafts","entity","versions","Boolean","drafts","defaultActions","area","collections","globals","collection","find","c","slug","Error","actions","global","g","buildRegistry","areas","seen","Set","registry","customActions","manage","label","map","includes","has","add","standard","action","custom","Object","entries","permissions","key"],"mappings":"AAIA,OAAO,MAAMA,oBAAoB,qBAAqB;AAEtD,MAAMC,kBAAkD;IACtDC,QAAQ;IACRC,QAAQ;IACRC,MAAM;IACNC,SAAS;IACTC,MAAM;AACR;AAEA,MAAMC,YAAY,CAACC,SACjB,OAAOA,OAAOC,QAAQ,KAAK,YAAYC,QAAQF,OAAOC,QAAQ,EAAEE;AAElE,MAAMC,iBAAiB,CACrBC,MACAC,aACAC;IAEA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KAAKS,GAAG,CAACtB,KAAKM,IAAI;QAElB,MAAMiB,WAAW,AACfvB,CAAAA,KAAKQ,OAAO,IAAIT,eAAeC,MAAMC,aAAaC,QAAO,EACzDiB,GAAG,CAACK,CAAAA,SAAW,CAAA;gBACfA;gBACAN,OAAO9B,eAAe,CAACoC,OAAO;YAChC,CAAA;QACA,MAAMC,SAASC,OAAOC,OAAO,CAAC3B,KAAKgB,aAAa,IAAI,CAAC,GAAGG,GAAG,CACzD,CAAC,CAACK,QAAQN,MAAM,GAAM,CAAA;gBACpBM;gBACAN;YACF,CAAA;QAGF,OAAO;YACLZ,MAAMN,KAAKM,IAAI;YACfY,OAAOlB,KAAKkB,KAAK,IAAIlB,KAAKM,IAAI;YAC9BsB,aAAa;mBAAIL;mBAAaE;aAAO,CAACN,GAAG,CAAC,CAAC,EAAEK,MAAM,EAAEN,KAAK,EAAE,GAAM,CAAA;oBAChEM;oBACAxB,MAAMA,KAAKM,IAAI;oBACfuB,KAAK,GAAG7B,KAAKM,IAAI,CAAC,CAAC,EAAEkB,QAAQ;oBAC7BN;gBACF,CAAA;QACF;IACF;IACA,OAAOH;AACT,EAAE"}
|
package/dist/resolve.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/resolve.ts"],"sourcesContent":["import type { Override } from './types.js'
|
|
1
|
+
{"version":3,"sources":["../src/resolve.ts"],"sourcesContent":["import type { Override } from './types.js';\n\nexport type PermissionSource = 'override' | 'role' | 'superAdmin';\n\nexport type ResolvedPermission = {\n allowed: boolean;\n source: PermissionSource;\n};\n\ntype Input = {\n overrides: Override[];\n rolePermissions: string[];\n superAdmin: boolean;\n};\n\n/**\n * Super admin → allowed. Deny override → denied. Allow override → allowed.\n * Otherwise whatever the role says. Shared by the access checks and the admin\n * UI so the two can't disagree.\n */\nexport const resolvePermission = (\n key: string,\n input: Input\n): ResolvedPermission => {\n if (input.superAdmin) {\n return { allowed: true, source: 'superAdmin' };\n }\n const overrides = input.overrides.filter(o => o.permission === key);\n if (overrides.some(o => o.effect === 'deny')) {\n return { allowed: false, source: 'override' };\n }\n if (overrides.length) {\n return { allowed: true, source: 'override' };\n }\n return { allowed: input.rolePermissions.includes(key), source: 'role' };\n};\n\nexport const resolvePermissions = (keys: string[], input: Input): Set<string> =>\n new Set(keys.filter(key => resolvePermission(key, input).allowed));\n\n/** Overrides that say the same as the role, which a role change leaves pointless. */\nexport const redundantOverrides = <T extends Override>(\n overrides: T[],\n rolePermissions: string[]\n): T[] =>\n overrides.filter(\n o => (o.effect === 'allow') === rolePermissions.includes(o.permission)\n );\n"],"names":["resolvePermission","key","input","superAdmin","allowed","source","overrides","filter","o","permission","some","effect","length","rolePermissions","includes","resolvePermissions","keys","Set","redundantOverrides"],"mappings":"AAeA;;;;CAIC,GACD,OAAO,MAAMA,oBAAoB,CAC/BC,KACAC;IAEA,IAAIA,MAAMC,UAAU,EAAE;QACpB,OAAO;YAAEC,SAAS;YAAMC,QAAQ;QAAa;IAC/C;IACA,MAAMC,YAAYJ,MAAMI,SAAS,CAACC,MAAM,CAACC,CAAAA,IAAKA,EAAEC,UAAU,KAAKR;IAC/D,IAAIK,UAAUI,IAAI,CAACF,CAAAA,IAAKA,EAAEG,MAAM,KAAK,SAAS;QAC5C,OAAO;YAAEP,SAAS;YAAOC,QAAQ;QAAW;IAC9C;IACA,IAAIC,UAAUM,MAAM,EAAE;QACpB,OAAO;YAAER,SAAS;YAAMC,QAAQ;QAAW;IAC7C;IACA,OAAO;QAAED,SAASF,MAAMW,eAAe,CAACC,QAAQ,CAACb;QAAMI,QAAQ;IAAO;AACxE,EAAE;AAEF,OAAO,MAAMU,qBAAqB,CAACC,MAAgBd,QACjD,IAAIe,IAAID,KAAKT,MAAM,CAACN,CAAAA,MAAOD,kBAAkBC,KAAKC,OAAOE,OAAO,GAAG;AAErE,mFAAmF,GACnF,OAAO,MAAMc,qBAAqB,CAChCZ,WACAO,kBAEAP,UAAUC,MAAM,CACdC,CAAAA,IAAK,AAACA,EAAEG,MAAM,KAAK,YAAaE,gBAAgBC,QAAQ,CAACN,EAAEC,UAAU,GACrE"}
|
package/dist/rules.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/rules.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'
|
|
1
|
+
{"version":3,"sources":["../src/rules.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload';\n\nimport { APIError } from 'payload';\n\nimport { getPermissions, isCMSUser } from './access.js';\n\nconst forbid = (message: string) => new APIError(message, 403, undefined, true);\n\n/** Nobody changes their own role or overrides. */\nexport const assertNotSelf = (req: PayloadRequest, userID: unknown) => {\n if (\n isCMSUser(req.payload, req.user) &&\n String(req.user.id) === String(userID)\n ) {\n throw forbid(\"You can't change your own permissions.\");\n }\n};\n\n/** Nobody grants a permission they don't hold themselves. */\nexport const assertCanGrant = async (req: PayloadRequest, keys: string[]) => {\n if (!isCMSUser(req.payload, req.user) || !keys.length) {\n return;\n }\n const held = await getPermissions(req);\n const missing = keys.filter(key => !held.has(key));\n if (missing.length) {\n throw forbid(\n `You can't grant permissions you don't hold: ${missing.join(', ')}`\n );\n }\n};\n"],"names":["APIError","getPermissions","isCMSUser","forbid","message","undefined","assertNotSelf","req","userID","payload","user","String","id","assertCanGrant","keys","length","held","missing","filter","key","has","join"],"mappings":"AAEA,SAASA,QAAQ,QAAQ,UAAU;AAEnC,SAASC,cAAc,EAAEC,SAAS,QAAQ,cAAc;AAExD,MAAMC,SAAS,CAACC,UAAoB,IAAIJ,SAASI,SAAS,KAAKC,WAAW;AAE1E,gDAAgD,GAChD,OAAO,MAAMC,gBAAgB,CAACC,KAAqBC;IACjD,IACEN,UAAUK,IAAIE,OAAO,EAAEF,IAAIG,IAAI,KAC/BC,OAAOJ,IAAIG,IAAI,CAACE,EAAE,MAAMD,OAAOH,SAC/B;QACA,MAAML,OAAO;IACf;AACF,EAAE;AAEF,2DAA2D,GAC3D,OAAO,MAAMU,iBAAiB,OAAON,KAAqBO;IACxD,IAAI,CAACZ,UAAUK,IAAIE,OAAO,EAAEF,IAAIG,IAAI,KAAK,CAACI,KAAKC,MAAM,EAAE;QACrD;IACF;IACA,MAAMC,OAAO,MAAMf,eAAeM;IAClC,MAAMU,UAAUH,KAAKI,MAAM,CAACC,CAAAA,MAAO,CAACH,KAAKI,GAAG,CAACD;IAC7C,IAAIF,QAAQF,MAAM,EAAE;QAClB,MAAMZ,OACJ,CAAC,4CAA4C,EAAEc,QAAQI,IAAI,CAAC,OAAO;IAEvE;AACF,EAAE"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { CollectionSlug } from 'payload'
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { CollectionSlug } from 'payload';\n\nexport type StandardAction = 'create' | 'delete' | 'edit' | 'publish' | 'read';\n\n/**\n * A section of the CMS. Usually maps to a collection or global, sometimes to a\n * custom feature with only custom actions (e.g. CRM resends).\n */\nexport type AreaConfig = {\n /**\n * Standard actions this area exposes. Defaults to every action the mapped\n * collection/global supports (publish only when drafts are enabled), or none\n * for an unmapped area. An action left out is denied for CMS users.\n */\n actions?: StandardAction[];\n /** Collection whose access this area controls. */\n collection?: string;\n /** Extra non-CRUD actions, keyed by action slug, e.g. `{ resend: 'Resend CRM sends' }`. */\n customActions?: Record<string, string>;\n /** Global whose access this area controls. */\n global?: string;\n /** Defaults to the slug. */\n label?: string;\n /** First half of every permission key in this area; must not contain a dot. */\n slug: string;\n};\n\nexport type PermissionsPluginConfig = {\n /** The areas this site has. Only these show up in the matrix. */\n areas?: AreaConfig[];\n disabled?: boolean;\n /**\n * Umi staff. Super admins hold every permission and sit outside roles and\n * overrides, so they can't be locked out through the UI. Defaults to nobody.\n */\n isSuperAdmin?: (user: Record<string, unknown>) => boolean;\n};\n\nexport type Permission = {\n action: string;\n area: string;\n /** `area.action` */\n key: string;\n label: string;\n};\n\nexport type Area = {\n label: string;\n permissions: Permission[];\n slug: string;\n};\n\nexport type OverrideEffect = 'allow' | 'deny';\n\nexport type Override = {\n effect: OverrideEffect;\n id?: number | string;\n permission: string;\n};\n\n/** What the plugin stores on `config.custom.permissions` for runtime helpers. */\nexport type PluginState = {\n isSuperAdmin: (user: Record<string, unknown>) => boolean;\n keys: string[];\n registry: Area[];\n usersSlug: CollectionSlug;\n};\n"],"names":[],"mappings":"AA4DA,+EAA+E,GAC/E,WAKE"}
|
package/dist/users.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getOverrides, getRolePermissions, hasPermission, isCMSUser, markActive, OVERRIDES_SLUG,
|
|
1
|
+
import { getOverrides, getRolePermissions, hasPermission, isCMSUser, markActive, OVERRIDES_SLUG, ROLES_SLUG, relationID } from './access.js';
|
|
2
2
|
import { PART_OF_CHANGE, writeAudit } from './audit.js';
|
|
3
3
|
import { MANAGE_PERMISSION } from './registry.js';
|
|
4
4
|
import { redundantOverrides } from './resolve.js';
|
package/dist/users.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/users.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload'
|
|
1
|
+
{"version":3,"sources":["../src/users.ts"],"sourcesContent":["import type { CollectionConfig } from 'payload';\n\nimport {\n getOverrides,\n getRolePermissions,\n hasPermission,\n isCMSUser,\n markActive,\n OVERRIDES_SLUG,\n ROLES_SLUG,\n relationID,\n} from './access.js';\nimport { PART_OF_CHANGE, writeAudit } from './audit.js';\nimport { MANAGE_PERMISSION } from './registry.js';\nimport { redundantOverrides } from './resolve.js';\nimport { assertCanGrant, assertNotSelf } from './rules.js';\n\nconst roleName = async (\n req: Parameters<typeof writeAudit>[0],\n id: null | number | string\n) => {\n if (id === null) {\n return null;\n }\n const { docs } = await req.payload.find({\n collection: ROLES_SLUG,\n depth: 0,\n limit: 1,\n overrideAccess: true,\n req,\n where: { id: { equals: id } },\n });\n return (docs[0]?.name as string | undefined) ?? null;\n};\n\n/** Adds the role field, last-active stamp and role-change rules to the users collection. */\nexport const extendUsersCollection = (\n users: CollectionConfig\n): CollectionConfig => {\n for (const name of ['role', 'lastActiveAt']) {\n if (users.fields.some(field => 'name' in field && field.name === name)) {\n throw new Error(\n `permissions: the \"${users.slug}\" collection already has a \"${name}\" field`\n );\n }\n }\n\n return {\n ...users,\n fields: [\n ...users.fields,\n {\n name: 'role',\n type: 'relationship',\n access: {\n create: ({ req }) => hasPermission(req, MANAGE_PERMISSION),\n update: async ({ id, req }) =>\n !(\n isCMSUser(req.payload, req.user) &&\n String(req.user.id) === String(id)\n ) && hasPermission(req, MANAGE_PERMISSION),\n },\n admin: { position: 'sidebar' },\n index: true,\n relationTo: ROLES_SLUG,\n },\n {\n name: 'lastActiveAt',\n type: 'date',\n admin: {\n date: { pickerAppearance: 'dayAndTime' },\n description: 'Last login or edit.',\n position: 'sidebar',\n readOnly: true,\n },\n },\n ],\n hooks: {\n ...users.hooks,\n // The override's user is required, so the database can't just null it out.\n afterChange: [\n ...(users.hooks?.afterChange ?? []),\n async ({ doc, operation, previousDoc, req }) => {\n const was =\n operation === 'create' ? null : relationID(previousDoc?.role);\n const now = relationID(doc.role);\n if (String(was) === String(now)) {\n return;\n }\n\n const rolePermissions = await getRolePermissions(\n req.payload,\n now,\n req\n );\n const dropped = redundantOverrides(\n await getOverrides(req.payload, doc.id, req),\n rolePermissions\n );\n if (dropped.length) {\n await req.payload.delete({\n collection: OVERRIDES_SLUG,\n context: { [PART_OF_CHANGE]: true },\n overrideAccess: true,\n req,\n where: { id: { in: dropped.map(o => o.id) } },\n });\n }\n\n const fromName = await roleName(req, was);\n const toName = await roleName(req, now);\n await writeAudit(req, {\n action: 'user.role',\n after: {\n droppedOverrides: dropped.map(({ effect, permission }) => ({\n effect,\n permission,\n })),\n role: toName,\n },\n before: { role: fromName },\n role: now,\n summary: `Role changed from ${fromName ?? 'none'} to ${toName ?? 'none'}`,\n user: doc.id,\n });\n },\n ],\n afterLogin: [\n ...(users.hooks?.afterLogin ?? []),\n ({ req, user }) => markActive(req, { ...user, collection: users.slug }),\n ],\n beforeChange: [\n ...(users.hooks?.beforeChange ?? []),\n async ({ data, originalDoc, req }) => {\n if (data.role === undefined) {\n return data;\n }\n const now = relationID(data.role);\n if (String(relationID(originalDoc?.role)) === String(now)) {\n return data;\n }\n if (originalDoc) {\n assertNotSelf(req, originalDoc.id);\n }\n if (isCMSUser(req.payload, req.user)) {\n // Read outside the transaction: Payload runs beforeChange work concurrently\n // and Mongo rejects parallel operations racing to start a transaction.\n await assertCanGrant(\n req,\n await getRolePermissions(req.payload, now)\n );\n }\n return data;\n },\n ],\n beforeDelete: [\n ...(users.hooks?.beforeDelete ?? []),\n async ({ id, req }) => {\n await req.payload.delete({\n collection: OVERRIDES_SLUG,\n context: { [PART_OF_CHANGE]: true },\n overrideAccess: true,\n req,\n where: { user: { equals: id } },\n });\n },\n ],\n },\n };\n};\n"],"names":["getOverrides","getRolePermissions","hasPermission","isCMSUser","markActive","OVERRIDES_SLUG","ROLES_SLUG","relationID","PART_OF_CHANGE","writeAudit","MANAGE_PERMISSION","redundantOverrides","assertCanGrant","assertNotSelf","roleName","req","id","docs","payload","find","collection","depth","limit","overrideAccess","where","equals","name","extendUsersCollection","users","fields","some","field","Error","slug","type","access","create","update","user","String","admin","position","index","relationTo","date","pickerAppearance","description","readOnly","hooks","afterChange","doc","operation","previousDoc","was","role","now","rolePermissions","dropped","length","delete","context","in","map","o","fromName","toName","action","after","droppedOverrides","effect","permission","before","summary","afterLogin","beforeChange","data","originalDoc","undefined","beforeDelete"],"mappings":"AAEA,SACEA,YAAY,EACZC,kBAAkB,EAClBC,aAAa,EACbC,SAAS,EACTC,UAAU,EACVC,cAAc,EACdC,UAAU,EACVC,UAAU,QACL,cAAc;AACrB,SAASC,cAAc,EAAEC,UAAU,QAAQ,aAAa;AACxD,SAASC,iBAAiB,QAAQ,gBAAgB;AAClD,SAASC,kBAAkB,QAAQ,eAAe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ragment } from "react/jsx-run
|
|
|
2
2
|
import { DefaultTemplate } from '@payloadcms/next/templates';
|
|
3
3
|
import { Gutter, Link } from '@payloadcms/ui';
|
|
4
4
|
import { redirect } from 'next/navigation.js';
|
|
5
|
-
import React from 'react';
|
|
6
5
|
import { AUDIT_SLUG, hasPermission } from '../access.js';
|
|
7
6
|
import { MANAGE_PERMISSION } from '../registry.js';
|
|
8
7
|
import '../components/index.scss';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/views/PermissionsLayout.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../src/views/PermissionsLayout.tsx"],"sourcesContent":["import { DefaultTemplate } from '@payloadcms/next/templates';\nimport { Gutter, Link } from '@payloadcms/ui';\nimport { redirect } from 'next/navigation.js';\nimport type { AdminViewServerProps } from 'payload';\nimport type React from 'react';\n\nimport { AUDIT_SLUG, hasPermission } from '../access.js';\nimport { MANAGE_PERMISSION } from '../registry.js';\nimport '../components/index.scss';\n\ntype Props = {\n /** Only called once the viewer is allowed in, so no data loads otherwise. */\n render: () => Promise<React.ReactNode>;\n tab: 'roles' | 'users';\n} & AdminViewServerProps;\n\n/** Admin chrome, tabs and the permissions.manage check shared by both views. */\nexport const PermissionsLayout = async ({\n initPageResult,\n params,\n render,\n searchParams,\n tab,\n}: Props) => {\n const { req } = initPageResult;\n const adminRoute = req.payload.config.routes.admin;\n if (!req.user) {\n redirect(`${adminRoute}/login`);\n }\n const allowed = await hasPermission(req, MANAGE_PERMISSION);\n\n const tabs = [\n { href: `${adminRoute}/permissions`, key: 'roles', label: 'Roles' },\n { href: `${adminRoute}/permissions/users`, key: 'users', label: 'Users' },\n {\n href: `${adminRoute}/collections/${AUDIT_SLUG}`,\n key: 'audit',\n label: 'Audit log',\n },\n ];\n\n return (\n <DefaultTemplate\n i18n={req.i18n}\n locale={initPageResult.locale}\n params={params}\n payload={req.payload}\n permissions={initPageResult.permissions}\n searchParams={searchParams}\n user={req.user ?? undefined}\n visibleEntities={initPageResult.visibleEntities}\n >\n <Gutter className='perm'>\n <h1>Permissions</h1>\n {allowed ? (\n <>\n <nav className='perm__tabs'>\n {tabs.map(t => (\n <Link\n aria-current={t.key === tab ? 'page' : undefined}\n className='perm__tab'\n href={t.href}\n key={t.key}\n >\n {t.label}\n </Link>\n ))}\n </nav>\n {await render()}\n </>\n ) : (\n <p>You don't have permission to manage roles and permissions.</p>\n )}\n </Gutter>\n </DefaultTemplate>\n );\n};\n"],"names":["DefaultTemplate","Gutter","Link","redirect","AUDIT_SLUG","hasPermission","MANAGE_PERMISSION","PermissionsLayout","initPageResult","params","render","searchParams","tab","req","adminRoute","payload","config","routes","admin","user","allowed","tabs","href","key","label","i18n","locale","permissions","undefined","visibleEntities","className","h1","nav","map","t","aria-current","p"],"mappings":";AAAA,SAASA,eAAe,QAAQ,6BAA6B;AAC7D,SAASC,MAAM,EAAEC,IAAI,QAAQ,iBAAiB;AAC9C,SAASC,QAAQ,QAAQ,qBAAqB;AAI9C,SAASC,UAAU,EAAEC,aAAa,QAAQ,eAAe;AACzD,SAASC,iBAAiB,QAAQ,iBAAiB;AACnD,OAAO,2BAA2B;AAQlC,8EAA8E,GAC9E,OAAO,MAAMC,oBAAoB,OAAO,EACtCC,cAAc,EACdC,MAAM,EACNC,MAAM,EACNC,YAAY,EACZC,GAAG,EACG;IACN,MAAM,EAAEC,GAAG,EAAE,GAAGL;IAChB,MAAMM,aAAaD,IAAIE,OAAO,CAACC,MAAM,CAACC,MAAM,CAACC,KAAK;IAClD,IAAI,CAACL,IAAIM,IAAI,EAAE;QACbhB,SAAS,GAAGW,WAAW,MAAM,CAAC;IAChC;IACA,MAAMM,UAAU,MAAMf,cAAcQ,KAAKP;IAEzC,MAAMe,OAAO;QACX;YAAEC,MAAM,GAAGR,WAAW,YAAY,CAAC;YAAES,KAAK;YAASC,OAAO;QAAQ;QAClE;YAAEF,MAAM,GAAGR,WAAW,kBAAkB,CAAC;YAAES,KAAK;YAASC,OAAO;QAAQ;QACxE;YACEF,MAAM,GAAGR,WAAW,aAAa,EAAEV,YAAY;YAC/CmB,KAAK;YACLC,OAAO;QACT;KACD;IAED,qBACE,KAACxB;QACCyB,MAAMZ,IAAIY,IAAI;QACdC,QAAQlB,eAAekB,MAAM;QAC7BjB,QAAQA;QACRM,SAASF,IAAIE,OAAO;QACpBY,aAAanB,eAAemB,WAAW;QACvChB,cAAcA;QACdQ,MAAMN,IAAIM,IAAI,IAAIS;QAClBC,iBAAiBrB,eAAeqB,eAAe;kBAE/C,cAAA,MAAC5B;YAAO6B,WAAU;;8BAChB,KAACC;8BAAG;;gBACHX,wBACC;;sCACE,KAACY;4BAAIF,WAAU;sCACZT,KAAKY,GAAG,CAACC,CAAAA,kBACR,KAAChC;oCACCiC,gBAAcD,EAAEX,GAAG,KAAKX,MAAM,SAASgB;oCACvCE,WAAU;oCACVR,MAAMY,EAAEZ,IAAI;8CAGXY,EAAEV,KAAK;mCAFHU,EAAEX,GAAG;;wBAMf,MAAMb;;mCAGT,KAAC0B;8BAAE;;;;;AAKb,EAAE"}
|
package/dist/views/RolesView.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createElement as _createElement } from "react";
|
|
3
|
-
import React from 'react';
|
|
4
3
|
import { RolesMatrix } from '../components/RolesMatrix.js';
|
|
5
4
|
import { loadViewData } from './data.js';
|
|
6
5
|
import { PermissionsLayout } from './PermissionsLayout.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/views/RolesView.tsx"],"sourcesContent":["import type { AdminViewServerProps } from 'payload'
|
|
1
|
+
{"version":3,"sources":["../../src/views/RolesView.tsx"],"sourcesContent":["import type { AdminViewServerProps } from 'payload';\n\nimport { RolesMatrix } from '../components/RolesMatrix.js';\nimport { loadViewData } from './data.js';\nimport { PermissionsLayout } from './PermissionsLayout.js';\n\nexport const RolesView = (props: AdminViewServerProps) => (\n <PermissionsLayout\n {...props}\n render={async () => {\n const data = await loadViewData(props.initPageResult.req);\n // Keyed on the saved roles so a refresh after saving resets the draft.\n return <RolesMatrix {...data} key={JSON.stringify(data.roles)} />;\n }}\n tab='roles'\n />\n);\n"],"names":["RolesMatrix","loadViewData","PermissionsLayout","RolesView","props","render","data","initPageResult","req","key","JSON","stringify","roles","tab"],"mappings":";;AAEA,SAASA,WAAW,QAAQ,+BAA+B;AAC3D,SAASC,YAAY,QAAQ,YAAY;AACzC,SAASC,iBAAiB,QAAQ,yBAAyB;AAE3D,OAAO,MAAMC,YAAY,CAACC,sBACxB,KAACF;QACE,GAAGE,KAAK;QACTC,QAAQ;YACN,MAAMC,OAAO,MAAML,aAAaG,MAAMG,cAAc,CAACC,GAAG;YACxD,uEAAuE;YACvE,qBAAO,eAACR;gBAAa,GAAGM,IAAI;gBAAEG,KAAKC,KAAKC,SAAS,CAACL,KAAKM,KAAK;;QAC9D;QACAC,KAAI;OAEN"}
|
package/dist/views/UsersView.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/views/UsersView.tsx"],"sourcesContent":["import type { AdminViewServerProps } from 'payload'
|
|
1
|
+
{"version":3,"sources":["../../src/views/UsersView.tsx"],"sourcesContent":["import type { AdminViewServerProps } from 'payload';\n\nimport { UsersTable } from '../components/UsersTable.js';\nimport { loadViewData } from './data.js';\nimport { PermissionsLayout } from './PermissionsLayout.js';\n\nexport const UsersView = (props: AdminViewServerProps) => (\n <PermissionsLayout\n {...props}\n render={async () => (\n <UsersTable {...(await loadViewData(props.initPageResult.req))} />\n )}\n tab='users'\n />\n);\n"],"names":["UsersTable","loadViewData","PermissionsLayout","UsersView","props","render","initPageResult","req","tab"],"mappings":";AAEA,SAASA,UAAU,QAAQ,8BAA8B;AACzD,SAASC,YAAY,QAAQ,YAAY;AACzC,SAASC,iBAAiB,QAAQ,yBAAyB;AAE3D,OAAO,MAAMC,YAAY,CAACC,sBACxB,KAACF;QACE,GAAGE,KAAK;QACTC,QAAQ,wBACN,KAACL;gBAAY,GAAI,MAAMC,aAAaG,MAAME,cAAc,CAACC,GAAG,CAAC;;QAE/DC,KAAI;OAEN"}
|
package/dist/views/data.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getPermissions, getState, OVERRIDES_SLUG,
|
|
1
|
+
import { getPermissions, getState, OVERRIDES_SLUG, ROLES_SLUG, relationID } from '../access.js';
|
|
2
2
|
export const loadViewData = async (req)=>{
|
|
3
3
|
const { payload } = req;
|
|
4
4
|
const { isSuperAdmin, registry, usersSlug } = getState(payload);
|
package/dist/views/data.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/views/data.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'
|
|
1
|
+
{"version":3,"sources":["../../src/views/data.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload';\nimport {\n getPermissions,\n getState,\n OVERRIDES_SLUG,\n ROLES_SLUG,\n relationID,\n} from '../access.js';\nimport type { Area, OverrideEffect } from '../types.js';\n\ntype ID = number | string;\n\nexport type ViewRole = { id: ID; name: string; permissions: string[] };\n\nexport type ViewUser = {\n email: string;\n id: ID;\n label: string;\n lastActiveAt: null | string;\n role: ID | null;\n superAdmin: boolean;\n};\n\nexport type ViewOverride = {\n effect: OverrideEffect;\n id: ID;\n permission: string;\n user: ID;\n};\n\n/** Everything the permissions views need, serialisable for client components. */\nexport type ViewData = {\n adminRoute: string;\n apiRoute: string;\n currentUserID: ID;\n /** Permissions the viewer holds, and so can grant. */\n held: string[];\n overrides: ViewOverride[];\n registry: Area[];\n roles: ViewRole[];\n users: ViewUser[];\n};\n\nexport const loadViewData = async (req: PayloadRequest): Promise<ViewData> => {\n const { payload } = req;\n const { isSuperAdmin, registry, usersSlug } = getState(payload);\n const titleField =\n payload.collections[usersSlug].config.admin.useAsTitle ?? 'id';\n const all = {\n depth: 0,\n overrideAccess: true,\n pagination: false,\n req,\n } as const;\n\n const roles = await payload.find({\n ...all,\n collection: ROLES_SLUG,\n sort: 'name',\n });\n const users = await payload.find({ ...all, collection: usersSlug });\n const overrides = await payload.find({ ...all, collection: OVERRIDES_SLUG });\n\n return {\n adminRoute: payload.config.routes.admin,\n apiRoute: `${payload.config.serverURL}${payload.config.routes.api}`,\n currentUserID: req.user!.id,\n held: [...(await getPermissions(req))],\n overrides: overrides.docs.map(o => ({\n id: o.id,\n effect: o.effect as OverrideEffect,\n permission: o.permission as string,\n user: relationID(o.user)!,\n })),\n registry,\n roles: roles.docs.map(r => ({\n id: r.id,\n name: r.name as string,\n permissions: (r.permissions as string[] | undefined) ?? [],\n })),\n users: (users.docs as unknown as Record<string, unknown>[]).map(u => ({\n id: u.id as ID,\n email: u.email as string,\n label: String((titleField !== 'id' && u[titleField]) || u.email),\n lastActiveAt: (u.lastActiveAt as null | string) ?? null,\n role: relationID(u.role),\n superAdmin: isSuperAdmin({ ...u, collection: usersSlug }),\n })),\n };\n};\n"],"names":["getPermissions","getState","OVERRIDES_SLUG","ROLES_SLUG","relationID","loadViewData","req","payload","isSuperAdmin","registry","usersSlug","titleField","collections","config","admin","useAsTitle","all","depth","overrideAccess","pagination","roles","find","collection","sort","users","overrides","adminRoute","routes","apiRoute","serverURL","api","currentUserID","user","id","held","docs","map","o","effect","permission","r","name","permissions","u","email","label","String","lastActiveAt","role","superAdmin"],"mappings":"AACA,SACEA,cAAc,EACdC,QAAQ,EACRC,cAAc,EACdC,UAAU,EACVC,UAAU,QACL,eAAe;AAoCtB,OAAO,MAAMC,eAAe,OAAOC;IACjC,MAAM,EAAEC,OAAO,EAAE,GAAGD;IACpB,MAAM,EAAEE,YAAY,EAAEC,QAAQ,EAAEC,SAAS,EAAE,GAAGT,SAASM;IACvD,MAAMI,aACJJ,QAAQK,WAAW,CAACF,UAAU,CAACG,MAAM,CAACC,KAAK,CAACC,UAAU,IAAI;IAC5D,MAAMC,MAAM;QACVC,OAAO;QACPC,gBAAgB;QAChBC,YAAY;QACZb;I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aAAa;oBAAE,GAAGmC,CAAC;oBAAErB,YAAYZ;gBAAU;YACzD,CAAA;IACF;AACF,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foundrykit/permissions-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Granular permissions for Payload CMS 3: area.action permissions, editable roles, per-user overrides and an audit log",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/umi-labs/
|
|
8
|
+
"url": "git+https://github.com/umi-labs/foundry.git",
|
|
9
|
+
"directory": "packages/payload/permissions-plugin"
|
|
9
10
|
},
|
|
10
11
|
"type": "module",
|
|
11
12
|
"exports": {
|
|
@@ -30,37 +31,11 @@
|
|
|
30
31
|
"files": [
|
|
31
32
|
"dist"
|
|
32
33
|
],
|
|
33
|
-
"scripts": {
|
|
34
|
-
"build": "pnpm copyfiles && pnpm build:types && pnpm build:swc",
|
|
35
|
-
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths --ignore \"**/*.test.ts\"",
|
|
36
|
-
"build:types": "tsc --outDir dist --rootDir ./src",
|
|
37
|
-
"clean": "rimraf {dist,*.tsbuildinfo}",
|
|
38
|
-
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
|
|
39
|
-
"dev": "next dev dev --turbo",
|
|
40
|
-
"dev:generate-importmap": "pnpm dev:payload generate:importmap",
|
|
41
|
-
"dev:generate-types": "pnpm dev:payload generate:types",
|
|
42
|
-
"dev:payload": "cross-env PAYLOAD_CONFIG_PATH=./dev/payload.config.ts payload",
|
|
43
|
-
"generate:importmap": "pnpm dev:generate-importmap",
|
|
44
|
-
"generate:types": "pnpm dev:generate-types",
|
|
45
|
-
"lint": "eslint",
|
|
46
|
-
"lint:fix": "eslint ./src --fix",
|
|
47
|
-
"prepublishOnly": "pnpm build && node scripts/verify-pack.mjs",
|
|
48
|
-
"verify:pack": "node scripts/verify-pack.mjs",
|
|
49
|
-
"release": "release-it",
|
|
50
|
-
"release:dry": "release-it --dry-run",
|
|
51
|
-
"test": "pnpm test:unit && pnpm test:int && pnpm test:e2e",
|
|
52
|
-
"test:unit": "vitest run src",
|
|
53
|
-
"test:e2e": "playwright test",
|
|
54
|
-
"test:int": "vitest run dev/int.spec.ts"
|
|
55
|
-
},
|
|
56
34
|
"devDependencies": {
|
|
57
|
-
"@eslint/eslintrc": "^3.2.0",
|
|
58
35
|
"@payloadcms/db-mongodb": "3.84.1",
|
|
59
|
-
"@payloadcms/eslint-config": "3.28.0",
|
|
60
36
|
"@payloadcms/next": "3.84.1",
|
|
61
37
|
"@payloadcms/ui": "3.84.1",
|
|
62
38
|
"@playwright/test": "1.58.2",
|
|
63
|
-
"@release-it/conventional-changelog": "^11.0.0",
|
|
64
39
|
"@swc-node/register": "1.10.9",
|
|
65
40
|
"@swc/cli": "0.6.0",
|
|
66
41
|
"@types/node": "22.19.9",
|
|
@@ -68,21 +43,17 @@
|
|
|
68
43
|
"@types/react-dom": "19.2.3",
|
|
69
44
|
"copyfiles": "2.4.1",
|
|
70
45
|
"cross-env": "^7.0.3",
|
|
71
|
-
"eslint": "^9.23.0",
|
|
72
|
-
"eslint-config-next": "16.2.6",
|
|
73
46
|
"graphql": "^16.8.1",
|
|
74
47
|
"mongodb-memory-server": "10.1.4",
|
|
75
48
|
"next": "16.2.6",
|
|
76
49
|
"payload": "3.84.1",
|
|
77
|
-
"prettier": "^3.4.2",
|
|
78
50
|
"react": "19.2.6",
|
|
79
51
|
"react-dom": "19.2.6",
|
|
80
|
-
"release-it": "^20.0.1",
|
|
81
52
|
"rimraf": "3.0.2",
|
|
82
53
|
"sharp": "0.34.2",
|
|
83
|
-
"typescript": "5.
|
|
54
|
+
"typescript": "5.9.2",
|
|
84
55
|
"vite-tsconfig-paths": "6.0.5",
|
|
85
|
-
"vitest": "4.
|
|
56
|
+
"vitest": "4.1.10"
|
|
86
57
|
},
|
|
87
58
|
"peerDependencies": {
|
|
88
59
|
"@payloadcms/next": "^3.84.1",
|
|
@@ -92,18 +63,31 @@
|
|
|
92
63
|
"react": "^19"
|
|
93
64
|
},
|
|
94
65
|
"engines": {
|
|
95
|
-
"node": "
|
|
96
|
-
"pnpm": "^9 || ^10"
|
|
66
|
+
"node": ">=20.9.0"
|
|
97
67
|
},
|
|
98
68
|
"publishConfig": {
|
|
99
69
|
"access": "public"
|
|
100
70
|
},
|
|
101
|
-
"
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
"esbuild",
|
|
105
|
-
"unrs-resolver"
|
|
106
|
-
]
|
|
71
|
+
"homepage": "https://github.com/umi-labs/foundry/tree/prod/packages/payload/permissions-plugin#readme",
|
|
72
|
+
"bugs": {
|
|
73
|
+
"url": "https://github.com/umi-labs/foundry/issues"
|
|
107
74
|
},
|
|
108
|
-
"
|
|
109
|
-
|
|
75
|
+
"scripts": {
|
|
76
|
+
"build": "pnpm copyfiles && pnpm build:types && pnpm build:swc",
|
|
77
|
+
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths --ignore \"**/*.test.ts\"",
|
|
78
|
+
"build:types": "tsc --outDir dist --rootDir ./src",
|
|
79
|
+
"clean": "rimraf {dist,*.tsbuildinfo}",
|
|
80
|
+
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
|
|
81
|
+
"dev": "next dev dev --turbo",
|
|
82
|
+
"dev:generate-importmap": "pnpm dev:payload generate:importmap",
|
|
83
|
+
"dev:generate-types": "pnpm dev:payload generate:types",
|
|
84
|
+
"dev:payload": "cross-env PAYLOAD_CONFIG_PATH=./dev/payload.config.ts payload",
|
|
85
|
+
"generate:importmap": "pnpm dev:generate-importmap",
|
|
86
|
+
"generate:types": "pnpm dev:generate-types",
|
|
87
|
+
"verify:pack": "node scripts/verify-pack.mjs",
|
|
88
|
+
"test": "pnpm test:unit && pnpm test:int",
|
|
89
|
+
"test:unit": "vitest run src",
|
|
90
|
+
"test:e2e": "playwright test",
|
|
91
|
+
"test:int": "vitest run dev/int.spec.ts"
|
|
92
|
+
}
|
|
93
|
+
}
|