payload-access-plugin 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +220 -2
- package/dist/access/can.d.ts +3 -0
- package/dist/access/can.js +10 -0
- package/dist/access/can.js.map +1 -0
- package/dist/access/combine.d.ts +6 -0
- package/dist/access/combine.js +23 -0
- package/dist/access/combine.js.map +1 -0
- package/dist/access/fields.d.ts +7 -0
- package/dist/access/fields.js +41 -0
- package/dist/access/fields.js.map +1 -0
- package/dist/access/load.d.ts +6 -0
- package/dist/access/load.js +22 -0
- package/dist/access/load.js.map +1 -0
- package/dist/access/manage.d.ts +9 -0
- package/dist/access/manage.js +8 -0
- package/dist/access/manage.js.map +1 -0
- package/dist/access/resolve.d.ts +22 -0
- package/dist/access/resolve.js +106 -0
- package/dist/access/resolve.js.map +1 -0
- package/dist/access/wrap.d.ts +6 -0
- package/dist/access/wrap.js +120 -0
- package/dist/access/wrap.js.map +1 -0
- package/dist/admin/AccessView.d.ts +3 -0
- package/dist/admin/AccessView.js +66 -0
- package/dist/admin/AccessView.js.map +1 -0
- package/dist/admin/Matrix.d.ts +10 -0
- package/dist/admin/Matrix.js +383 -0
- package/dist/admin/Matrix.js.map +1 -0
- package/dist/admin/MatrixCell.d.ts +17 -0
- package/dist/admin/MatrixCell.js +42 -0
- package/dist/admin/MatrixCell.js.map +1 -0
- package/dist/admin/MatrixFilters.d.ts +18 -0
- package/dist/admin/MatrixFilters.js +91 -0
- package/dist/admin/MatrixFilters.js.map +1 -0
- package/dist/admin/NavLink.d.ts +3 -0
- package/dist/admin/NavLink.js +23 -0
- package/dist/admin/NavLink.js.map +1 -0
- package/dist/admin/NavLinkClient.d.ts +9 -0
- package/dist/admin/NavLinkClient.js +36 -0
- package/dist/admin/NavLinkClient.js.map +1 -0
- package/dist/admin/NewRoleDrawer.d.ts +14 -0
- package/dist/admin/NewRoleDrawer.js +226 -0
- package/dist/admin/NewRoleDrawer.js.map +1 -0
- package/dist/admin/RoleGrid.d.ts +21 -0
- package/dist/admin/RoleGrid.js +141 -0
- package/dist/admin/RoleGrid.js.map +1 -0
- package/dist/admin/RolePermissionsField.d.ts +17 -0
- package/dist/admin/RolePermissionsField.js +96 -0
- package/dist/admin/RolePermissionsField.js.map +1 -0
- package/dist/admin/css.d.js +2 -0
- package/dist/admin/css.d.js.map +1 -0
- package/dist/admin/model.d.ts +58 -0
- package/dist/admin/model.js +166 -0
- package/dist/admin/model.js.map +1 -0
- package/dist/admin/steps/FieldsGlobalsStep.d.ts +2 -0
- package/dist/admin/steps/FieldsGlobalsStep.js +21 -0
- package/dist/admin/steps/FieldsGlobalsStep.js.map +1 -0
- package/dist/admin/steps/NameStep.d.ts +7 -0
- package/dist/admin/steps/NameStep.js +74 -0
- package/dist/admin/steps/NameStep.js.map +1 -0
- package/dist/admin/steps/PermissionsStep.d.ts +2 -0
- package/dist/admin/steps/PermissionsStep.js +21 -0
- package/dist/admin/steps/PermissionsStep.js.map +1 -0
- package/dist/admin/steps/ReviewStep.d.ts +6 -0
- package/dist/admin/steps/ReviewStep.js +85 -0
- package/dist/admin/steps/ReviewStep.js.map +1 -0
- package/dist/admin/steps/StartFromStep.d.ts +10 -0
- package/dist/admin/steps/StartFromStep.js +63 -0
- package/dist/admin/steps/StartFromStep.js.map +1 -0
- package/dist/admin/steps/types.d.ts +18 -0
- package/dist/admin/steps/types.js +3 -0
- package/dist/admin/steps/types.js.map +1 -0
- package/dist/admin/styles.module.css +289 -0
- package/dist/collections/roles.d.ts +3 -0
- package/dist/collections/roles.js +80 -0
- package/dist/collections/roles.js.map +1 -0
- package/dist/core/decide.d.ts +3 -0
- package/dist/core/decide.js +9 -0
- package/dist/core/decide.js.map +1 -0
- package/dist/core/locks.d.ts +7 -0
- package/dist/core/locks.js +57 -0
- package/dist/core/locks.js.map +1 -0
- package/dist/core/merge.d.ts +4 -0
- package/dist/core/merge.js +64 -0
- package/dist/core/merge.js.map +1 -0
- package/dist/core/types.d.ts +34 -0
- package/dist/core/types.js +4 -0
- package/dist/core/types.js.map +1 -0
- package/dist/endpoints/me.d.ts +13 -0
- package/dist/endpoints/me.js +55 -0
- package/dist/endpoints/me.js.map +1 -0
- package/dist/endpoints/schema.d.ts +14 -0
- package/dist/endpoints/schema.js +39 -0
- package/dist/endpoints/schema.js.map +1 -0
- package/dist/exports/client.d.ts +7 -0
- package/dist/exports/client.js +9 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/rsc.d.ts +2 -0
- package/dist/exports/rsc.js +4 -0
- package/dist/exports/rsc.js.map +1 -0
- package/dist/fields/owner.d.ts +7 -0
- package/dist/fields/owner.js +32 -0
- package/dist/fields/owner.js.map +1 -0
- package/dist/fields/userRoles.d.ts +3 -0
- package/dist/fields/userRoles.js +17 -0
- package/dist/fields/userRoles.js.map +1 -0
- package/dist/hooks/guardrails.d.ts +17 -0
- package/dist/hooks/guardrails.js +255 -0
- package/dist/hooks/guardrails.js.map +1 -0
- package/dist/i18n.d.ts +74 -0
- package/dist/i18n.js +76 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +122 -0
- package/dist/index.js.map +1 -0
- package/dist/options.d.ts +45 -0
- package/dist/options.js +203 -0
- package/dist/options.js.map +1 -0
- package/dist/schema.d.ts +6 -0
- package/dist/schema.js +78 -0
- package/dist/schema.js.map +1 -0
- package/dist/seed.d.ts +4 -0
- package/dist/seed.js +35 -0
- package/dist/seed.js.map +1 -0
- package/dist/slug.d.ts +3 -0
- package/dist/slug.js +3 -0
- package/dist/slug.js.map +1 -0
- package/dist/types.d.ts +66 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +113 -4
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { APIError } from 'payload';
|
|
2
|
+
import { idsOf, loadRoles } from '../access/load.js';
|
|
3
|
+
import { canManageRoles, isSuperAdmin } from '../access/manage.js';
|
|
4
|
+
import { asCollection } from '../slug.js';
|
|
5
|
+
const refuse = (message)=>{
|
|
6
|
+
throw new APIError(message, 403);
|
|
7
|
+
};
|
|
8
|
+
const sameIds = (a, b)=>{
|
|
9
|
+
const left = a.map(String).sort();
|
|
10
|
+
const right = b.map(String).sort();
|
|
11
|
+
return left.length === right.length && left.every((id, i)=>id === right[i]);
|
|
12
|
+
};
|
|
13
|
+
/** Guardrails on the roles collection. Kept on even when the plugin is disabled. */ export const roleGuardrails = (opts)=>{
|
|
14
|
+
const beforeChange = ({ data, operation, originalDoc })=>{
|
|
15
|
+
if (operation !== 'update') {
|
|
16
|
+
return data;
|
|
17
|
+
}
|
|
18
|
+
if (originalDoc?.locked) {
|
|
19
|
+
return refuse("This role is locked by the app and can't be changed here.");
|
|
20
|
+
}
|
|
21
|
+
return data;
|
|
22
|
+
};
|
|
23
|
+
const beforeDelete = async ({ id, req })=>{
|
|
24
|
+
const role = await req.payload.findByID({
|
|
25
|
+
id,
|
|
26
|
+
collection: asCollection(opts.rolesSlug),
|
|
27
|
+
depth: 0,
|
|
28
|
+
overrideAccess: true,
|
|
29
|
+
req
|
|
30
|
+
});
|
|
31
|
+
if (role.locked) {
|
|
32
|
+
refuse("This role is locked by the app and can't be changed here.");
|
|
33
|
+
}
|
|
34
|
+
let assigned = 0;
|
|
35
|
+
for (const slug of opts.usersSlugs){
|
|
36
|
+
const { totalDocs } = await req.payload.count({
|
|
37
|
+
collection: asCollection(slug),
|
|
38
|
+
overrideAccess: true,
|
|
39
|
+
req,
|
|
40
|
+
where: {
|
|
41
|
+
roles: {
|
|
42
|
+
contains: id
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
assigned += totalDocs;
|
|
47
|
+
}
|
|
48
|
+
if (assigned > 0) {
|
|
49
|
+
refuse(`This role is still assigned to ${assigned} users. Remove it from them first.`);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
return {
|
|
53
|
+
beforeChange: [
|
|
54
|
+
beforeChange
|
|
55
|
+
],
|
|
56
|
+
beforeDelete: [
|
|
57
|
+
beforeDelete
|
|
58
|
+
]
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
/** True when another user, in any users collection, holds a super-admin role. */ const anotherSuperAdmin = async (req, opts, exclude)=>{
|
|
62
|
+
for (const slug of opts.usersSlugs){
|
|
63
|
+
let page = 1;
|
|
64
|
+
for(;;){
|
|
65
|
+
const result = await req.payload.find({
|
|
66
|
+
collection: asCollection(slug),
|
|
67
|
+
depth: 1,
|
|
68
|
+
limit: 100,
|
|
69
|
+
overrideAccess: true,
|
|
70
|
+
page,
|
|
71
|
+
req,
|
|
72
|
+
...slug === exclude.slug && exclude.ids.length > 0 ? {
|
|
73
|
+
where: {
|
|
74
|
+
id: {
|
|
75
|
+
not_in: exclude.ids
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
} : {}
|
|
79
|
+
});
|
|
80
|
+
if (result.docs.some((user)=>opts.superAdmin(user))) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
if (!result.hasNextPage) {
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
page += 1;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Role-field slug guard: the slug is fixed once created. Runs before field access, which then
|
|
93
|
+
* makes the field read-only in the admin UI.
|
|
94
|
+
*/ export const slugGuard = ({ operation, originalDoc, value })=>{
|
|
95
|
+
if (operation === 'update' && typeof value === 'string' && value !== originalDoc?.slug) {
|
|
96
|
+
refuse("The slug of a role can't be changed.");
|
|
97
|
+
}
|
|
98
|
+
return value;
|
|
99
|
+
};
|
|
100
|
+
/** True when no user exists yet in any users collection (the create-first-user case). */ export const noUsersYet = async (req, opts)=>{
|
|
101
|
+
for (const slug of opts.usersSlugs){
|
|
102
|
+
// find, not count: MongoDB can't run an unfiltered count inside a transaction.
|
|
103
|
+
const { docs } = await req.payload.find({
|
|
104
|
+
collection: asCollection(slug),
|
|
105
|
+
depth: 0,
|
|
106
|
+
limit: 1,
|
|
107
|
+
overrideAccess: true,
|
|
108
|
+
pagination: false,
|
|
109
|
+
req
|
|
110
|
+
});
|
|
111
|
+
if (docs.length > 0) {
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return true;
|
|
116
|
+
};
|
|
117
|
+
const NO_SUPER_ADMIN = 'At least one user must keep a super-admin role.';
|
|
118
|
+
const GRANT_SUPER_ADMIN = 'Only a super admin can grant a super-admin role.';
|
|
119
|
+
// beforeChange cannot see overrideAccess, so beforeOperation records it on the request context.
|
|
120
|
+
const OVERRIDE_KEY = 'accessPluginOverrideAccess';
|
|
121
|
+
/** Seeds and other trusted calls (no user, or overrideAccess) may grant any role. */ const trusted = (req)=>!req.user || req.context[OVERRIDE_KEY] === true;
|
|
122
|
+
/** Refuses a roles change that makes a user a super admin, unless the actor is one. */ const requireSuperAdminToGrant = async (req, opts)=>{
|
|
123
|
+
if (!await isSuperAdmin(req, opts)) {
|
|
124
|
+
refuse(GRANT_SUPER_ADMIN);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const holdsSuperAdmin = async (req, opts, doc, roles)=>opts.superAdmin({
|
|
128
|
+
...doc,
|
|
129
|
+
roles: await loadRoles(req, opts, idsOf(roles))
|
|
130
|
+
});
|
|
131
|
+
/** Guardrails on a users collection: default roles and the last super admin. */ export const userGuardrails = (opts, slug)=>({
|
|
132
|
+
// Truly concurrent single-user demotions are a known limitation: each check sees the other
|
|
133
|
+
// still holding the role. Bulk operations are handled in beforeOperation.
|
|
134
|
+
beforeChange: async ({ data, operation, originalDoc, req })=>{
|
|
135
|
+
if (operation === 'create') {
|
|
136
|
+
if (idsOf(data.roles).length === 0 && opts.defaultRoles.length > 0) {
|
|
137
|
+
const { docs } = await req.payload.find({
|
|
138
|
+
collection: asCollection(opts.rolesSlug),
|
|
139
|
+
depth: 0,
|
|
140
|
+
overrideAccess: true,
|
|
141
|
+
pagination: false,
|
|
142
|
+
req,
|
|
143
|
+
where: {
|
|
144
|
+
slug: {
|
|
145
|
+
in: opts.defaultRoles
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
data.roles = docs.map((doc)=>doc.id);
|
|
150
|
+
}
|
|
151
|
+
if (!trusted(req) && idsOf(data.roles).length > 0 && await holdsSuperAdmin(req, opts, data, data.roles)) {
|
|
152
|
+
await requireSuperAdminToGrant(req, opts);
|
|
153
|
+
}
|
|
154
|
+
return data;
|
|
155
|
+
}
|
|
156
|
+
if (operation !== 'update' || !originalDoc || data.roles === undefined) {
|
|
157
|
+
return data;
|
|
158
|
+
}
|
|
159
|
+
if (sameIds(idsOf(originalDoc.roles), idsOf(data.roles))) {
|
|
160
|
+
return data;
|
|
161
|
+
}
|
|
162
|
+
const wasSuperAdmin = await holdsSuperAdmin(req, opts, originalDoc, originalDoc.roles);
|
|
163
|
+
if (!wasSuperAdmin && !trusted(req) && await holdsSuperAdmin(req, opts, originalDoc, data.roles)) {
|
|
164
|
+
await requireSuperAdminToGrant(req, opts);
|
|
165
|
+
}
|
|
166
|
+
if (wasSuperAdmin && !await holdsSuperAdmin(req, opts, originalDoc, data.roles) && !await anotherSuperAdmin(req, opts, {
|
|
167
|
+
slug,
|
|
168
|
+
ids: [
|
|
169
|
+
originalDoc.id
|
|
170
|
+
]
|
|
171
|
+
})) {
|
|
172
|
+
refuse(NO_SUPER_ADMIN);
|
|
173
|
+
}
|
|
174
|
+
return data;
|
|
175
|
+
},
|
|
176
|
+
beforeDelete: async ({ id, req })=>{
|
|
177
|
+
const doc = await req.payload.findByID({
|
|
178
|
+
id,
|
|
179
|
+
collection: asCollection(slug),
|
|
180
|
+
depth: 0,
|
|
181
|
+
overrideAccess: true,
|
|
182
|
+
req
|
|
183
|
+
});
|
|
184
|
+
if (await holdsSuperAdmin(req, opts, doc, doc.roles) && !await anotherSuperAdmin(req, opts, {
|
|
185
|
+
slug,
|
|
186
|
+
ids: [
|
|
187
|
+
id
|
|
188
|
+
]
|
|
189
|
+
})) {
|
|
190
|
+
refuse(NO_SUPER_ADMIN);
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
// Bulk (where-based) update and delete run per document in parallel transactions, so the
|
|
194
|
+
// per-document checks cannot see each other. Check the whole affected set up front.
|
|
195
|
+
beforeOperation: async ({ args, operation, req })=>{
|
|
196
|
+
const bulk = args;
|
|
197
|
+
if (operation === 'create' || operation === 'update') {
|
|
198
|
+
;
|
|
199
|
+
req.context[OVERRIDE_KEY] = bulk.overrideAccess === true;
|
|
200
|
+
}
|
|
201
|
+
if (bulk.id !== undefined || !bulk.where) {
|
|
202
|
+
return args;
|
|
203
|
+
}
|
|
204
|
+
let newRoles;
|
|
205
|
+
if (operation === 'update') {
|
|
206
|
+
newRoles = bulk.data?.roles;
|
|
207
|
+
// Without access to the field, Payload drops the change.
|
|
208
|
+
if (newRoles === undefined || !bulk.overrideAccess && !await canManageRoles(req, opts)) {
|
|
209
|
+
return args;
|
|
210
|
+
}
|
|
211
|
+
} else if (operation !== 'delete') {
|
|
212
|
+
return args;
|
|
213
|
+
}
|
|
214
|
+
const { docs } = await req.payload.find({
|
|
215
|
+
collection: asCollection(slug),
|
|
216
|
+
depth: 0,
|
|
217
|
+
overrideAccess: true,
|
|
218
|
+
pagination: false,
|
|
219
|
+
req,
|
|
220
|
+
where: bulk.where
|
|
221
|
+
});
|
|
222
|
+
if (operation === 'update' && !trusted(req) && await isSuperAdmin(req, opts) === false) {
|
|
223
|
+
for (const doc of docs){
|
|
224
|
+
if (!await holdsSuperAdmin(req, opts, doc, doc.roles) && await holdsSuperAdmin(req, opts, doc, newRoles)) {
|
|
225
|
+
refuse(GRANT_SUPER_ADMIN);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
let lost = false;
|
|
230
|
+
for (const doc of docs){
|
|
231
|
+
if (await holdsSuperAdmin(req, opts, doc, doc.roles)) {
|
|
232
|
+
lost = true;
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (!lost) {
|
|
237
|
+
return args;
|
|
238
|
+
}
|
|
239
|
+
if (operation === 'update') {
|
|
240
|
+
const changed = await Promise.all(docs.map((doc)=>holdsSuperAdmin(req, opts, doc, newRoles)));
|
|
241
|
+
if (changed.some(Boolean)) {
|
|
242
|
+
return args;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
if (!await anotherSuperAdmin(req, opts, {
|
|
246
|
+
slug,
|
|
247
|
+
ids: docs.map((doc)=>doc.id)
|
|
248
|
+
})) {
|
|
249
|
+
refuse(NO_SUPER_ADMIN);
|
|
250
|
+
}
|
|
251
|
+
return args;
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
//# sourceMappingURL=guardrails.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/guardrails.ts"],"sourcesContent":["import type {\n CollectionBeforeChangeHook,\n CollectionBeforeDeleteHook,\n CollectionBeforeOperationHook,\n CollectionConfig,\n FieldHook,\n PayloadRequest,\n Where,\n} from 'payload'\n\nimport { APIError } from 'payload'\n\nimport type { NormalizedOptions } from '../options.js'\n\nimport { idsOf, loadRoles } from '../access/load.js'\nimport { canManageRoles, isSuperAdmin } from '../access/manage.js'\nimport { asCollection } from '../slug.js'\n\ntype Id = number | string\n\nconst refuse = (message: string): never => {\n throw new APIError(message, 403)\n}\n\nconst sameIds = (a: Id[], b: Id[]): boolean => {\n const left = a.map(String).sort()\n const right = b.map(String).sort()\n return left.length === right.length && left.every((id, i) => id === right[i])\n}\n\n/** Guardrails on the roles collection. Kept on even when the plugin is disabled. */\nexport const roleGuardrails = (opts: NormalizedOptions): CollectionConfig['hooks'] => {\n const beforeChange: CollectionBeforeChangeHook = ({ data, operation, originalDoc }) => {\n if (operation !== 'update') {\n return data\n }\n if (originalDoc?.locked) {\n return refuse(\"This role is locked by the app and can't be changed here.\")\n }\n return data\n }\n\n const beforeDelete: CollectionBeforeDeleteHook = async ({ id, req }) => {\n const role = await req.payload.findByID({\n id,\n collection: asCollection(opts.rolesSlug),\n depth: 0,\n overrideAccess: true,\n req,\n })\n if ((role as { locked?: boolean }).locked) {\n refuse(\"This role is locked by the app and can't be changed here.\")\n }\n let assigned = 0\n for (const slug of opts.usersSlugs) {\n const { totalDocs } = await req.payload.count({\n collection: asCollection(slug),\n overrideAccess: true,\n req,\n where: { roles: { contains: id } },\n })\n assigned += totalDocs\n }\n if (assigned > 0) {\n refuse(`This role is still assigned to ${assigned} users. Remove it from them first.`)\n }\n }\n\n return { beforeChange: [beforeChange], beforeDelete: [beforeDelete] }\n}\n\n/** True when another user, in any users collection, holds a super-admin role. */\nconst anotherSuperAdmin = async (\n req: PayloadRequest,\n opts: NormalizedOptions,\n exclude: { ids: Id[]; slug: string },\n): Promise<boolean> => {\n for (const slug of opts.usersSlugs) {\n let page = 1\n for (;;) {\n const result = await req.payload.find({\n collection: asCollection(slug),\n depth: 1,\n limit: 100,\n overrideAccess: true,\n page,\n req,\n ...(slug === exclude.slug && exclude.ids.length > 0\n ? { where: { id: { not_in: exclude.ids } } }\n : {}),\n })\n if (result.docs.some((user) => opts.superAdmin(user))) {\n return true\n }\n if (!result.hasNextPage) {\n break\n }\n page += 1\n }\n }\n return false\n}\n\n/**\n * Role-field slug guard: the slug is fixed once created. Runs before field access, which then\n * makes the field read-only in the admin UI.\n */\nexport const slugGuard: FieldHook = ({ operation, originalDoc, value }) => {\n if (operation === 'update' && typeof value === 'string' && value !== originalDoc?.slug) {\n refuse(\"The slug of a role can't be changed.\")\n }\n return value\n}\n\n/** True when no user exists yet in any users collection (the create-first-user case). */\nexport const noUsersYet = async (req: PayloadRequest, opts: NormalizedOptions) => {\n for (const slug of opts.usersSlugs) {\n // find, not count: MongoDB can't run an unfiltered count inside a transaction.\n const { docs } = await req.payload.find({\n collection: asCollection(slug),\n depth: 0,\n limit: 1,\n overrideAccess: true,\n pagination: false,\n req,\n })\n if (docs.length > 0) {\n return false\n }\n }\n return true\n}\n\nconst NO_SUPER_ADMIN = 'At least one user must keep a super-admin role.'\nconst GRANT_SUPER_ADMIN = 'Only a super admin can grant a super-admin role.'\n\n// beforeChange cannot see overrideAccess, so beforeOperation records it on the request context.\nconst OVERRIDE_KEY = 'accessPluginOverrideAccess'\n\n/** Seeds and other trusted calls (no user, or overrideAccess) may grant any role. */\nconst trusted = (req: PayloadRequest): boolean =>\n !req.user || (req.context as Record<string, unknown>)[OVERRIDE_KEY] === true\n\n/** Refuses a roles change that makes a user a super admin, unless the actor is one. */\nconst requireSuperAdminToGrant = async (req: PayloadRequest, opts: NormalizedOptions) => {\n if (!(await isSuperAdmin(req, opts))) {\n refuse(GRANT_SUPER_ADMIN)\n }\n}\n\nconst holdsSuperAdmin = async (\n req: PayloadRequest,\n opts: NormalizedOptions,\n doc: object,\n roles: unknown,\n) => opts.superAdmin({ ...doc, roles: await loadRoles(req, opts, idsOf(roles)) })\n\n/** Guardrails on a users collection: default roles and the last super admin. */\nexport const userGuardrails = (\n opts: NormalizedOptions,\n slug: string,\n): {\n beforeChange: CollectionBeforeChangeHook\n beforeDelete: CollectionBeforeDeleteHook\n beforeOperation: CollectionBeforeOperationHook\n} => ({\n // Truly concurrent single-user demotions are a known limitation: each check sees the other\n // still holding the role. Bulk operations are handled in beforeOperation.\n beforeChange: async ({ data, operation, originalDoc, req }) => {\n if (operation === 'create') {\n if (idsOf(data.roles).length === 0 && opts.defaultRoles.length > 0) {\n const { docs } = await req.payload.find({\n collection: asCollection(opts.rolesSlug),\n depth: 0,\n overrideAccess: true,\n pagination: false,\n req,\n where: { slug: { in: opts.defaultRoles } },\n })\n data.roles = docs.map((doc) => doc.id)\n }\n if (\n !trusted(req) &&\n idsOf(data.roles).length > 0 &&\n (await holdsSuperAdmin(req, opts, data, data.roles))\n ) {\n await requireSuperAdminToGrant(req, opts)\n }\n return data\n }\n\n if (operation !== 'update' || !originalDoc || data.roles === undefined) {\n return data\n }\n if (sameIds(idsOf(originalDoc.roles), idsOf(data.roles))) {\n return data\n }\n const wasSuperAdmin = await holdsSuperAdmin(req, opts, originalDoc, originalDoc.roles)\n if (\n !wasSuperAdmin &&\n !trusted(req) &&\n (await holdsSuperAdmin(req, opts, originalDoc, data.roles))\n ) {\n await requireSuperAdminToGrant(req, opts)\n }\n if (\n wasSuperAdmin &&\n !(await holdsSuperAdmin(req, opts, originalDoc, data.roles)) &&\n !(await anotherSuperAdmin(req, opts, { slug, ids: [originalDoc.id] }))\n ) {\n refuse(NO_SUPER_ADMIN)\n }\n return data\n },\n\n beforeDelete: async ({ id, req }) => {\n const doc = await req.payload.findByID({\n id,\n collection: asCollection(slug),\n depth: 0,\n overrideAccess: true,\n req,\n })\n if (\n (await holdsSuperAdmin(req, opts, doc, (doc as { roles?: unknown }).roles)) &&\n !(await anotherSuperAdmin(req, opts, { slug, ids: [id] }))\n ) {\n refuse(NO_SUPER_ADMIN)\n }\n },\n\n // Bulk (where-based) update and delete run per document in parallel transactions, so the\n // per-document checks cannot see each other. Check the whole affected set up front.\n beforeOperation: async ({ args, operation, req }) => {\n const bulk = args as {\n data?: { roles?: unknown }\n id?: Id\n overrideAccess?: boolean\n where?: Where\n }\n if (operation === 'create' || operation === 'update') {\n ;(req.context as Record<string, unknown>)[OVERRIDE_KEY] = bulk.overrideAccess === true\n }\n if (bulk.id !== undefined || !bulk.where) {\n return args\n }\n let newRoles: unknown\n if (operation === 'update') {\n newRoles = bulk.data?.roles\n // Without access to the field, Payload drops the change.\n if (newRoles === undefined || (!bulk.overrideAccess && !(await canManageRoles(req, opts)))) {\n return args\n }\n } else if (operation !== 'delete') {\n return args\n }\n const { docs } = await req.payload.find({\n collection: asCollection(slug),\n depth: 0,\n overrideAccess: true,\n pagination: false,\n req,\n where: bulk.where,\n })\n if (operation === 'update' && !trusted(req) && (await isSuperAdmin(req, opts)) === false) {\n for (const doc of docs) {\n if (\n !(await holdsSuperAdmin(req, opts, doc, (doc as { roles?: unknown }).roles)) &&\n (await holdsSuperAdmin(req, opts, doc, newRoles))\n ) {\n refuse(GRANT_SUPER_ADMIN)\n }\n }\n }\n let lost = false\n for (const doc of docs) {\n if (await holdsSuperAdmin(req, opts, doc, (doc as { roles?: unknown }).roles)) {\n lost = true\n break\n }\n }\n if (!lost) {\n return args\n }\n if (operation === 'update') {\n const changed = await Promise.all(\n docs.map((doc) => holdsSuperAdmin(req, opts, doc, newRoles)),\n )\n if (changed.some(Boolean)) {\n return args\n }\n }\n if (!(await anotherSuperAdmin(req, opts, { slug, ids: docs.map((doc) => doc.id) }))) {\n refuse(NO_SUPER_ADMIN)\n }\n return args\n },\n})\n"],"names":["APIError","idsOf","loadRoles","canManageRoles","isSuperAdmin","asCollection","refuse","message","sameIds","a","b","left","map","String","sort","right","length","every","id","i","roleGuardrails","opts","beforeChange","data","operation","originalDoc","locked","beforeDelete","req","role","payload","findByID","collection","rolesSlug","depth","overrideAccess","assigned","slug","usersSlugs","totalDocs","count","where","roles","contains","anotherSuperAdmin","exclude","page","result","find","limit","ids","not_in","docs","some","user","superAdmin","hasNextPage","slugGuard","value","noUsersYet","pagination","NO_SUPER_ADMIN","GRANT_SUPER_ADMIN","OVERRIDE_KEY","trusted","context","requireSuperAdminToGrant","holdsSuperAdmin","doc","userGuardrails","defaultRoles","in","undefined","wasSuperAdmin","beforeOperation","args","bulk","newRoles","lost","changed","Promise","all","Boolean"],"mappings":"AAUA,SAASA,QAAQ,QAAQ,UAAS;AAIlC,SAASC,KAAK,EAAEC,SAAS,QAAQ,oBAAmB;AACpD,SAASC,cAAc,EAAEC,YAAY,QAAQ,sBAAqB;AAClE,SAASC,YAAY,QAAQ,aAAY;AAIzC,MAAMC,SAAS,CAACC;IACd,MAAM,IAAIP,SAASO,SAAS;AAC9B;AAEA,MAAMC,UAAU,CAACC,GAASC;IACxB,MAAMC,OAAOF,EAAEG,GAAG,CAACC,QAAQC,IAAI;IAC/B,MAAMC,QAA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CAAC6B,UAAU;oBACzB,OAAOP;gBACT;YACF;YACA,IAAI,CAAE,MAAM/B,kBAAkBhB,KAAKP,MAAM;gBAAEgB;gBAAMa,KAAKE,KAAKxC,GAAG,CAAC,CAACwD,MAAQA,IAAIlD,EAAE;YAAE,IAAK;gBACnFZ,OAAOuD;YACT;YACA,OAAOc;QACT;IACF,CAAA,EAAE"}
|
package/dist/i18n.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** Every string the access screen shows. Override any of them with the `i18n` plugin option. */
|
|
2
|
+
export type Translations = {
|
|
3
|
+
all: string;
|
|
4
|
+
allGroups: string;
|
|
5
|
+
allowAllView: string;
|
|
6
|
+
allTargets: string;
|
|
7
|
+
back: string;
|
|
8
|
+
cancel: string;
|
|
9
|
+
changeLine: string;
|
|
10
|
+
changesSummary: string;
|
|
11
|
+
clearRow: string;
|
|
12
|
+
clearRowFor: string;
|
|
13
|
+
collectionsGroup: string;
|
|
14
|
+
conflict: string;
|
|
15
|
+
created: string;
|
|
16
|
+
createFailed: string;
|
|
17
|
+
createRole: string;
|
|
18
|
+
description: string;
|
|
19
|
+
discard: string;
|
|
20
|
+
fieldsHeading: string;
|
|
21
|
+
filterDifferences: string;
|
|
22
|
+
filterGroup: string;
|
|
23
|
+
filterRoles: string;
|
|
24
|
+
globalsGroup: string;
|
|
25
|
+
grantLine: string;
|
|
26
|
+
grantsHeading: string;
|
|
27
|
+
hidden: string;
|
|
28
|
+
inherit: string;
|
|
29
|
+
loading: string;
|
|
30
|
+
locked: string;
|
|
31
|
+
lockedByApp: string;
|
|
32
|
+
lockedRole: string;
|
|
33
|
+
lockLine: string;
|
|
34
|
+
locksHeading: string;
|
|
35
|
+
locksIntro: string;
|
|
36
|
+
name: string;
|
|
37
|
+
newRole: string;
|
|
38
|
+
next: string;
|
|
39
|
+
noAccess: string;
|
|
40
|
+
noEditAccess: string;
|
|
41
|
+
noGrants: string;
|
|
42
|
+
noLongerInApp: string;
|
|
43
|
+
none: string;
|
|
44
|
+
own: string;
|
|
45
|
+
permission: string;
|
|
46
|
+
readOnlyRule: string;
|
|
47
|
+
rolePermissions: string;
|
|
48
|
+
saveChanges: string;
|
|
49
|
+
saved: string;
|
|
50
|
+
saveFailed: string;
|
|
51
|
+
slug: string;
|
|
52
|
+
slugClash: string;
|
|
53
|
+
slugEmpty: string;
|
|
54
|
+
slugHint: string;
|
|
55
|
+
startBlank: string;
|
|
56
|
+
startBlankHint: string;
|
|
57
|
+
startCopy: string;
|
|
58
|
+
startCopyHint: string;
|
|
59
|
+
startReadOnly: string;
|
|
60
|
+
startReadOnlyHint: string;
|
|
61
|
+
stepFields: string;
|
|
62
|
+
stepName: string;
|
|
63
|
+
stepOf: string;
|
|
64
|
+
stepPermissions: string;
|
|
65
|
+
stepReview: string;
|
|
66
|
+
stepsLabel: string;
|
|
67
|
+
stepStart: string;
|
|
68
|
+
subtitle: string;
|
|
69
|
+
title: string;
|
|
70
|
+
};
|
|
71
|
+
export declare const defaultTranslations: Translations;
|
|
72
|
+
/** The English defaults with the app's `i18n` option merged over them. */
|
|
73
|
+
export declare const translations: (overrides?: Partial<Translations>) => Translations;
|
|
74
|
+
export declare const format: (text: string, values: Record<string, number | string>) => string;
|
package/dist/i18n.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/** Every string the access screen shows. Override any of them with the `i18n` plugin option. */ export const defaultTranslations = {
|
|
2
|
+
name: 'Name',
|
|
3
|
+
slug: 'Slug',
|
|
4
|
+
all: 'all',
|
|
5
|
+
allGroups: 'All groups',
|
|
6
|
+
allowAllView: 'Allow all view',
|
|
7
|
+
allTargets: 'every target',
|
|
8
|
+
back: 'Back',
|
|
9
|
+
cancel: 'Cancel',
|
|
10
|
+
changeLine: '{role} · {target} · {action}: {from} to {to}',
|
|
11
|
+
changesSummary: 'Unsaved changes',
|
|
12
|
+
clearRow: 'Clear row',
|
|
13
|
+
clearRowFor: 'Clear row: {target}',
|
|
14
|
+
collectionsGroup: 'Collections',
|
|
15
|
+
conflict: '{name} was changed by someone else. Reload the page to see their changes; your edits to it are kept here.',
|
|
16
|
+
created: 'Created {name}.',
|
|
17
|
+
createFailed: 'Could not create the role: {message}',
|
|
18
|
+
createRole: 'Create role',
|
|
19
|
+
description: 'Description',
|
|
20
|
+
discard: 'Discard changes',
|
|
21
|
+
fieldsHeading: '{target} fields',
|
|
22
|
+
filterDifferences: 'Show only differences',
|
|
23
|
+
filterGroup: 'Group',
|
|
24
|
+
filterRoles: 'Roles',
|
|
25
|
+
globalsGroup: 'Globals',
|
|
26
|
+
grantLine: '{target} · {action}: {value}',
|
|
27
|
+
grantsHeading: 'Grants',
|
|
28
|
+
hidden: 'hidden',
|
|
29
|
+
inherit: 'inherit',
|
|
30
|
+
loading: 'Loading...',
|
|
31
|
+
locked: 'locked',
|
|
32
|
+
lockedByApp: 'Locked by the app',
|
|
33
|
+
lockedRole: 'This role is locked',
|
|
34
|
+
lockLine: '{target} · {action}: fixed to {value}. Your choice will not apply.',
|
|
35
|
+
locksHeading: 'Locked by the app',
|
|
36
|
+
locksIntro: 'The app fixes these for this role. Your choices for them will not apply.',
|
|
37
|
+
newRole: 'New role',
|
|
38
|
+
next: 'Next',
|
|
39
|
+
noAccess: "You don't have access to this page.",
|
|
40
|
+
noEditAccess: "You can't edit permissions.",
|
|
41
|
+
noGrants: 'No permissions granted.',
|
|
42
|
+
noLongerInApp: 'No longer in the app',
|
|
43
|
+
none: 'none',
|
|
44
|
+
own: 'own',
|
|
45
|
+
permission: 'Permission',
|
|
46
|
+
readOnlyRule: 'read only',
|
|
47
|
+
rolePermissions: 'Permissions for {name}',
|
|
48
|
+
saveChanges: 'Save changes ({count})',
|
|
49
|
+
saved: 'Saved {count} role(s).',
|
|
50
|
+
saveFailed: 'Could not save {name}: {message}',
|
|
51
|
+
slugClash: 'A role with this slug already exists.',
|
|
52
|
+
slugEmpty: 'The slug needs at least one letter or number. Type one in the slug field.',
|
|
53
|
+
slugHint: 'Fixed once the role is created.',
|
|
54
|
+
startBlank: 'Blank',
|
|
55
|
+
startBlankHint: 'No access until you grant it.',
|
|
56
|
+
startCopy: 'Copy "{name}"',
|
|
57
|
+
startCopyHint: 'Starts with the same permissions.',
|
|
58
|
+
startReadOnly: 'Read-only',
|
|
59
|
+
startReadOnlyHint: 'Read on every collection and global.',
|
|
60
|
+
stepFields: 'Fields & globals',
|
|
61
|
+
stepName: 'Name',
|
|
62
|
+
stepOf: 'Step {current} of {total}',
|
|
63
|
+
stepPermissions: 'Permissions',
|
|
64
|
+
stepReview: 'Review',
|
|
65
|
+
stepsLabel: 'Steps',
|
|
66
|
+
stepStart: 'Start from',
|
|
67
|
+
subtitle: 'What each role may do. Click a cell to change it, then save.',
|
|
68
|
+
title: 'Access'
|
|
69
|
+
};
|
|
70
|
+
/** The English defaults with the app's `i18n` option merged over them. */ export const translations = (overrides)=>({
|
|
71
|
+
...defaultTranslations,
|
|
72
|
+
...overrides
|
|
73
|
+
});
|
|
74
|
+
export const format = (text, values)=>text.replace(/\{(\w+)\}/g, (match, key)=>key in values ? String(values[key]) : match);
|
|
75
|
+
|
|
76
|
+
//# sourceMappingURL=i18n.js.map
|
package/dist/i18n.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/i18n.ts"],"sourcesContent":["/** Every string the access screen shows. Override any of them with the `i18n` plugin option. */\nexport type Translations = {\n all: string\n allGroups: string\n allowAllView: string\n allTargets: string\n back: string\n cancel: string\n changeLine: string\n changesSummary: string\n clearRow: string\n clearRowFor: string\n collectionsGroup: string\n conflict: string\n created: string\n createFailed: string\n createRole: string\n description: string\n discard: string\n fieldsHeading: string\n filterDifferences: string\n filterGroup: string\n filterRoles: string\n globalsGroup: string\n grantLine: string\n grantsHeading: string\n hidden: string\n inherit: string\n loading: string\n locked: string\n lockedByApp: string\n lockedRole: string\n lockLine: string\n locksHeading: string\n locksIntro: string\n name: string\n newRole: string\n next: string\n noAccess: string\n noEditAccess: string\n noGrants: string\n noLongerInApp: string\n none: string\n own: string\n permission: string\n readOnlyRule: string\n rolePermissions: string\n saveChanges: string\n saved: string\n saveFailed: string\n slug: string\n slugClash: string\n slugEmpty: string\n slugHint: string\n startBlank: string\n startBlankHint: string\n startCopy: string\n startCopyHint: string\n startReadOnly: string\n startReadOnlyHint: string\n stepFields: string\n stepName: string\n stepOf: string\n stepPermissions: string\n stepReview: string\n stepsLabel: string\n stepStart: string\n subtitle: string\n title: string\n}\n\nexport const defaultTranslations: Translations = {\n name: 'Name',\n slug: 'Slug',\n all: 'all',\n allGroups: 'All groups',\n allowAllView: 'Allow all view',\n allTargets: 'every target',\n back: 'Back',\n cancel: 'Cancel',\n changeLine: '{role} · {target} · {action}: {from} to {to}',\n changesSummary: 'Unsaved changes',\n clearRow: 'Clear row',\n clearRowFor: 'Clear row: {target}',\n collectionsGroup: 'Collections',\n conflict:\n '{name} was changed by someone else. Reload the page to see their changes; your edits to it are kept here.',\n created: 'Created {name}.',\n createFailed: 'Could not create the role: {message}',\n createRole: 'Create role',\n description: 'Description',\n discard: 'Discard changes',\n fieldsHeading: '{target} fields',\n filterDifferences: 'Show only differences',\n filterGroup: 'Group',\n filterRoles: 'Roles',\n globalsGroup: 'Globals',\n grantLine: '{target} · {action}: {value}',\n grantsHeading: 'Grants',\n hidden: 'hidden',\n inherit: 'inherit',\n loading: 'Loading...',\n locked: 'locked',\n lockedByApp: 'Locked by the app',\n lockedRole: 'This role is locked',\n lockLine: '{target} · {action}: fixed to {value}. Your choice will not apply.',\n locksHeading: 'Locked by the app',\n locksIntro: 'The app fixes these for this role. Your choices for them will not apply.',\n newRole: 'New role',\n next: 'Next',\n noAccess: \"You don't have access to this page.\",\n noEditAccess: \"You can't edit permissions.\",\n noGrants: 'No permissions granted.',\n noLongerInApp: 'No longer in the app',\n none: 'none',\n own: 'own',\n permission: 'Permission',\n readOnlyRule: 'read only',\n rolePermissions: 'Permissions for {name}',\n saveChanges: 'Save changes ({count})',\n saved: 'Saved {count} role(s).',\n saveFailed: 'Could not save {name}: {message}',\n slugClash: 'A role with this slug already exists.',\n slugEmpty: 'The slug needs at least one letter or number. Type one in the slug field.',\n slugHint: 'Fixed once the role is created.',\n startBlank: 'Blank',\n startBlankHint: 'No access until you grant it.',\n startCopy: 'Copy \"{name}\"',\n startCopyHint: 'Starts with the same permissions.',\n startReadOnly: 'Read-only',\n startReadOnlyHint: 'Read on every collection and global.',\n stepFields: 'Fields & globals',\n stepName: 'Name',\n stepOf: 'Step {current} of {total}',\n stepPermissions: 'Permissions',\n stepReview: 'Review',\n stepsLabel: 'Steps',\n stepStart: 'Start from',\n subtitle: 'What each role may do. Click a cell to change it, then save.',\n title: 'Access',\n}\n\n/** The English defaults with the app's `i18n` option merged over them. */\nexport const translations = (overrides?: Partial<Translations>): Translations => ({\n ...defaultTranslations,\n ...overrides,\n})\n\nexport const format = (text: string, values: Record<string, number | string>): string =>\n text.replace(/\\{(\\w+)\\}/g, (match, key: string) => (key in values ? String(values[key]) : match))\n"],"names":["defaultTranslations","name","slug","all","allGroups","allowAllView","allTargets","back","cancel","changeLine","changesSummary","clearRow","clearRowFor","collectionsGroup","conflict","created","createFailed","createRole","description","discard","fieldsHeading","filterDifferences","filterGroup","filterRoles","globalsGroup","grantLine","grantsHeading","hidden","inherit","loading","locked","lockedByApp","lockedRole","lockLine","locksHeading","locksIntro","newRole","next","noAccess","noEditAccess","noGrants","noLongerInApp","none","own","permission","readOnlyRule","rolePermissions","saveChanges","saved","saveFailed","slugClash","slugEmpty","slugHint","startBlank","startBlankHint","startCopy","startCopyHint","startReadOnly","startReadOnlyHint","stepFields","stepName","stepOf","stepPermissions","stepReview","stepsLabel","stepStart","subtitle","title","translations","overrides","format","text","values","replace","match","key","String"],"mappings":"AAAA,8FAA8F,GAuE9F,OAAO,MAAMA,sBAAoC;IAC/CC,MAAM;IACNC,MAAM;IACNC,KAAK;IACLC,WAAW;IACXC,cAAc;IACdC,YAAY;IACZC,MAAM;IACNC,QAAQ;IACRC,YAAY;IACZC,gBAAgB;IAChBC,UAAU;IACVC,aAAa;IACbC,kBAAkB;IAClBC,UACE;IACFC,SAAS;IACTC,cAAc;IACdC,YAAY;IACZC,aAAa;IACbC,SAAS;IACTC,eAAe;IACfC,mBAAmB;IACnBC,aAAa;IACbC,aAAa;IACbC,cAAc;IACdC,WAAW;IACXC,eAAe;IACfC,QAAQ;IACRC,SAAS;IACTC,SAAS;IACTC,QAAQ;IACRC,aAAa;IACbC,YAAY;IACZC,UAAU;IACVC,cAAc;IACdC,YAAY;IACZC,SAAS;IACTC,MAAM;IACNC,UAAU;IACVC,cAAc;IACdC,UAAU;IACVC,eAAe;IACfC,MAAM;IACNC,KAAK;IACLC,YAAY;IACZC,cAAc;IACdC,iBAAiB;IACjBC,aAAa;IACbC,OAAO;IACPC,YAAY;IACZC,WAAW;IACXC,WAAW;IACXC,UAAU;IACVC,YAAY;IACZC,gBAAgB;IAChBC,WAAW;IACXC,eAAe;IACfC,eAAe;IACfC,mBAAmB;IACnBC,YAAY;IACZC,UAAU;IACVC,QAAQ;IACRC,iBAAiB;IACjBC,YAAY;IACZC,YAAY;IACZC,WAAW;IACXC,UAAU;IACVC,OAAO;AACT,EAAC;AAED,wEAAwE,GACxE,OAAO,MAAMC,eAAe,CAACC,YAAqD,CAAA;QAChF,GAAGrE,mBAAmB;QACtB,GAAGqE,SAAS;IACd,CAAA,EAAE;AAEF,OAAO,MAAMC,SAAS,CAACC,MAAcC,SACnCD,KAAKE,OAAO,CAAC,cAAc,CAACC,OAAOC,MAAiBA,OAAOH,SAASI,OAAOJ,MAAM,CAACG,IAAI,IAAID,OAAO"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Config } from 'payload';
|
|
2
|
+
import type { AccessPluginOptions } from './types.js';
|
|
3
|
+
export { can } from './access/can.js';
|
|
4
|
+
export { getPermissions } from './access/resolve.js';
|
|
5
|
+
export type { Translations } from './i18n.js';
|
|
6
|
+
export type { AccessPluginOptions, CustomAction, Lock, RoleSeed } from './types.js';
|
|
7
|
+
export declare const accessPlugin: (options?: AccessPluginOptions) => (config: Config) => Config;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { roleCacheHooks } from './access/resolve.js';
|
|
2
|
+
import { wrapCollectionAccess, wrapGlobalAccess } from './access/wrap.js';
|
|
3
|
+
import { rolesCollection } from './collections/roles.js';
|
|
4
|
+
import { meEndpoint } from './endpoints/me.js';
|
|
5
|
+
import { schemaEndpoint } from './endpoints/schema.js';
|
|
6
|
+
import { ownerField } from './fields/owner.js';
|
|
7
|
+
import { userRolesField } from './fields/userRoles.js';
|
|
8
|
+
import { userGuardrails } from './hooks/guardrails.js';
|
|
9
|
+
import { normalizeOptions } from './options.js';
|
|
10
|
+
import { seedRoles } from './seed.js';
|
|
11
|
+
export { can } from './access/can.js';
|
|
12
|
+
export { getPermissions } from './access/resolve.js';
|
|
13
|
+
export const accessPlugin = (options = {})=>(config)=>{
|
|
14
|
+
const opts = normalizeOptions(options, config);
|
|
15
|
+
const collections = config.collections ?? [];
|
|
16
|
+
for (const slug of opts.usersSlugs){
|
|
17
|
+
if (!collections.some((c)=>c.slug === slug)) {
|
|
18
|
+
throw new Error(`payload-access-plugin: the users collection "${slug}" does not exist in the config.`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const withRoles = collections.map((collection)=>{
|
|
22
|
+
let next = collection;
|
|
23
|
+
const owner = opts.ownership[collection.slug];
|
|
24
|
+
if (owner && !next.fields.some((f)=>'name' in f && f.name === owner)) {
|
|
25
|
+
next = {
|
|
26
|
+
...next,
|
|
27
|
+
fields: [
|
|
28
|
+
...next.fields,
|
|
29
|
+
ownerField(owner, opts)
|
|
30
|
+
]
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (opts.usersSlugs.includes(next.slug)) {
|
|
34
|
+
const guard = userGuardrails(opts, next.slug);
|
|
35
|
+
next = {
|
|
36
|
+
...next,
|
|
37
|
+
fields: [
|
|
38
|
+
...next.fields,
|
|
39
|
+
userRolesField(opts)
|
|
40
|
+
],
|
|
41
|
+
hooks: {
|
|
42
|
+
...next.hooks,
|
|
43
|
+
beforeChange: [
|
|
44
|
+
...next.hooks?.beforeChange ?? [],
|
|
45
|
+
guard.beforeChange
|
|
46
|
+
],
|
|
47
|
+
beforeDelete: [
|
|
48
|
+
...next.hooks?.beforeDelete ?? [],
|
|
49
|
+
guard.beforeDelete
|
|
50
|
+
],
|
|
51
|
+
beforeOperation: [
|
|
52
|
+
...next.hooks?.beforeOperation ?? [],
|
|
53
|
+
guard.beforeOperation
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return opts.enabled && Object.hasOwn(opts.targets.collections, next.slug) ? wrapCollectionAccess(next, opts) : next;
|
|
59
|
+
});
|
|
60
|
+
const globals = (config.globals ?? []).map((global)=>opts.enabled && Object.hasOwn(opts.targets.globals, global.slug) ? wrapGlobalAccess(global, opts) : global);
|
|
61
|
+
const roles = rolesCollection(opts, options.roles?.overrides);
|
|
62
|
+
const cacheHooks = roleCacheHooks();
|
|
63
|
+
const rolesWithCache = {
|
|
64
|
+
...roles,
|
|
65
|
+
hooks: {
|
|
66
|
+
...roles.hooks,
|
|
67
|
+
afterChange: [
|
|
68
|
+
...roles.hooks?.afterChange ?? [],
|
|
69
|
+
cacheHooks.afterChange
|
|
70
|
+
],
|
|
71
|
+
afterDelete: [
|
|
72
|
+
...roles.hooks?.afterDelete ?? [],
|
|
73
|
+
cacheHooks.afterDelete
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const appOnInit = config.onInit;
|
|
78
|
+
return {
|
|
79
|
+
...config,
|
|
80
|
+
admin: opts.enabled ? {
|
|
81
|
+
...config.admin,
|
|
82
|
+
components: {
|
|
83
|
+
...config.admin?.components,
|
|
84
|
+
afterNavLinks: [
|
|
85
|
+
...config.admin?.components?.afterNavLinks ?? [],
|
|
86
|
+
'payload-access-plugin/rsc#NavLink'
|
|
87
|
+
],
|
|
88
|
+
views: {
|
|
89
|
+
...config.admin?.components?.views,
|
|
90
|
+
accessPlugin: {
|
|
91
|
+
Component: 'payload-access-plugin/rsc#AccessView',
|
|
92
|
+
path: opts.admin.path
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} : config.admin,
|
|
97
|
+
collections: [
|
|
98
|
+
...withRoles,
|
|
99
|
+
rolesWithCache
|
|
100
|
+
],
|
|
101
|
+
custom: {
|
|
102
|
+
...config.custom,
|
|
103
|
+
accessPlugin: opts
|
|
104
|
+
},
|
|
105
|
+
endpoints: [
|
|
106
|
+
...config.endpoints ?? [],
|
|
107
|
+
...opts.enabled ? [
|
|
108
|
+
meEndpoint(opts),
|
|
109
|
+
schemaEndpoint(opts)
|
|
110
|
+
] : []
|
|
111
|
+
],
|
|
112
|
+
...config.globals ? {
|
|
113
|
+
globals
|
|
114
|
+
} : {},
|
|
115
|
+
onInit: async (payload)=>{
|
|
116
|
+
await appOnInit?.(payload);
|
|
117
|
+
await seedRoles(payload, opts);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollectionConfig, Config } from 'payload'\n\nimport type { AccessPluginOptions } from './types.js'\n\nimport { roleCacheHooks } from './access/resolve.js'\nimport { wrapCollectionAccess, wrapGlobalAccess } from './access/wrap.js'\nimport { rolesCollection } from './collections/roles.js'\nimport { meEndpoint } from './endpoints/me.js'\nimport { schemaEndpoint } from './endpoints/schema.js'\nimport { ownerField } from './fields/owner.js'\nimport { userRolesField } from './fields/userRoles.js'\nimport { userGuardrails } from './hooks/guardrails.js'\nimport { normalizeOptions } from './options.js'\nimport { seedRoles } from './seed.js'\n\nexport { can } from './access/can.js'\nexport { getPermissions } from './access/resolve.js'\nexport type { Translations } from './i18n.js'\nexport type { AccessPluginOptions, CustomAction, Lock, RoleSeed } from './types.js'\n\nexport const accessPlugin =\n (options: AccessPluginOptions = {}) =>\n (config: Config): Config => {\n const opts = normalizeOptions(options, config)\n const collections = config.collections ?? []\n\n for (const slug of opts.usersSlugs) {\n if (!collections.some((c) => c.slug === slug)) {\n throw new Error(\n `payload-access-plugin: the users collection \"${slug}\" does not exist in the config.`,\n )\n }\n }\n\n const withRoles = collections.map((collection): CollectionConfig => {\n let next = collection\n const owner = opts.ownership[collection.slug]\n if (owner && !next.fields.some((f) => 'name' in f && f.name === owner)) {\n next = { ...next, fields: [...next.fields, ownerField(owner, opts)] }\n }\n if (opts.usersSlugs.includes(next.slug)) {\n const guard = userGuardrails(opts, next.slug)\n next = {\n ...next,\n fields: [...next.fields, userRolesField(opts)],\n hooks: {\n ...next.hooks,\n beforeChange: [...(next.hooks?.beforeChange ?? []), guard.beforeChange],\n beforeDelete: [...(next.hooks?.beforeDelete ?? []), guard.beforeDelete],\n beforeOperation: [...(next.hooks?.beforeOperation ?? []), guard.beforeOperation],\n },\n }\n }\n return opts.enabled && Object.hasOwn(opts.targets.collections, next.slug)\n ? wrapCollectionAccess(next, opts)\n : next\n })\n\n const globals = (config.globals ?? []).map((global) =>\n opts.enabled && Object.hasOwn(opts.targets.globals, global.slug)\n ? wrapGlobalAccess(global, opts)\n : global,\n )\n\n const roles = rolesCollection(opts, options.roles?.overrides)\n const cacheHooks = roleCacheHooks()\n const rolesWithCache: CollectionConfig = {\n ...roles,\n hooks: {\n ...roles.hooks,\n afterChange: [...(roles.hooks?.afterChange ?? []), cacheHooks.afterChange],\n afterDelete: [...(roles.hooks?.afterDelete ?? []), cacheHooks.afterDelete],\n },\n }\n\n const appOnInit = config.onInit\n return {\n ...config,\n admin: opts.enabled\n ? {\n ...config.admin,\n components: {\n ...config.admin?.components,\n afterNavLinks: [\n ...(config.admin?.components?.afterNavLinks ?? []),\n 'payload-access-plugin/rsc#NavLink',\n ],\n views: {\n ...config.admin?.components?.views,\n accessPlugin: {\n Component: 'payload-access-plugin/rsc#AccessView',\n path: opts.admin.path as `/${string}`,\n },\n },\n },\n }\n : config.admin,\n collections: [...withRoles, rolesWithCache],\n custom: { ...config.custom, accessPlugin: opts },\n endpoints: [\n ...(config.endpoints ?? []),\n ...(opts.enabled ? [meEndpoint(opts), schemaEndpoint(opts)] : []),\n ],\n ...(config.globals ? { globals } : {}),\n onInit: async (payload) => {\n await appOnInit?.(payload)\n await seedRoles(payload, opts)\n },\n }\n }\n"],"names":["roleCacheHooks","wrapCollectionAccess","wrapGlobalAccess","rolesCollection","meEndpoint","schemaEndpoint","ownerField","userRolesField","userGuardrails","normalizeOptions","seedRoles","can","getPermissions","accessPlugin","options","config","opts","collections","slug","usersSlugs","some","c","Error","withRoles","map","collection","next","owner","ownership","fields","f","name","includes","guard","hooks","beforeChange","beforeDelete","beforeOperation","enabled","Object","hasOwn","targets","globals","global","roles","overrides","cacheHooks","rolesWithCache","afterChange","afterDelete","appOnInit","onInit","admin","components","afterNavLinks","views","Component","path","custom","endpoints","payload"],"mappings":"AAIA,SAASA,cAAc,QAAQ,sBAAqB;AACpD,SAASC,oBAAoB,EAAEC,gBAAgB,QAAQ,mBAAkB;AACzE,SAASC,eAAe,QAAQ,yBAAwB;AACxD,SAASC,UAAU,QAAQ,oBAAmB;AAC9C,SAASC,cAAc,QAAQ,wBAAuB;AACtD,SAASC,UAAU,QAAQ,oBAAmB;AAC9C,SAASC,cAAc,QAAQ,wBAAuB;AACtD,SAASC,cAAc,QAAQ,wBAAuB;AACtD,SAASC,gBAAgB,QAAQ,eAAc;AAC/C,SAASC,SAAS,QAAQ,YAAW;AAErC,SAASC,GAAG,QAAQ,kBAAiB;AACrC,SAASC,cAAc,QAAQ,sBAAqB;AAIpD,OAAO,MAAMC,eACX,CAACC,UAA+B,CAAC,CAAC,GAClC,CAACC;QACC,MAAMC,OAAOP,iBAAiBK,SAASC;QACvC,MAAME,cAAc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KsB,OAAO,GAAG;oBAAClC,WAAWY;oBAAOX,eAAeW;iBAAM,GAAG,EAAE;aACjE;YACD,GAAID,OAAO2B,OAAO,GAAG;gBAAEA;YAAQ,IAAI,CAAC,CAAC;YACrCS,QAAQ,OAAOS;gBACb,MAAMV,YAAYU;gBAClB,MAAMlD,UAAUkD,SAAS5C;YAC3B;QACF;IACF,EAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Config, Field } from 'payload';
|
|
2
|
+
import type { KnownTargets, Lock } from './core/types.js';
|
|
3
|
+
import type { Translations } from './i18n.js';
|
|
4
|
+
import type { AccessPluginOptions, CustomAction, RoleSeed } from './types.js';
|
|
5
|
+
export type TargetLabels = Record<string, {
|
|
6
|
+
actions: {
|
|
7
|
+
label: string;
|
|
8
|
+
name: string;
|
|
9
|
+
}[];
|
|
10
|
+
fields: {
|
|
11
|
+
label: string;
|
|
12
|
+
path: string;
|
|
13
|
+
}[];
|
|
14
|
+
group?: string;
|
|
15
|
+
kind: 'collection' | 'global';
|
|
16
|
+
label: string;
|
|
17
|
+
}>;
|
|
18
|
+
export type NormalizedOptions = {
|
|
19
|
+
admin: {
|
|
20
|
+
group?: string;
|
|
21
|
+
label?: string;
|
|
22
|
+
path: string;
|
|
23
|
+
};
|
|
24
|
+
cacheTtlMs: number;
|
|
25
|
+
customActions: CustomAction[];
|
|
26
|
+
defaultRoles: string[];
|
|
27
|
+
enabled: boolean;
|
|
28
|
+
i18n: Partial<Translations>;
|
|
29
|
+
labels: TargetLabels;
|
|
30
|
+
locks: Lock[];
|
|
31
|
+
manageRoles: (user: unknown) => boolean;
|
|
32
|
+
ownership: Record<string, string>;
|
|
33
|
+
rolesSlug: string;
|
|
34
|
+
seed: RoleSeed[];
|
|
35
|
+
superAdmin: (user: unknown) => boolean;
|
|
36
|
+
targets: KnownTargets;
|
|
37
|
+
usersSlugs: string[];
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Walks the governable fields with their dotted paths: named fields, named groups and tabs
|
|
41
|
+
* (prefixed), unnamed rows, collapsibles and tabs (flattened), `ui` skipped. Arrays and blocks
|
|
42
|
+
* are one entry. `visit` may return a replacement for a leaf field; the tree is rebuilt around it.
|
|
43
|
+
*/
|
|
44
|
+
export declare const mapFields: (fields: Field[], prefix: string, visit: (field: Field, path: string) => Field | void) => Field[];
|
|
45
|
+
export declare const normalizeOptions: (options: AccessPluginOptions, config: Config) => NormalizedOptions;
|