@nocobase/plugin-acl 0.7.0-alpha.33 → 0.7.0-alpha.56

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.
Files changed (64) hide show
  1. package/lib/actions/available-actions.js +35 -25
  2. package/lib/actions/role-check.js +85 -38
  3. package/lib/actions/role-collections.js +46 -53
  4. package/lib/collections/roles.js +70 -78
  5. package/lib/collections/rolesResources.js +27 -30
  6. package/lib/collections/rolesResourcesActions.js +26 -27
  7. package/lib/collections/rolesResourcesScopes.js +21 -22
  8. package/lib/index.js +14 -8
  9. package/lib/model/RoleModel.js +39 -15
  10. package/lib/model/RoleResourceActionModel.js +103 -68
  11. package/lib/model/RoleResourceModel.js +125 -62
  12. package/lib/server.js +609 -354
  13. package/package.json +5 -10
  14. package/src/__tests__/own.test.ts +5 -6
  15. package/esm/actions/available-actions.d.ts +0 -7
  16. package/esm/actions/available-actions.js +0 -26
  17. package/esm/actions/available-actions.js.map +0 -1
  18. package/esm/actions/role-check.d.ts +0 -1
  19. package/esm/actions/role-check.js +0 -38
  20. package/esm/actions/role-check.js.map +0 -1
  21. package/esm/actions/role-collections.d.ts +0 -7
  22. package/esm/actions/role-collections.js +0 -54
  23. package/esm/actions/role-collections.js.map +0 -1
  24. package/esm/collections/roles.d.ts +0 -3
  25. package/esm/collections/roles.js +0 -78
  26. package/esm/collections/roles.js.map +0 -1
  27. package/esm/collections/rolesResources.d.ts +0 -3
  28. package/esm/collections/rolesResources.js +0 -30
  29. package/esm/collections/rolesResources.js.map +0 -1
  30. package/esm/collections/rolesResourcesActions.d.ts +0 -3
  31. package/esm/collections/rolesResourcesActions.js +0 -27
  32. package/esm/collections/rolesResourcesActions.js.map +0 -1
  33. package/esm/collections/rolesResourcesScopes.d.ts +0 -3
  34. package/esm/collections/rolesResourcesScopes.js +0 -22
  35. package/esm/collections/rolesResourcesScopes.js.map +0 -1
  36. package/esm/index.d.ts +0 -1
  37. package/esm/index.js +0 -2
  38. package/esm/index.js.map +0 -1
  39. package/esm/model/RoleModel.d.ts +0 -7
  40. package/esm/model/RoleModel.js +0 -15
  41. package/esm/model/RoleModel.js.map +0 -1
  42. package/esm/model/RoleResourceActionModel.d.ts +0 -12
  43. package/esm/model/RoleResourceActionModel.js +0 -67
  44. package/esm/model/RoleResourceActionModel.js.map +0 -1
  45. package/esm/model/RoleResourceModel.d.ts +0 -16
  46. package/esm/model/RoleResourceModel.js +0 -61
  47. package/esm/model/RoleResourceModel.js.map +0 -1
  48. package/esm/server.d.ts +0 -33
  49. package/esm/server.js +0 -369
  50. package/esm/server.js.map +0 -1
  51. package/lib/actions/available-actions.js.map +0 -1
  52. package/lib/actions/role-check.js.map +0 -1
  53. package/lib/actions/role-collections.js.map +0 -1
  54. package/lib/collections/roles.js.map +0 -1
  55. package/lib/collections/rolesResources.js.map +0 -1
  56. package/lib/collections/rolesResourcesActions.js.map +0 -1
  57. package/lib/collections/rolesResourcesScopes.js.map +0 -1
  58. package/lib/index.js.map +0 -1
  59. package/lib/model/RoleModel.js.map +0 -1
  60. package/lib/model/RoleResourceActionModel.js.map +0 -1
  61. package/lib/model/RoleResourceModel.js.map +0 -1
  62. package/lib/server.js.map +0 -1
  63. package/tsconfig.build.json +0 -9
  64. package/tsconfig.json +0 -5
@@ -1,61 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { Model } from '@nocobase/database';
11
- import { ACLResource } from '@nocobase/acl';
12
- export class RoleResourceModel extends Model {
13
- revoke(options) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- const { role, resourceName, grantHelper } = options;
16
- role.revokeResource(resourceName);
17
- const targetActions = grantHelper.resourceTargetActionMap.get(`${role.name}.${resourceName}`) || [];
18
- for (const targetAction of targetActions) {
19
- const targetActionResource = (grantHelper.targetActionResourceMap.get(targetAction) || []).filter((item) => `${role.name}.${resourceName}` !== item);
20
- grantHelper.targetActionResourceMap.set(targetAction, targetActionResource);
21
- if (targetActionResource.length == 0) {
22
- role.revokeAction(targetAction);
23
- }
24
- }
25
- grantHelper.resourceTargetActionMap.set(`${role.name}.${resourceName}`, []);
26
- });
27
- }
28
- writeToACL(options) {
29
- return __awaiter(this, void 0, void 0, function* () {
30
- const { acl, associationFieldsActions, grantHelper } = options;
31
- const resourceName = this.get('name');
32
- const roleName = this.get('roleName');
33
- const role = acl.getRole(roleName);
34
- // revoke resource of role
35
- yield this.revoke({ role, resourceName, grantHelper });
36
- // @ts-ignore
37
- if (this.usingActionsConfig === false) {
38
- return;
39
- }
40
- const resource = new ACLResource({
41
- role,
42
- name: resourceName,
43
- });
44
- role.resources.set(resourceName, resource);
45
- // @ts-ignore
46
- const actions = yield this.getActions({
47
- transaction: options.transaction,
48
- });
49
- for (const action of actions) {
50
- yield action.writeToACL({
51
- acl,
52
- role,
53
- resourceName,
54
- associationFieldsActions,
55
- grantHelper: options.grantHelper,
56
- });
57
- }
58
- });
59
- }
60
- }
61
- //# sourceMappingURL=RoleResourceModel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RoleResourceModel.js","sourceRoot":"","sources":["../../src/model/RoleResourceModel.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAY,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAO,WAAW,EAAW,MAAM,eAAe,CAAC;AAI1D,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACpC,MAAM,CAAC,OAA0E;;YACrF,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE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KAAK,KAAK,EAAE;gBACrC,OAAO;aACR;YAED,MAAM,QAAQ,GAAG,IAAI,WAAW,CAAC;gBAC/B,IAAI;gBACJ,IAAI,EAAE,YAAY;aACnB,CAAC,CAAC;YAEH,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;YAE3C,aAAa;YACb,MAAM,OAAO,GAA8B,MAAM,IAAI,CAAC,UAAU,CAAC;gBAC/D,WAAW,EAAE,OAAO,CAAC,WAAW;aACjC,CAAC,CAAC;YAEH,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;gBAC5B,MAAM,MAAM,CAAC,UAAU,CAAC;oBACtB,GAAG;oBACH,IAAI;oBACJ,YAAY;oBACZ,wBAAwB;oBACxB,WAAW,EAAE,OAAO,CAAC,WAAW;iBACjC,CAAC,CAAC;aACJ;QACH,CAAC;KAAA;CACF","sourcesContent":["import { Database, Model } from '@nocobase/database';\nimport { ACL, ACLResource, ACLRole } from '@nocobase/acl';\nimport { RoleResourceActionModel } from './RoleResourceActionModel';\nimport { AssociationFieldsActions, GrantHelper } from '../server';\n\nexport class RoleResourceModel extends Model {\n async revoke(options: { role: ACLRole; resourceName: string; grantHelper: GrantHelper }) {\n const { role, resourceName, grantHelper } = options;\n role.revokeResource(resourceName);\n\n const targetActions = grantHelper.resourceTargetActionMap.get(`${role.name}.${resourceName}`) || [];\n\n for (const targetAction of targetActions) {\n const targetActionResource = (grantHelper.targetActionResourceMap.get(targetAction) || []).filter(\n (item) => `${role.name}.${resourceName}` !== item,\n );\n\n grantHelper.targetActionResourceMap.set(targetAction, targetActionResource);\n\n if (targetActionResource.length == 0) {\n role.revokeAction(targetAction);\n }\n }\n\n grantHelper.resourceTargetActionMap.set(`${role.name}.${resourceName}`, []);\n }\n\n async writeToACL(options: {\n acl: ACL;\n associationFieldsActions: AssociationFieldsActions;\n grantHelper: GrantHelper;\n transaction: any;\n }) {\n const { acl, associationFieldsActions, grantHelper } = options;\n const resourceName = this.get('name') as string;\n const roleName = this.get('roleName') as string;\n const role = acl.getRole(roleName);\n\n // revoke resource of role\n await this.revoke({ role, resourceName, grantHelper });\n\n // @ts-ignore\n if (this.usingActionsConfig === false) {\n return;\n }\n\n const resource = new ACLResource({\n role,\n name: resourceName,\n });\n\n role.resources.set(resourceName, resource);\n\n // @ts-ignore\n const actions: RoleResourceActionModel[] = await this.getActions({\n transaction: options.transaction,\n });\n\n for (const action of actions) {\n await action.writeToACL({\n acl,\n role,\n resourceName,\n associationFieldsActions,\n grantHelper: options.grantHelper,\n });\n }\n }\n}\n"]}
package/esm/server.d.ts DELETED
@@ -1,33 +0,0 @@
1
- import { Plugin } from '@nocobase/server';
2
- import { RoleResourceActionModel } from './model/RoleResourceActionModel';
3
- import { RoleResourceModel } from './model/RoleResourceModel';
4
- export interface AssociationFieldAction {
5
- associationActions: string[];
6
- targetActions?: string[];
7
- }
8
- interface AssociationFieldActions {
9
- [availableActionName: string]: AssociationFieldAction;
10
- }
11
- export interface AssociationFieldsActions {
12
- [associationType: string]: AssociationFieldActions;
13
- }
14
- export declare class GrantHelper {
15
- resourceTargetActionMap: Map<string, string[]>;
16
- targetActionResourceMap: Map<string, string[]>;
17
- constructor();
18
- }
19
- export declare class PluginACL extends Plugin {
20
- associationFieldsActions: AssociationFieldsActions;
21
- grantHelper: GrantHelper;
22
- get acl(): import("@nocobase/acl").ACL;
23
- registerAssociationFieldAction(associationType: string, value: AssociationFieldActions): void;
24
- registerAssociationFieldsActions(): void;
25
- writeResourceToACL(resourceModel: RoleResourceModel, transaction: any): Promise<void>;
26
- writeActionToACL(actionModel: RoleResourceActionModel, transaction: any): Promise<void>;
27
- writeRolesToACL(): Promise<void>;
28
- beforeLoad(): Promise<void>;
29
- install(): Promise<void>;
30
- load(): Promise<void>;
31
- getName(): string;
32
- }
33
- export default PluginACL;
package/esm/server.js DELETED
@@ -1,369 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { Plugin } from '@nocobase/server';
11
- import { resolve } from 'path';
12
- import { availableActionResource } from './actions/available-actions';
13
- import { checkAction } from './actions/role-check';
14
- import { roleCollectionsResource } from './actions/role-collections';
15
- import { RoleModel } from './model/RoleModel';
16
- import { RoleResourceActionModel } from './model/RoleResourceActionModel';
17
- import { RoleResourceModel } from './model/RoleResourceModel';
18
- export class GrantHelper {
19
- constructor() {
20
- this.resourceTargetActionMap = new Map();
21
- this.targetActionResourceMap = new Map();
22
- }
23
- }
24
- export class PluginACL extends Plugin {
25
- constructor() {
26
- // association field actions config
27
- super(...arguments);
28
- this.associationFieldsActions = {};
29
- this.grantHelper = new GrantHelper();
30
- }
31
- get acl() {
32
- return this.app.acl;
33
- }
34
- registerAssociationFieldAction(associationType, value) {
35
- this.associationFieldsActions[associationType] = value;
36
- }
37
- registerAssociationFieldsActions() {
38
- // if grant create action to role, it should
39
- // also grant add action and association target's view action
40
- this.registerAssociationFieldAction('linkTo', {
41
- view: {
42
- associationActions: ['list', 'get'],
43
- },
44
- create: {
45
- associationActions: ['add'],
46
- targetActions: ['view'],
47
- },
48
- update: {
49
- associationActions: ['add', 'remove', 'toggle'],
50
- targetActions: ['view'],
51
- },
52
- });
53
- this.registerAssociationFieldAction('attachments', {
54
- view: {
55
- associationActions: ['list', 'get'],
56
- },
57
- add: {
58
- associationActions: ['upload', 'add'],
59
- },
60
- update: {
61
- associationActions: ['update', 'add', 'remove', 'toggle'],
62
- },
63
- });
64
- this.registerAssociationFieldAction('subTable', {
65
- view: {
66
- associationActions: ['list', 'get'],
67
- },
68
- create: {
69
- associationActions: ['create'],
70
- },
71
- update: {
72
- associationActions: ['update', 'destroy'],
73
- },
74
- });
75
- }
76
- writeResourceToACL(resourceModel, transaction) {
77
- return __awaiter(this, void 0, void 0, function* () {
78
- yield resourceModel.writeToACL({
79
- acl: this.acl,
80
- associationFieldsActions: this.associationFieldsActions,
81
- transaction: transaction,
82
- grantHelper: this.grantHelper,
83
- });
84
- });
85
- }
86
- writeActionToACL(actionModel, transaction) {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- const resource = actionModel.get('resource');
89
- const role = this.acl.getRole(resource.get('roleName'));
90
- yield actionModel.writeToACL({
91
- acl: this.acl,
92
- role,
93
- resourceName: resource.get('name'),
94
- associationFieldsActions: this.associationFieldsActions,
95
- grantHelper: this.grantHelper,
96
- });
97
- });
98
- }
99
- writeRolesToACL() {
100
- return __awaiter(this, void 0, void 0, function* () {
101
- const roles = (yield this.app.db.getRepository('roles').find({
102
- appends: ['resources', 'resources.actions'],
103
- }));
104
- for (const role of roles) {
105
- role.writeToAcl({ acl: this.acl });
106
- for (const resource of role.get('resources')) {
107
- yield this.writeResourceToACL(resource, null);
108
- }
109
- }
110
- });
111
- }
112
- beforeLoad() {
113
- return __awaiter(this, void 0, void 0, function* () {
114
- this.app.db.registerModels({
115
- RoleResourceActionModel,
116
- RoleResourceModel,
117
- RoleModel,
118
- });
119
- this.registerAssociationFieldsActions();
120
- this.app.resourcer.define(availableActionResource);
121
- this.app.resourcer.define(roleCollectionsResource);
122
- this.app.resourcer.registerActionHandler('roles:check', checkAction);
123
- this.app.db.on('roles.afterSaveWithAssociations', (model, options) => __awaiter(this, void 0, void 0, function* () {
124
- const { transaction } = options;
125
- model.writeToAcl({
126
- acl: this.acl,
127
- });
128
- for (const resource of (yield model.getResources({ transaction }))) {
129
- yield this.writeResourceToACL(resource, transaction);
130
- }
131
- // model is default
132
- if (model.get('default')) {
133
- yield this.app.db.getRepository('roles').update({
134
- values: {
135
- default: false,
136
- },
137
- filter: {
138
- 'name.$ne': model.get('name'),
139
- },
140
- hooks: false,
141
- transaction,
142
- });
143
- }
144
- }));
145
- this.app.db.on('roles.afterDestroy', (model) => {
146
- const roleName = model.get('name');
147
- this.acl.removeRole(roleName);
148
- });
149
- this.app.db.on('rolesResources.afterSaveWithAssociations', (model, options) => __awaiter(this, void 0, void 0, function* () {
150
- yield this.writeResourceToACL(model, options.transaction);
151
- }));
152
- this.app.db.on('rolesResourcesActions.afterUpdateWithAssociations', (model, options) => __awaiter(this, void 0, void 0, function* () {
153
- const { transaction } = options;
154
- const resource = yield model.getResource({
155
- transaction,
156
- });
157
- yield this.writeResourceToACL(resource, transaction);
158
- }));
159
- this.app.db.on('rolesResources.afterDestroy', (model, options) => __awaiter(this, void 0, void 0, function* () {
160
- const role = this.acl.getRole(model.get('roleName'));
161
- role.revokeResource(model.get('name'));
162
- }));
163
- this.app.db.on('collections.afterDestroy', (model, options) => __awaiter(this, void 0, void 0, function* () {
164
- const { transaction } = options;
165
- yield this.app.db.getRepository('rolesResources').destroy({
166
- filter: {
167
- name: model.get('name'),
168
- },
169
- transaction,
170
- });
171
- }));
172
- this.app.db.on('fields.afterCreate', (model, options) => __awaiter(this, void 0, void 0, function* () {
173
- const { transaction } = options;
174
- const collectionName = model.get('collectionName');
175
- const fieldName = model.get('name');
176
- const resourceActions = (yield this.app.db.getRepository('rolesResourcesActions').find({
177
- filter: {
178
- 'resource.name': collectionName,
179
- },
180
- transaction,
181
- appends: ['resource'],
182
- }));
183
- for (const resourceAction of resourceActions) {
184
- const fields = resourceAction.get('fields');
185
- const newFields = [...fields, fieldName];
186
- yield this.app.db.getRepository('rolesResourcesActions').update({
187
- filterByTk: resourceAction.get('id'),
188
- values: {
189
- fields: newFields,
190
- },
191
- transaction,
192
- });
193
- }
194
- }));
195
- this.app.db.on('fields.afterDestroy', (model, options) => __awaiter(this, void 0, void 0, function* () {
196
- const collectionName = model.get('collectionName');
197
- const fieldName = model.get('name');
198
- const resourceActions = yield this.app.db.getRepository('rolesResourcesActions').find({
199
- filter: {
200
- 'resource.name': collectionName,
201
- 'fields.$anyOf': [fieldName],
202
- },
203
- transaction: options.transaction,
204
- });
205
- for (const resourceAction of resourceActions) {
206
- const fields = resourceAction.get('fields');
207
- const newFields = fields.filter((field) => field != fieldName);
208
- yield this.app.db.getRepository('rolesResourcesActions').update({
209
- filterByTk: resourceAction.get('id'),
210
- values: {
211
- fields: newFields,
212
- },
213
- transaction: options.transaction,
214
- });
215
- }
216
- }));
217
- // sync database role data to acl
218
- this.app.on('beforeStart', () => __awaiter(this, void 0, void 0, function* () {
219
- yield this.writeRolesToACL();
220
- }));
221
- this.app.on('beforeInstallPlugin', (plugin) => __awaiter(this, void 0, void 0, function* () {
222
- if (plugin.constructor.name !== 'UsersPlugin') {
223
- return;
224
- }
225
- const roles = this.app.db.getRepository('roles');
226
- yield roles.createMany({
227
- records: [
228
- {
229
- name: 'root',
230
- title: '{{t("Root")}}',
231
- hidden: true,
232
- },
233
- {
234
- name: 'admin',
235
- title: '{{t("Admin")}}',
236
- allowConfigure: true,
237
- allowNewMenu: true,
238
- strategy: { actions: ['create', 'export', 'view', 'update', 'destroy'] },
239
- },
240
- {
241
- name: 'member',
242
- title: '{{t("Member")}}',
243
- allowNewMenu: true,
244
- strategy: { actions: ['view', 'update:own', 'destroy:own', 'create'] },
245
- default: true,
246
- },
247
- ],
248
- });
249
- const rolesResourcesScopes = this.app.db.getRepository('rolesResourcesScopes');
250
- yield rolesResourcesScopes.createMany({
251
- records: [
252
- {
253
- key: 'all',
254
- name: '{{t("All records")}}',
255
- scope: {},
256
- },
257
- {
258
- key: 'own',
259
- name: '{{t("Own records")}}',
260
- scope: {
261
- createdById: '{{ ctx.state.currentUser.id }}',
262
- },
263
- },
264
- ],
265
- });
266
- }));
267
- this.app.acl.allow('roles', 'check', 'loggedIn');
268
- this.app.acl.allow('roles', ['create', 'update', 'destroy'], 'allowConfigure');
269
- this.app.acl.allow('roles.menuUiSchemas', ['set', 'toggle', 'list'], 'allowConfigure');
270
- this.app.acl.allow('*', '*', (ctx) => {
271
- return ctx.state.currentRole === 'root';
272
- });
273
- this.app.resourcer.use((ctx, next) => __awaiter(this, void 0, void 0, function* () {
274
- const { actionName, resourceName, params } = ctx.action;
275
- const { showAnonymous } = params || {};
276
- if (actionName === 'list' && resourceName === 'roles') {
277
- if (!showAnonymous) {
278
- ctx.action.mergeParams({
279
- filter: {
280
- 'name.$ne': 'anonymous',
281
- },
282
- });
283
- }
284
- }
285
- yield next();
286
- }));
287
- this.app.acl.use((ctx, next) => __awaiter(this, void 0, void 0, function* () {
288
- var _a, _b, _c, _d, _e;
289
- const { actionName, resourceName } = ctx.action;
290
- if (actionName === 'get' || actionName === 'list') {
291
- if (!Array.isArray((_c = (_b = (_a = ctx === null || ctx === void 0 ? void 0 : ctx.permission) === null || _a === void 0 ? void 0 : _a.can) === null || _b === void 0 ? void 0 : _b.params) === null || _c === void 0 ? void 0 : _c.fields)) {
292
- return next();
293
- }
294
- let collection;
295
- if (resourceName.includes('.')) {
296
- const [collectionName, associationName] = resourceName.split('.');
297
- const field = (_e = (_d = ctx.db.getCollection(collectionName)) === null || _d === void 0 ? void 0 : _d.getField) === null || _e === void 0 ? void 0 : _e.call(_d, associationName);
298
- if (field.target) {
299
- collection = ctx.db.getCollection(field.target);
300
- }
301
- }
302
- else {
303
- collection = ctx.db.getCollection(resourceName);
304
- }
305
- if (collection && collection.hasField('createdById')) {
306
- ctx.permission.can.params.fields.push('createdById');
307
- }
308
- }
309
- return next();
310
- }));
311
- const parseJsonTemplate = this.app.acl.parseJsonTemplate;
312
- this.app.acl.use((ctx, next) => __awaiter(this, void 0, void 0, function* () {
313
- var _f, _g, _h, _j;
314
- const { actionName, resourceName, resourceOf } = ctx.action;
315
- if (resourceName.includes('.') && resourceOf) {
316
- if (!((_g = (_f = ctx === null || ctx === void 0 ? void 0 : ctx.permission) === null || _f === void 0 ? void 0 : _f.can) === null || _g === void 0 ? void 0 : _g.params)) {
317
- return next();
318
- }
319
- // 关联数据去掉 filter
320
- delete ctx.permission.can.params.filter;
321
- // 关联数据能不能处理取决于 source 是否有权限
322
- const [collectionName] = resourceName.split('.');
323
- const action = ctx.can({ resource: collectionName, action: actionName });
324
- const availableAction = this.app.acl.getAvailableAction(actionName);
325
- if ((_h = availableAction === null || availableAction === void 0 ? void 0 : availableAction.options) === null || _h === void 0 ? void 0 : _h.onNewRecord) {
326
- if (action) {
327
- ctx.permission.skip = true;
328
- }
329
- else {
330
- ctx.permission.can = false;
331
- }
332
- }
333
- else {
334
- const filter = parseJsonTemplate(((_j = action === null || action === void 0 ? void 0 : action.params) === null || _j === void 0 ? void 0 : _j.filter) || {}, ctx);
335
- const sourceInstance = yield ctx.db.getRepository(collectionName).findOne({
336
- filterByTk: resourceOf,
337
- filter,
338
- });
339
- if (!sourceInstance) {
340
- ctx.permission.can = false;
341
- }
342
- }
343
- }
344
- yield next();
345
- }));
346
- });
347
- }
348
- install() {
349
- return __awaiter(this, void 0, void 0, function* () {
350
- const repo = this.db.getRepository('collections');
351
- if (repo) {
352
- yield repo.db2cm('roles');
353
- }
354
- });
355
- }
356
- load() {
357
- return __awaiter(this, void 0, void 0, function* () {
358
- yield this.app.db.import({
359
- directory: resolve(__dirname, 'collections'),
360
- });
361
- this.app.resourcer.use(this.acl.middleware());
362
- });
363
- }
364
- getName() {
365
- return this.getPackageName(__dirname);
366
- }
367
- }
368
- export default PluginACL;
369
- //# sourceMappingURL=server.js.map
package/esm/server.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";;;;;;;;;AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,O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S,CAAC","sourcesContent":["import { Context } from '@nocobase/actions';\nimport { Collection } from '@nocobase/database';\nimport { Plugin } from '@nocobase/server';\nimport { resolve } from 'path';\nimport { availableActionResource } from './actions/available-actions';\nimport { checkAction } from './actions/role-check';\nimport { roleCollectionsResource } from './actions/role-collections';\nimport { RoleModel } from './model/RoleModel';\nimport { RoleResourceActionModel } from './model/RoleResourceActionModel';\nimport { RoleResourceModel } from './model/RoleResourceModel';\n\nexport interface AssociationFieldAction {\n associationActions: string[];\n targetActions?: string[];\n}\n\ninterface AssociationFieldActions {\n [availableActionName: string]: AssociationFieldAction;\n}\n\nexport interface AssociationFieldsActions {\n [associationType: string]: AssociationFieldActions;\n}\n\nexport class GrantHelper {\n resourceTargetActionMap = new Map<string, string[]>();\n targetActionResourceMap = new Map<string, string[]>();\n\n constructor() {}\n}\n\nexport class PluginACL extends Plugin {\n // association field actions config\n\n associationFieldsActions: AssociationFieldsActions = {};\n\n grantHelper = new GrantHelper();\n\n get acl() {\n return this.app.acl;\n }\n\n registerAssociationFieldAction(associationType: string, value: AssociationFieldActions) {\n this.associationFieldsActions[associationType] = value;\n }\n\n registerAssociationFieldsActions() {\n // if grant create action to role, it should\n // also grant add action and association target's view action\n this.registerAssociationFieldAction('linkTo', {\n view: {\n associationActions: ['list', 'get'],\n },\n create: {\n associationActions: ['add'],\n targetActions: ['view'],\n },\n update: {\n associationActions: ['add', 'remove', 'toggle'],\n targetActions: ['view'],\n },\n });\n\n this.registerAssociationFieldAction('attachments', {\n view: {\n associationActions: ['list', 'get'],\n },\n add: {\n associationActions: ['upload', 'add'],\n },\n update: {\n associationActions: ['update', 'add', 'remove', 'toggle'],\n },\n });\n\n this.registerAssociationFieldAction('subTable', {\n view: {\n associationActions: ['list', 'get'],\n },\n create: {\n associationActions: ['create'],\n },\n update: {\n associationActions: ['update', 'destroy'],\n },\n });\n }\n\n async writeResourceToACL(resourceModel: RoleResourceModel, transaction) {\n await resourceModel.writeToACL({\n acl: this.acl,\n associationFieldsActions: this.associationFieldsActions,\n transaction: transaction,\n grantHelper: this.grantHelper,\n });\n }\n\n async writeActionToACL(actionModel: RoleResourceActionModel, transaction) {\n const resource = actionModel.get('resource') as RoleResourceModel;\n const role = this.acl.getRole(resource.get('roleName') as string);\n await actionModel.writeToACL({\n acl: this.acl,\n role,\n resourceName: resource.get('name') as string,\n associationFieldsActions: this.associationFieldsActions,\n grantHelper: this.grantHelper,\n });\n }\n\n async writeRolesToACL() {\n const roles = (await this.app.db.getRepository('roles').find({\n appends: ['resources', 'resources.actions'],\n })) as RoleModel[];\n\n for (const role of roles) {\n role.writeToAcl({ acl: this.acl });\n for (const resource of role.get('resources') as RoleResourceModel[]) {\n await this.writeResourceToACL(resource, null);\n }\n }\n }\n\n async beforeLoad() {\n this.app.db.registerModels({\n RoleResourceActionModel,\n RoleResourceModel,\n RoleModel,\n });\n\n this.registerAssociationFieldsActions();\n\n this.app.resourcer.define(availableActionResource);\n this.app.resourcer.define(roleCollectionsResource);\n\n this.app.resourcer.registerActionHandler('roles:check', checkAction);\n\n this.app.db.on('roles.afterSaveWithAssociations', async (model, options) => {\n const { transaction } = options;\n\n model.writeToAcl({\n acl: this.acl,\n });\n\n for (const resource of (await model.getResources({ transaction })) as RoleResourceModel[]) {\n await this.writeResourceToACL(resource, transaction);\n }\n\n // model is default\n if (model.get('default')) {\n await this.app.db.getRepository('roles').update({\n values: {\n default: false,\n },\n filter: {\n 'name.$ne': model.get('name'),\n },\n hooks: false,\n transaction,\n });\n }\n });\n\n this.app.db.on('roles.afterDestroy', (model) => {\n const roleName = model.get('name');\n this.acl.removeRole(roleName);\n });\n\n this.app.db.on('rolesResources.afterSaveWithAssociations', async (model: RoleResourceModel, options) => {\n await this.writeResourceToACL(model, options.transaction);\n });\n\n this.app.db.on('rolesResourcesActions.afterUpdateWithAssociations', async (model, options) => {\n const { transaction } = options;\n const resource = await model.getResource({\n transaction,\n });\n\n await this.writeResourceToACL(resource, transaction);\n });\n\n this.app.db.on('rolesResources.afterDestroy', async (model, options) => {\n const role = this.acl.getRole(model.get('roleName'));\n role.revokeResource(model.get('name'));\n });\n\n this.app.db.on('collections.afterDestroy', async (model, options) => {\n const { transaction } = options;\n await this.app.db.getRepository('rolesResources').destroy({\n filter: {\n name: model.get('name'),\n },\n transaction,\n });\n });\n\n this.app.db.on('fields.afterCreate', async (model, options) => {\n const { transaction } = options;\n\n const collectionName = model.get('collectionName');\n const fieldName = model.get('name');\n\n const resourceActions = (await this.app.db.getRepository('rolesResourcesActions').find({\n filter: {\n 'resource.name': collectionName,\n },\n transaction,\n appends: ['resource'],\n })) as RoleResourceActionModel[];\n\n for (const resourceAction of resourceActions) {\n const fields = resourceAction.get('fields') as string[];\n const newFields = [...fields, fieldName];\n\n await this.app.db.getRepository('rolesResourcesActions').update({\n filterByTk: resourceAction.get('id') as number,\n values: {\n fields: newFields,\n },\n transaction,\n });\n }\n });\n\n this.app.db.on('fields.afterDestroy', async (model, options) => {\n const collectionName = model.get('collectionName');\n const fieldName = model.get('name');\n\n const resourceActions = await this.app.db.getRepository('rolesResourcesActions').find({\n filter: {\n 'resource.name': collectionName,\n 'fields.$anyOf': [fieldName],\n },\n transaction: options.transaction,\n });\n\n for (const resourceAction of resourceActions) {\n const fields = resourceAction.get('fields') as string[];\n const newFields = fields.filter((field) => field != fieldName);\n\n await this.app.db.getRepository('rolesResourcesActions').update({\n filterByTk: resourceAction.get('id') as number,\n values: {\n fields: newFields,\n },\n transaction: options.transaction,\n });\n }\n });\n\n // sync database role data to acl\n this.app.on('beforeStart', async () => {\n await this.writeRolesToACL();\n });\n\n this.app.on('beforeInstallPlugin', async (plugin) => {\n if (plugin.constructor.name !== 'UsersPlugin') {\n return;\n }\n const roles = this.app.db.getRepository('roles');\n await roles.createMany({\n records: [\n {\n name: 'root',\n title: '{{t(\"Root\")}}',\n hidden: true,\n },\n {\n name: 'admin',\n title: '{{t(\"Admin\")}}',\n allowConfigure: true,\n allowNewMenu: true,\n strategy: { actions: ['create', 'export', 'view', 'update', 'destroy'] },\n },\n {\n name: 'member',\n title: '{{t(\"Member\")}}',\n allowNewMenu: true,\n strategy: { actions: ['view', 'update:own', 'destroy:own', 'create'] },\n default: true,\n },\n ],\n });\n const rolesResourcesScopes = this.app.db.getRepository('rolesResourcesScopes');\n await rolesResourcesScopes.createMany({\n records: [\n {\n key: 'all',\n name: '{{t(\"All records\")}}',\n scope: {},\n },\n {\n key: 'own',\n name: '{{t(\"Own records\")}}',\n scope: {\n createdById: '{{ ctx.state.currentUser.id }}',\n },\n },\n ],\n });\n });\n\n this.app.acl.allow('roles', 'check', 'loggedIn');\n this.app.acl.allow('roles', ['create', 'update', 'destroy'], 'allowConfigure');\n\n this.app.acl.allow('roles.menuUiSchemas', ['set', 'toggle', 'list'], 'allowConfigure');\n\n this.app.acl.allow('*', '*', (ctx) => {\n return ctx.state.currentRole === 'root';\n });\n\n this.app.resourcer.use(async (ctx, next) => {\n const { actionName, resourceName, params } = ctx.action;\n const { showAnonymous } = params || {};\n if (actionName === 'list' && resourceName === 'roles') {\n if (!showAnonymous) {\n ctx.action.mergeParams({\n filter: {\n 'name.$ne': 'anonymous',\n },\n });\n }\n }\n await next();\n });\n\n this.app.acl.use(async (ctx: Context, next) => {\n const { actionName, resourceName } = ctx.action;\n if (actionName === 'get' || actionName === 'list') {\n if (!Array.isArray(ctx?.permission?.can?.params?.fields)) {\n return next();\n }\n let collection: Collection;\n if (resourceName.includes('.')) {\n const [collectionName, associationName] = resourceName.split('.');\n const field = ctx.db.getCollection(collectionName)?.getField?.(associationName);\n if (field.target) {\n collection = ctx.db.getCollection(field.target);\n }\n } else {\n collection = ctx.db.getCollection(resourceName);\n }\n if (collection && collection.hasField('createdById')) {\n ctx.permission.can.params.fields.push('createdById');\n }\n }\n return next();\n });\n\n const parseJsonTemplate = this.app.acl.parseJsonTemplate;\n this.app.acl.use(async (ctx: Context, next) => {\n const { actionName, resourceName, resourceOf } = ctx.action;\n if (resourceName.includes('.') && resourceOf) {\n if (!ctx?.permission?.can?.params) {\n return next();\n }\n // 关联数据去掉 filter\n delete ctx.permission.can.params.filter;\n // 关联数据能不能处理取决于 source 是否有权限\n const [collectionName] = resourceName.split('.');\n const action = ctx.can({ resource: collectionName, action: actionName });\n const availableAction = this.app.acl.getAvailableAction(actionName);\n if (availableAction?.options?.onNewRecord) {\n if (action) {\n ctx.permission.skip = true;\n } else {\n ctx.permission.can = false;\n }\n } else {\n const filter = parseJsonTemplate(action?.params?.filter || {}, ctx);\n const sourceInstance = await ctx.db.getRepository(collectionName).findOne({\n filterByTk: resourceOf,\n filter,\n });\n if (!sourceInstance) {\n ctx.permission.can = false;\n }\n }\n }\n await next();\n });\n }\n\n async install() {\n const repo = this.db.getRepository<any>('collections');\n if (repo) {\n await repo.db2cm('roles');\n }\n }\n\n async load() {\n await this.app.db.import({\n directory: resolve(__dirname, 'collections'),\n });\n\n this.app.resourcer.use(this.acl.middleware());\n }\n\n getName(): string {\n return this.getPackageName(__dirname);\n }\n}\n\nexport default PluginACL;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"available-actions.js","sourceRoot":"","sources":["../../src/actions/available-actions.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,MAAM,uBAAuB,GAAG;IAC9B,IAAI,EAAE,kBAAkB;IACxB,OAAO,EAAE;QACD,IAAI,CAAC,GAAG,EAAE,IAAI;;gBAClB,MAAM,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC;gBACxB,MAAM,gBAAgB,GAAG,GAAG,CAAC,mBAAmB,EAAE,CAAC;gBACnD,GAAG,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE;oBAC9E,uCACK,OAAO,KACV,IAAI,IACJ;gBACJ,CAAC,CAAC,CAAC;gBACH,MAAM,IAAI,EAAE,CAAC;YACf,CAAC;SAAA;KACF;CACF,CAAC;AAEO,0DAAuB","sourcesContent":["const availableActionResource = {\n name: 'availableActions',\n actions: {\n async list(ctx, next) {\n const acl = ctx.app.acl;\n const availableActions = acl.getAvailableActions();\n ctx.body = Array.from(availableActions.entries()).map(([, { name, options }]) => {\n return {\n ...options,\n name,\n };\n });\n await next();\n },\n },\n};\n\nexport { availableActionResource };\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"role-check.js","sourceRoot":"","sources":["../../src/actions/role-check.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,MAAM,OAAO,GAAG,CAAC,GAAwB,EAAE,EAAE;IAC3C,MAAM,GAAG,GAAG,EAAE,CAAC;IACf,KAAI,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,GAAG,EAAC;QAC1B,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;KAClB;IACF,OAAO,GAAG,CAAC;AACZ,CAAC,CAAA;AAED,SAAsB,WAAW,CAAC,GAAG,EAAE,IAAI;;QACzC,MAAM,WAAW,GAAG,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC;QAC1C,IAAI,WAAW,EAAE;YACf,MAAM,YAAY,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;gBAC/D,MAAM,EAAE;oBACN,IAAI,EAAE,WAAW;iBAClB;gBACD,OAAO,EAAE,CAAC,eAAe,CAAC;aAC3B,CAAC,CAAC;YAEH,MAAM,SAAS,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC;gBAC5D,MAAM,EAAE;oBACN,IAAI,EAAE,WAAW;iBAClB;aACF,CAAC,CAAC;YAEH,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;YAE9C,GAAG,CAAC,IAAI,mCACH,IAAI,CAAC,MAAM,EAAE,KAChB,SAAS,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,CAAC,EACrC,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,CAAC,EAC7C,QAAQ,EAAE,WAAW,KAAK,MAAM,EAChC,cAAc,EAAE,YAAY,CAAC,GAAG,CAAC,gBAAgB,CAAC,EAClD,gBAAgB,EAAE,YAAY,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,EAC5F,cAAc,EAAE,CAAC,CAAC,SAAS,GAC5B,CAAC;SACH;QAED,MAAM,IAAI,EAAE,CAAC;IACf,CAAC;CAAA;AA9BD,kCA8BC","sourcesContent":["const map2obj = (map: Map<string, string>) => {\n const obj = {};\n for(let [key, value] of map){\n obj[key] = value;\n }\n return obj;\n}\n\nexport async function checkAction(ctx, next) {\n const currentRole = ctx.state.currentRole;\n if (currentRole) {\n const roleInstance = await ctx.db.getRepository('roles').findOne({\n filter: {\n name: currentRole,\n },\n appends: ['menuUiSchemas'],\n });\n\n const anonymous = await ctx.db.getRepository('roles').findOne({\n filter: {\n name: 'anonymous',\n },\n });\n\n const role = ctx.app.acl.getRole(currentRole);\n\n ctx.body = {\n ...role.toJSON(),\n resources: [...role.resources.keys()],\n actionAlias: map2obj(ctx.app.acl.actionAlias),\n allowAll: currentRole === 'root',\n allowConfigure: roleInstance.get('allowConfigure'),\n allowMenuItemIds: roleInstance.get('menuUiSchemas').map((uiSchema) => uiSchema.get('x-uid')),\n allowAnonymous: !!anonymous,\n };\n }\n\n await next();\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"role-collections.js","sourceRoot":"","sources":["../../src/actions/role-collections.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,MAAM,uBAAuB,GAAG;IAC9B,IAAI,EAAE,mBAAmB;IACzB,OAAO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C,gBAAgB;wBAClB,CAAC,CAAC,UAAU,CAAC;oBAEf,OAAO;wBACL,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,MAAM,CAAW;wBACtC,KAAK,EAAE,UAAU,CAAC,GAAG,CAAC,OAAO,CAAW;wBACxC,QAAQ,EAAE,IAAI;wBACd,WAAW;wBACX,MAAM;qBACP,CAAC;gBACJ,CAAC,CAAC;qBACD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBAE9C,MAAM,IAAI,EAAE,CAAC;YACf,CAAC;SAAA;KACF;CACF,CAAC;AAEO,0DAAuB","sourcesContent":["import { Database } from '@nocobase/database';\n\ntype UsingConfigType = 'strategy' | 'resourceAction';\n\nconst roleCollectionsResource = {\n name: 'roles.collections',\n actions: {\n async list(ctx, next) {\n const role = ctx.action.params.associatedIndex;\n\n const db: Database = ctx.db;\n const collectionRepository = db.getRepository('collections');\n\n // all collections\n const collections = await collectionRepository.find({\n filter: ctx.action.params.filter,\n });\n\n // role collections\n const roleResources = await db.getRepository('rolesResources').find({\n filter: {\n roleName: role,\n },\n });\n\n // role collections\n const roleResourcesNames = roleResources.map((roleResource) => roleResource.get('name'));\n const roleResourceActionResourceNames = roleResources\n .filter((roleResources) => roleResources.get('usingActionsConfig'))\n .map((roleResources) => roleResources.get('name'));\n\n ctx.body = collections\n .map((collection) => {\n const exists = roleResourcesNames.includes(collection.get('name'));\n\n const usingConfig: UsingConfigType = roleResourceActionResourceNames.includes(collection.get('name'))\n ? 'resourceAction'\n : 'strategy';\n\n return {\n name: collection.get('name') as string,\n title: collection.get('title') as string,\n roleName: role,\n usingConfig,\n exists,\n };\n })\n .sort((a, b) => (a.name > b.name ? 1 : -1));\n\n await next();\n },\n },\n};\n\nexport { roleCollectionsResource };\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"roles.js","sourceRoot":"","sources":["../../src/collections/roles.ts"],"names":[],"mappings":";;AAEA,kBAAe;IACb,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,gBAAgB;IACvB,SAAS,EAAE,KAAK;IAChB,KAAK,EAAE,WAAW;IAClB,eAAe,EAAE,MAAM;IACvB,qBAAqB;IACrB,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE;QACN;YACE,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,MAAM;YACZ,MAAM,EAAE,IAAI;YACZ,UAAU,EAAE,IAAI;YAChB,SAAS,EAAE,OAAO;YAClB,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,mBAAmB;gBAC1B,aAAa,EAAE,OAAO;aACvB;SACF;QACD;YACE,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,IAAI;YACZ,SAAS,EAAE,OAAO;YAClB,QAAQ,EAAE;gBACR,IAAI,EAAE,QAAQ;gBACd,KAAK,EAAE,oBAAoB;gBAC3B,aAAa,EAAE,OAAO;aACvB;SACF;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,SAAS;SAChB;QACD;YACE,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,aAAa;SACpB;QACD;YACE,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,UAAU;SACjB;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,SAAS;YACf,YAAY,EAAE,KAAK;SACpB;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,QAAQ;YACd,YAAY,EAAE,KAAK;SACpB;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,gBAAgB;SACvB;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,cAAc;SACrB;QACD;YACE,IAAI,EAAE,eAAe;YACrB,IAAI,EAAE,eAAe;YACrB,MAAM,EAAE,WAAW;YACnB,SAAS,EAAE,OAAO;SACnB;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,gBAAgB;YACxB,SAAS,EAAE,MAAM;YACjB,SAAS,EAAE,MAAM;SAClB;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\n\nexport default {\n name: 'roles',\n title: '{{t(\"Roles\")}}',\n autoGenId: false,\n model: 'RoleModel',\n filterTargetKey: 'name',\n // targetKey: 'name',\n sortable: true,\n fields: [\n {\n type: 'uid',\n name: 'name',\n prefix: 'r_',\n primaryKey: true,\n interface: 'input',\n uiSchema: {\n type: 'string',\n title: '{{t(\"Role UID\")}}',\n 'x-component': 'Input',\n },\n },\n {\n type: 'string',\n name: 'title',\n unique: true,\n interface: 'input',\n uiSchema: {\n type: 'string',\n title: '{{t(\"Role name\")}}',\n 'x-component': 'Input',\n },\n },\n {\n type: 'boolean',\n name: 'default',\n },\n {\n type: 'string',\n name: 'description',\n },\n {\n type: 'json',\n name: 'strategy',\n },\n {\n type: 'boolean',\n name: 'default',\n defaultValue: false,\n },\n {\n type: 'boolean',\n name: 'hidden',\n defaultValue: false,\n },\n {\n type: 'boolean',\n name: 'allowConfigure',\n },\n {\n type: 'boolean',\n name: 'allowNewMenu',\n },\n {\n type: 'belongsToMany',\n name: 'menuUiSchemas',\n target: 'uiSchemas',\n targetKey: 'x-uid',\n },\n {\n type: 'hasMany',\n name: 'resources',\n target: 'rolesResources',\n sourceKey: 'name',\n targetKey: 'name',\n },\n ],\n} as CollectionOptions;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"rolesResources.js","sourceRoot":"","sources":["../../src/collections/rolesResources.ts"],"names":[],"mappings":";;AAEA,kBAAe;IACb,IAAI,EAAE,gBAAgB;IACtB,KAAK,EAAE,mBAAmB;IAC1B,OAAO,EAAE;QACP;YACE,MAAM,EAAE,IAAI;YACZ,MAAM,EAAE,CAAC,UAAU,EAAE,MAAM,CAAC;SAC7B;KACF;IACD,MAAM,EAAE;QACN;YACE,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,MAAM;SACb;QACD;YACE,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,MAAM;SACb;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,oBAAoB;SAC3B;QACD;YACE,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,uBAAuB;SAChC;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\n\nexport default {\n name: 'rolesResources',\n model: 'RoleResourceModel',\n indexes: [\n {\n unique: true,\n fields: ['roleName', 'name'],\n },\n ],\n fields: [\n {\n type: 'belongsTo',\n name: 'role',\n },\n {\n type: 'string',\n name: 'name',\n },\n {\n type: 'boolean',\n name: 'usingActionsConfig',\n },\n {\n type: 'hasMany',\n name: 'actions',\n target: 'rolesResourcesActions',\n },\n ],\n} as CollectionOptions;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"rolesResourcesActions.js","sourceRoot":"","sources":["../../src/collections/rolesResourcesActions.ts"],"names":[],"mappings":";;AAEA,kBAAe;IACb,IAAI,EAAE,uBAAuB;IAC7B,KAAK,EAAE,yBAAyB;IAChC,MAAM,EAAE;QACN;YACE,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,UAAU;YAChB,UAAU,EAAE,iBAAiB;YAC7B,MAAM,EAAE,gBAAgB;SACzB;QACD;YACE,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,MAAM;SACb;QACD;YACE,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,QAAQ;YACd,YAAY,EAAE,EAAE;SACjB;QACD;YACE,IAAI,EAAE,WAAW;YACjB,IAAI,EAAE,OAAO;YACb,MAAM,EAAE,sBAAsB;SAC/B;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\n\nexport default {\n name: 'rolesResourcesActions',\n model: 'RoleResourceActionModel',\n fields: [\n {\n type: 'belongsTo',\n name: 'resource',\n foreignKey: 'rolesResourceId',\n target: 'rolesResources',\n },\n {\n type: 'string',\n name: 'name',\n },\n {\n type: 'array',\n name: 'fields',\n defaultValue: [],\n },\n {\n type: 'belongsTo',\n name: 'scope',\n target: 'rolesResourcesScopes',\n },\n ],\n} as CollectionOptions;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"rolesResourcesScopes.js","sourceRoot":"","sources":["../../src/collections/rolesResourcesScopes.ts"],"names":[],"mappings":";;AAEA,kBAAe;IACb,IAAI,EAAE,sBAAsB;IAC5B,MAAM,EAAE;QACN;YACE,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,KAAK;SACZ;QACD;YACE,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,MAAM;SACb;QACD;YACE,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,cAAc;SACrB;QACD;YACE,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,OAAO;SACd;KACF;CACmB,CAAC","sourcesContent":["import { CollectionOptions } from '@nocobase/database';\n\nexport default {\n name: 'rolesResourcesScopes',\n fields: [\n {\n type: 'uid',\n name: 'key',\n },\n {\n type: 'string',\n name: 'name',\n },\n {\n type: 'string',\n name: 'resourceName',\n },\n {\n type: 'json',\n name: 'scope',\n },\n ],\n} as CollectionOptions;\n"]}
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAmC;AAA1B,kHAAA,OAAO,OAAA","sourcesContent":["export { default } from './server';\n\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"RoleModel.js","sourceRoot":"","sources":["../../src/model/RoleModel.ts"],"names":[],"mappings":";;;AAAA,iDAA2C;AAG3C,MAAa,SAAU,SAAQ,gBAAK;IAClC,UAAU,CAAC,OAAqB;QAC9B,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;QACxB,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAW,CAAC;QAC5C,IAAI,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAEjC,IAAI,CAAC,IAAI,EAAE;YACT,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC;gBAChB,IAAI,EAAE,QAAQ;aACf,CAAC,CAAC;SACJ;QAED,IAAI,CAAC,WAAW,iCACX,CAAE,IAAI,CAAC,GAAG,CAAC,UAAU,CAAY,IAAI,EAAE,CAAC,KAC3C,cAAc,EAAE,IAAI,CAAC,GAAG,CAAC,gBAAgB,CAAY,IACrD,CAAC;IACL,CAAC;CACF;AAjBD,8BAiBC","sourcesContent":["import { Model } from '@nocobase/database';\nimport { ACL } from '@nocobase/acl';\n\nexport class RoleModel extends Model {\n writeToAcl(options: { acl: ACL }) {\n const { acl } = options;\n const roleName = this.get('name') as string;\n let role = acl.getRole(roleName);\n\n if (!role) {\n role = acl.define({\n role: roleName,\n });\n }\n\n role.setStrategy({\n ...((this.get('strategy') as object) || {}),\n allowConfigure: this.get('allowConfigure') as boolean,\n });\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"RoleResourceActionModel.js","sourceRoot":"","sources":["../../src/model/RoleResourceActionModel.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,iDAAqD;AAGrD,MAAa,uBAAwB,SAAQ,gBAAK;IAC1C,UAAU,CAAC,OAMhB;;;YACC,aAAa;YACb,MAAM,EAAE,GAAa,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;YAE/C,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,GAAG,EAAE,wBAAwB,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;YAEnF,MAAM,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAW,CAAC;YAE9C,MAAM,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAQ,CAAC;YAEzC,MAAM,UAAU,GA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AC,WAAW,CAAC,UAAU,CAAC,CAAC;oBAC/B,CAAC,CAAC,CAAC;oBAEH,MAAM,aAAa,GAAG,YAAY,CAAC,aAAa,IAAI,EAAE,CAAC;oBAEvD,aAAa,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,EAAE;wBACrC,MAAM,gBAAgB,GAAG,GAAG,WAAW,IAAI,YAAY,EAAE,CAAC;wBAE1D,uDAAuD;wBACvD,WAAW,CAAC,uBAAuB,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,YAAY,EAAE,EAAE;4BACtE,GAAG,CAAC,WAAW,CAAC,uBAAuB,CAAC,GAAG,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;4BAChE,gBAAgB;yBACjB,CAAC,CAAC;wBAEH,WAAW,CAAC,uBAAuB,CAAC,GAAG,CAAC,gBAAgB,EAAE;4BACxD,GAAG,CAAC,WAAW,CAAC,uBAAuB,CAAC,GAAG,CAAC,gBAAgB,CAAC,IAAI,EAAE,CAAC;4BACpE,GAAG,IAAI,CAAC,IAAI,IAAI,YAAY,EAAE;yBAC/B,CAAC,CAAC;wBAEH,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;oBACrC,CAAC,CAAC,CAAC;iBACJ;aACF;;KACF;CACF;AA7ED,0DA6EC","sourcesContent":["import { ACL, ACLRole } from '@nocobase/acl';\nimport { Database, Model } from '@nocobase/database';\nimport { AssociationFieldAction, AssociationFieldsActions, GrantHelper } from '../server';\n\nexport class RoleResourceActionModel extends Model {\n async writeToACL(options: {\n acl: ACL;\n role: ACLRole;\n resourceName: string;\n associationFieldsActions: AssociationFieldsActions;\n grantHelper: GrantHelper;\n }) {\n // @ts-ignore\n const db: Database = this.constructor.database;\n\n const { resourceName, role, acl, associationFieldsActions, grantHelper } = options;\n\n const actionName = this.get('name') as string;\n\n const fields = this.get('fields') as any;\n\n const actionPath = `${resourceName}:${actionName}`;\n const actionParams = {\n fields,\n };\n\n // @ts-ignore\n const scope = await this.getScope();\n\n if (scope) {\n actionParams['own'] = scope.get('key') === 'own';\n actionParams['filter'] = scope.get('scope');\n }\n\n role.grantAction(actionPath, actionParams);\n\n const collection = db.getCollection(resourceName);\n\n if (!collection) {\n return;\n }\n\n const availableAction = acl.resolveActionAlias(actionName);\n\n for (const field of fields) {\n const collectionField = collection.getField(field);\n const fieldType = collectionField.get('interface') as string;\n\n const fieldActions: AssociationFieldAction = associationFieldsActions?.[fieldType]?.[availableAction];\n\n const fieldTarget = collectionField.get('target');\n\n if (fieldActions) {\n // grant association actions to role\n const associationActions = fieldActions.associationActions || [];\n associationActions.forEach((associationAction) => {\n const actionName = `${resourceName}.${fieldTarget}:${associationAction}`;\n role.grantAction(actionName);\n });\n\n const targetActions = fieldActions.targetActions || [];\n\n targetActions.forEach((targetAction) => {\n const targetActionPath = `${fieldTarget}:${targetAction}`;\n\n // set resource target action with current resourceName\n grantHelper.resourceTargetActionMap.set(`${role.name}.${resourceName}`, [\n ...(grantHelper.resourceTargetActionMap.get(resourceName) || []),\n targetActionPath,\n ]);\n\n grantHelper.targetActionResourceMap.set(targetActionPath, [\n ...(grantHelper.targetActionResourceMap.get(targetActionPath) || []),\n `${role.name}.${resourceName}`,\n ]);\n\n role.grantAction(targetActionPath);\n });\n }\n }\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"RoleResourceModel.js","sourceRoot":"","sources":["../../src/model/RoleResourceModel.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAAqD;AACrD,uCAA0D;AAI1D,MAAa,iBAAkB,SAAQ,gBAAK;IACpC,MAAM,CAAC,OAA0E;;YACrF,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;YACpD,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;YAElC,MAAM,aAAa,GAAG,WAAW,CAAC,uBAAuB,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,YAAY,EAAE,C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CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;YAE3C,aAAa;YACb,MAAM,OAAO,GAA8B,MAAM,IAAI,CAAC,UAAU,CAAC;gBAC/D,WAAW,EAAE,OAAO,CAAC,WAAW;aACjC,CAAC,CAAC;YAEH,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;gBAC5B,MAAM,MAAM,CAAC,UAAU,CAAC;oBACtB,GAAG;oBACH,IAAI;oBACJ,YAAY;oBACZ,wBAAwB;oBACxB,WAAW,EAAE,OAAO,CAAC,WAAW;iBACjC,CAAC,CAAC;aACJ;QACH,CAAC;KAAA;CACF;AA/DD,8CA+DC","sourcesContent":["import { Database, Model } from '@nocobase/database';\nimport { ACL, ACLResource, ACLRole } from '@nocobase/acl';\nimport { RoleResourceActionModel } from './RoleResourceActionModel';\nimport { AssociationFieldsActions, GrantHelper } from '../server';\n\nexport class RoleResourceModel extends Model {\n async revoke(options: { role: ACLRole; resourceName: string; grantHelper: GrantHelper }) {\n const { role, resourceName, grantHelper } = options;\n role.revokeResource(resourceName);\n\n const targetActions = grantHelper.resourceTargetActionMap.get(`${role.name}.${resourceName}`) || [];\n\n for (const targetAction of targetActions) {\n const targetActionResource = (grantHelper.targetActionResourceMap.get(targetAction) || []).filter(\n (item) => `${role.name}.${resourceName}` !== item,\n );\n\n grantHelper.targetActionResourceMap.set(targetAction, targetActionResource);\n\n if (targetActionResource.length == 0) {\n role.revokeAction(targetAction);\n }\n }\n\n grantHelper.resourceTargetActionMap.set(`${role.name}.${resourceName}`, []);\n }\n\n async writeToACL(options: {\n acl: ACL;\n associationFieldsActions: AssociationFieldsActions;\n grantHelper: GrantHelper;\n transaction: any;\n }) {\n const { acl, associationFieldsActions, grantHelper } = options;\n const resourceName = this.get('name') as string;\n const roleName = this.get('roleName') as string;\n const role = acl.getRole(roleName);\n\n // revoke resource of role\n await this.revoke({ role, resourceName, grantHelper });\n\n // @ts-ignore\n if (this.usingActionsConfig === false) {\n return;\n }\n\n const resource = new ACLResource({\n role,\n name: resourceName,\n });\n\n role.resources.set(resourceName, resource);\n\n // @ts-ignore\n const actions: RoleResourceActionModel[] = await this.getActions({\n transaction: options.transaction,\n });\n\n for (const action of actions) {\n await action.writeToACL({\n acl,\n role,\n resourceName,\n associationFieldsActions,\n grantHelper: options.grantHelper,\n });\n }\n }\n}\n"]}