@nocobase/plugin-acl 0.7.0-alpha.34 → 0.7.0-alpha.57
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/lib/actions/available-actions.js +35 -25
- package/lib/actions/role-check.js +85 -38
- package/lib/actions/role-collections.js +46 -53
- package/lib/collections/roles.js +70 -78
- package/lib/collections/rolesResources.js +27 -30
- package/lib/collections/rolesResourcesActions.js +26 -27
- package/lib/collections/rolesResourcesScopes.js +21 -22
- package/lib/index.js +14 -8
- package/lib/model/RoleModel.js +39 -15
- package/lib/model/RoleResourceActionModel.js +103 -68
- package/lib/model/RoleResourceModel.js +125 -62
- package/lib/server.js +609 -354
- package/package.json +5 -10
- package/src/__tests__/own.test.ts +5 -6
- package/esm/actions/available-actions.d.ts +0 -7
- package/esm/actions/available-actions.js +0 -26
- package/esm/actions/available-actions.js.map +0 -1
- package/esm/actions/role-check.d.ts +0 -1
- package/esm/actions/role-check.js +0 -38
- package/esm/actions/role-check.js.map +0 -1
- package/esm/actions/role-collections.d.ts +0 -7
- package/esm/actions/role-collections.js +0 -54
- package/esm/actions/role-collections.js.map +0 -1
- package/esm/collections/roles.d.ts +0 -3
- package/esm/collections/roles.js +0 -78
- package/esm/collections/roles.js.map +0 -1
- package/esm/collections/rolesResources.d.ts +0 -3
- package/esm/collections/rolesResources.js +0 -30
- package/esm/collections/rolesResources.js.map +0 -1
- package/esm/collections/rolesResourcesActions.d.ts +0 -3
- package/esm/collections/rolesResourcesActions.js +0 -27
- package/esm/collections/rolesResourcesActions.js.map +0 -1
- package/esm/collections/rolesResourcesScopes.d.ts +0 -3
- package/esm/collections/rolesResourcesScopes.js +0 -22
- package/esm/collections/rolesResourcesScopes.js.map +0 -1
- package/esm/index.d.ts +0 -1
- package/esm/index.js +0 -2
- package/esm/index.js.map +0 -1
- package/esm/model/RoleModel.d.ts +0 -7
- package/esm/model/RoleModel.js +0 -15
- package/esm/model/RoleModel.js.map +0 -1
- package/esm/model/RoleResourceActionModel.d.ts +0 -12
- package/esm/model/RoleResourceActionModel.js +0 -67
- package/esm/model/RoleResourceActionModel.js.map +0 -1
- package/esm/model/RoleResourceModel.d.ts +0 -16
- package/esm/model/RoleResourceModel.js +0 -61
- package/esm/model/RoleResourceModel.js.map +0 -1
- package/esm/server.d.ts +0 -33
- package/esm/server.js +0 -369
- package/esm/server.js.map +0 -1
- package/lib/actions/available-actions.js.map +0 -1
- package/lib/actions/role-check.js.map +0 -1
- package/lib/actions/role-collections.js.map +0 -1
- package/lib/collections/roles.js.map +0 -1
- package/lib/collections/rolesResources.js.map +0 -1
- package/lib/collections/rolesResourcesActions.js.map +0 -1
- package/lib/collections/rolesResourcesScopes.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/model/RoleModel.js.map +0 -1
- package/lib/model/RoleResourceActionModel.js.map +0 -1
- package/lib/model/RoleResourceModel.js.map +0 -1
- package/lib/server.js.map +0 -1
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/plugin-acl",
|
|
3
|
-
"version": "0.7.0-alpha.
|
|
3
|
+
"version": "0.7.0-alpha.57",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"licenses": [
|
|
@@ -11,20 +11,15 @@
|
|
|
11
11
|
],
|
|
12
12
|
"main": "./lib/index.js",
|
|
13
13
|
"types": "./lib/index.d.ts",
|
|
14
|
-
"scripts": {
|
|
15
|
-
"build": "rimraf -rf lib esm dist && npm run build:cjs && npm run build:esm",
|
|
16
|
-
"build:cjs": "tsc --project tsconfig.build.json",
|
|
17
|
-
"build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir esm"
|
|
18
|
-
},
|
|
19
14
|
"dependencies": {
|
|
20
|
-
"@nocobase/acl": "0.7.0-alpha.
|
|
21
|
-
"@nocobase/database": "0.7.0-alpha.
|
|
22
|
-
"@nocobase/server": "0.7.0-alpha.
|
|
15
|
+
"@nocobase/acl": "0.7.0-alpha.57",
|
|
16
|
+
"@nocobase/database": "0.7.0-alpha.57",
|
|
17
|
+
"@nocobase/server": "0.7.0-alpha.57"
|
|
23
18
|
},
|
|
24
19
|
"repository": {
|
|
25
20
|
"type": "git",
|
|
26
21
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
27
22
|
"directory": "packages/plugins/acl"
|
|
28
23
|
},
|
|
29
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "33f076e430645055d79254592971c50d9f131a6d"
|
|
30
25
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { mockServer, MockServer } from '@nocobase/test';
|
|
2
|
-
import { Database } from '@nocobase/database';
|
|
3
1
|
import { ACL } from '@nocobase/acl';
|
|
4
|
-
import {
|
|
5
|
-
import PluginUiSchema from '@nocobase/plugin-ui-schema-storage';
|
|
6
|
-
import PluginCollectionManager from '@nocobase/plugin-collection-manager';
|
|
2
|
+
import { Database } from '@nocobase/database';
|
|
7
3
|
import PluginACL from '@nocobase/plugin-acl';
|
|
4
|
+
import PluginCollectionManager from '@nocobase/plugin-collection-manager';
|
|
5
|
+
import PluginUiSchema from '@nocobase/plugin-ui-schema-storage';
|
|
8
6
|
import PluginUser from '@nocobase/plugin-users';
|
|
7
|
+
import { mockServer, MockServer } from '@nocobase/test';
|
|
9
8
|
import supertest from 'supertest';
|
|
10
9
|
|
|
11
10
|
describe('own test', () => {
|
|
@@ -38,7 +37,7 @@ describe('own test', () => {
|
|
|
38
37
|
app.plugin(PluginCollectionManager);
|
|
39
38
|
app.plugin(PluginUser, {
|
|
40
39
|
jwt: {
|
|
41
|
-
secret: process.env.
|
|
40
|
+
secret: process.env.APP_KEY || 'test-key',
|
|
42
41
|
},
|
|
43
42
|
});
|
|
44
43
|
|
|
@@ -1,26 +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
|
-
const availableActionResource = {
|
|
11
|
-
name: 'availableActions',
|
|
12
|
-
actions: {
|
|
13
|
-
list(ctx, next) {
|
|
14
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
const acl = ctx.app.acl;
|
|
16
|
-
const availableActions = acl.getAvailableActions();
|
|
17
|
-
ctx.body = Array.from(availableActions.entries()).map(([, { name, options }]) => {
|
|
18
|
-
return Object.assign(Object.assign({}, options), { name });
|
|
19
|
-
});
|
|
20
|
-
yield next();
|
|
21
|
-
});
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
export { availableActionResource };
|
|
26
|
-
//# sourceMappingURL=available-actions.js.map
|
|
@@ -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;AAEF,OAAO,EAAE,uBAAuB,EAAE,CAAC","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
|
-
export declare function checkAction(ctx: any, next: any): Promise<void>;
|
|
@@ -1,38 +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
|
-
const map2obj = (map) => {
|
|
11
|
-
const obj = {};
|
|
12
|
-
for (let [key, value] of map) {
|
|
13
|
-
obj[key] = value;
|
|
14
|
-
}
|
|
15
|
-
return obj;
|
|
16
|
-
};
|
|
17
|
-
export function checkAction(ctx, next) {
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
const currentRole = ctx.state.currentRole;
|
|
20
|
-
if (currentRole) {
|
|
21
|
-
const roleInstance = yield ctx.db.getRepository('roles').findOne({
|
|
22
|
-
filter: {
|
|
23
|
-
name: currentRole,
|
|
24
|
-
},
|
|
25
|
-
appends: ['menuUiSchemas'],
|
|
26
|
-
});
|
|
27
|
-
const anonymous = yield ctx.db.getRepository('roles').findOne({
|
|
28
|
-
filter: {
|
|
29
|
-
name: 'anonymous',
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
const role = ctx.app.acl.getRole(currentRole);
|
|
33
|
-
ctx.body = Object.assign(Object.assign({}, role.toJSON()), { resources: [...role.resources.keys()], actionAlias: map2obj(ctx.app.acl.actionAlias), allowAll: currentRole === 'root', allowConfigure: roleInstance.get('allowConfigure'), allowMenuItemIds: roleInstance.get('menuUiSchemas').map((uiSchema) => uiSchema.get('x-uid')), allowAnonymous: !!anonymous });
|
|
34
|
-
}
|
|
35
|
-
yield next();
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=role-check.js.map
|
|
@@ -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,MAAM,UAAgB,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","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,54 +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
|
-
const roleCollectionsResource = {
|
|
11
|
-
name: 'roles.collections',
|
|
12
|
-
actions: {
|
|
13
|
-
list(ctx, next) {
|
|
14
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
const role = ctx.action.params.associatedIndex;
|
|
16
|
-
const db = ctx.db;
|
|
17
|
-
const collectionRepository = db.getRepository('collections');
|
|
18
|
-
// all collections
|
|
19
|
-
const collections = yield collectionRepository.find({
|
|
20
|
-
filter: ctx.action.params.filter,
|
|
21
|
-
});
|
|
22
|
-
// role collections
|
|
23
|
-
const roleResources = yield db.getRepository('rolesResources').find({
|
|
24
|
-
filter: {
|
|
25
|
-
roleName: role,
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
// role collections
|
|
29
|
-
const roleResourcesNames = roleResources.map((roleResource) => roleResource.get('name'));
|
|
30
|
-
const roleResourceActionResourceNames = roleResources
|
|
31
|
-
.filter((roleResources) => roleResources.get('usingActionsConfig'))
|
|
32
|
-
.map((roleResources) => roleResources.get('name'));
|
|
33
|
-
ctx.body = collections
|
|
34
|
-
.map((collection) => {
|
|
35
|
-
const exists = roleResourcesNames.includes(collection.get('name'));
|
|
36
|
-
const usingConfig = roleResourceActionResourceNames.includes(collection.get('name'))
|
|
37
|
-
? 'resourceAction'
|
|
38
|
-
: 'strategy';
|
|
39
|
-
return {
|
|
40
|
-
name: collection.get('name'),
|
|
41
|
-
title: collection.get('title'),
|
|
42
|
-
roleName: role,
|
|
43
|
-
usingConfig,
|
|
44
|
-
exists,
|
|
45
|
-
};
|
|
46
|
-
})
|
|
47
|
-
.sort((a, b) => (a.name > b.name ? 1 : -1));
|
|
48
|
-
yield next();
|
|
49
|
-
});
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
export { roleCollectionsResource };
|
|
54
|
-
//# sourceMappingURL=role-collections.js.map
|
|
@@ -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,EAAE;QACD,IAAI,CAAC,GAAG,EAAE,IAAI;;gBAClB,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC;gBAE/C,MAAM,EAAE,GAAa,GAAG,CAAC,EAAE,CAAC;gBAC5B,MAAM,oBAAoB,GAAG,EAAE,CAAC,aAAa,CAAC,aAAa,CAAC,CAAC;gBAE7D,kBAAkB;gBAClB,MAAM,WAAW,GAAG,MAAM,oBAAoB,CAAC,IAAI,CAAC;oBAClD,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM;iBACjC,CAAC,CAAC;gBAEH,mBAAmB;gBACnB,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC;oBAClE,MAAM,EAAE;wB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EAAE,CAAC","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"]}
|
package/esm/collections/roles.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
name: 'roles',
|
|
3
|
-
title: '{{t("Roles")}}',
|
|
4
|
-
autoGenId: false,
|
|
5
|
-
model: 'RoleModel',
|
|
6
|
-
filterTargetKey: 'name',
|
|
7
|
-
// targetKey: 'name',
|
|
8
|
-
sortable: true,
|
|
9
|
-
fields: [
|
|
10
|
-
{
|
|
11
|
-
type: 'uid',
|
|
12
|
-
name: 'name',
|
|
13
|
-
prefix: 'r_',
|
|
14
|
-
primaryKey: true,
|
|
15
|
-
interface: 'input',
|
|
16
|
-
uiSchema: {
|
|
17
|
-
type: 'string',
|
|
18
|
-
title: '{{t("Role UID")}}',
|
|
19
|
-
'x-component': 'Input',
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
type: 'string',
|
|
24
|
-
name: 'title',
|
|
25
|
-
unique: true,
|
|
26
|
-
interface: 'input',
|
|
27
|
-
uiSchema: {
|
|
28
|
-
type: 'string',
|
|
29
|
-
title: '{{t("Role name")}}',
|
|
30
|
-
'x-component': 'Input',
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
type: 'boolean',
|
|
35
|
-
name: 'default',
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
type: 'string',
|
|
39
|
-
name: 'description',
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
type: 'json',
|
|
43
|
-
name: 'strategy',
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
type: 'boolean',
|
|
47
|
-
name: 'default',
|
|
48
|
-
defaultValue: false,
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
type: 'boolean',
|
|
52
|
-
name: 'hidden',
|
|
53
|
-
defaultValue: false,
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
type: 'boolean',
|
|
57
|
-
name: 'allowConfigure',
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
type: 'boolean',
|
|
61
|
-
name: 'allowNewMenu',
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
type: 'belongsToMany',
|
|
65
|
-
name: 'menuUiSchemas',
|
|
66
|
-
target: 'uiSchemas',
|
|
67
|
-
targetKey: 'x-uid',
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
type: 'hasMany',
|
|
71
|
-
name: 'resources',
|
|
72
|
-
target: 'rolesResources',
|
|
73
|
-
sourceKey: 'name',
|
|
74
|
-
targetKey: 'name',
|
|
75
|
-
},
|
|
76
|
-
],
|
|
77
|
-
};
|
|
78
|
-
//# sourceMappingURL=roles.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"roles.js","sourceRoot":"","sources":["../../src/collections/roles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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,30 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
name: 'rolesResources',
|
|
3
|
-
model: 'RoleResourceModel',
|
|
4
|
-
indexes: [
|
|
5
|
-
{
|
|
6
|
-
unique: true,
|
|
7
|
-
fields: ['roleName', 'name'],
|
|
8
|
-
},
|
|
9
|
-
],
|
|
10
|
-
fields: [
|
|
11
|
-
{
|
|
12
|
-
type: 'belongsTo',
|
|
13
|
-
name: 'role',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
type: 'string',
|
|
17
|
-
name: 'name',
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
type: 'boolean',
|
|
21
|
-
name: 'usingActionsConfig',
|
|
22
|
-
},
|
|
23
|
-
{
|
|
24
|
-
type: 'hasMany',
|
|
25
|
-
name: 'actions',
|
|
26
|
-
target: 'rolesResourcesActions',
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
};
|
|
30
|
-
//# sourceMappingURL=rolesResources.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rolesResources.js","sourceRoot":"","sources":["../../src/collections/rolesResources.ts"],"names":[],"mappings":"AAEA,eAAe;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,27 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
name: 'rolesResourcesActions',
|
|
3
|
-
model: 'RoleResourceActionModel',
|
|
4
|
-
fields: [
|
|
5
|
-
{
|
|
6
|
-
type: 'belongsTo',
|
|
7
|
-
name: 'resource',
|
|
8
|
-
foreignKey: 'rolesResourceId',
|
|
9
|
-
target: 'rolesResources',
|
|
10
|
-
},
|
|
11
|
-
{
|
|
12
|
-
type: 'string',
|
|
13
|
-
name: 'name',
|
|
14
|
-
},
|
|
15
|
-
{
|
|
16
|
-
type: 'array',
|
|
17
|
-
name: 'fields',
|
|
18
|
-
defaultValue: [],
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
type: 'belongsTo',
|
|
22
|
-
name: 'scope',
|
|
23
|
-
target: 'rolesResourcesScopes',
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
};
|
|
27
|
-
//# sourceMappingURL=rolesResourcesActions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rolesResourcesActions.js","sourceRoot":"","sources":["../../src/collections/rolesResourcesActions.ts"],"names":[],"mappings":"AAEA,eAAe;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,22 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
name: 'rolesResourcesScopes',
|
|
3
|
-
fields: [
|
|
4
|
-
{
|
|
5
|
-
type: 'uid',
|
|
6
|
-
name: 'key',
|
|
7
|
-
},
|
|
8
|
-
{
|
|
9
|
-
type: 'string',
|
|
10
|
-
name: 'name',
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
type: 'string',
|
|
14
|
-
name: 'resourceName',
|
|
15
|
-
},
|
|
16
|
-
{
|
|
17
|
-
type: 'json',
|
|
18
|
-
name: 'scope',
|
|
19
|
-
},
|
|
20
|
-
],
|
|
21
|
-
};
|
|
22
|
-
//# sourceMappingURL=rolesResourcesScopes.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rolesResourcesScopes.js","sourceRoot":"","sources":["../../src/collections/rolesResourcesScopes.ts"],"names":[],"mappings":"AAEA,eAAe;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/esm/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './server';
|
package/esm/index.js
DELETED
package/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC","sourcesContent":["export { default } from './server';\n\n"]}
|
package/esm/model/RoleModel.d.ts
DELETED
package/esm/model/RoleModel.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { Model } from '@nocobase/database';
|
|
2
|
-
export class RoleModel extends Model {
|
|
3
|
-
writeToAcl(options) {
|
|
4
|
-
const { acl } = options;
|
|
5
|
-
const roleName = this.get('name');
|
|
6
|
-
let role = acl.getRole(roleName);
|
|
7
|
-
if (!role) {
|
|
8
|
-
role = acl.define({
|
|
9
|
-
role: roleName,
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
role.setStrategy(Object.assign(Object.assign({}, (this.get('strategy') || {})), { allowConfigure: this.get('allowConfigure') }));
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=RoleModel.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RoleModel.js","sourceRoot":"","sources":["../../src/model/RoleModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,MAAM,OAAO,SAAU,SAAQ,KAAK;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","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,12 +0,0 @@
|
|
|
1
|
-
import { ACL, ACLRole } from '@nocobase/acl';
|
|
2
|
-
import { Model } from '@nocobase/database';
|
|
3
|
-
import { AssociationFieldsActions, GrantHelper } from '../server';
|
|
4
|
-
export declare class RoleResourceActionModel extends Model {
|
|
5
|
-
writeToACL(options: {
|
|
6
|
-
acl: ACL;
|
|
7
|
-
role: ACLRole;
|
|
8
|
-
resourceName: string;
|
|
9
|
-
associationFieldsActions: AssociationFieldsActions;
|
|
10
|
-
grantHelper: GrantHelper;
|
|
11
|
-
}): Promise<void>;
|
|
12
|
-
}
|
|
@@ -1,67 +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
|
-
export class RoleResourceActionModel extends Model {
|
|
12
|
-
writeToACL(options) {
|
|
13
|
-
var _a;
|
|
14
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
const db = this.constructor.database;
|
|
17
|
-
const { resourceName, role, acl, associationFieldsActions, grantHelper } = options;
|
|
18
|
-
const actionName = this.get('name');
|
|
19
|
-
const fields = this.get('fields');
|
|
20
|
-
const actionPath = `${resourceName}:${actionName}`;
|
|
21
|
-
const actionParams = {
|
|
22
|
-
fields,
|
|
23
|
-
};
|
|
24
|
-
// @ts-ignore
|
|
25
|
-
const scope = yield this.getScope();
|
|
26
|
-
if (scope) {
|
|
27
|
-
actionParams['own'] = scope.get('key') === 'own';
|
|
28
|
-
actionParams['filter'] = scope.get('scope');
|
|
29
|
-
}
|
|
30
|
-
role.grantAction(actionPath, actionParams);
|
|
31
|
-
const collection = db.getCollection(resourceName);
|
|
32
|
-
if (!collection) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
const availableAction = acl.resolveActionAlias(actionName);
|
|
36
|
-
for (const field of fields) {
|
|
37
|
-
const collectionField = collection.getField(field);
|
|
38
|
-
const fieldType = collectionField.get('interface');
|
|
39
|
-
const fieldActions = (_a = associationFieldsActions === null || associationFieldsActions === void 0 ? void 0 : associationFieldsActions[fieldType]) === null || _a === void 0 ? void 0 : _a[availableAction];
|
|
40
|
-
const fieldTarget = collectionField.get('target');
|
|
41
|
-
if (fieldActions) {
|
|
42
|
-
// grant association actions to role
|
|
43
|
-
const associationActions = fieldActions.associationActions || [];
|
|
44
|
-
associationActions.forEach((associationAction) => {
|
|
45
|
-
const actionName = `${resourceName}.${fieldTarget}:${associationAction}`;
|
|
46
|
-
role.grantAction(actionName);
|
|
47
|
-
});
|
|
48
|
-
const targetActions = fieldActions.targetActions || [];
|
|
49
|
-
targetActions.forEach((targetAction) => {
|
|
50
|
-
const targetActionPath = `${fieldTarget}:${targetAction}`;
|
|
51
|
-
// set resource target action with current resourceName
|
|
52
|
-
grantHelper.resourceTargetActionMap.set(`${role.name}.${resourceName}`, [
|
|
53
|
-
...(grantHelper.resourceTargetActionMap.get(resourceName) || []),
|
|
54
|
-
targetActionPath,
|
|
55
|
-
]);
|
|
56
|
-
grantHelper.targetActionResourceMap.set(targetActionPath, [
|
|
57
|
-
...(grantHelper.targetActionResourceMap.get(targetActionPath) || []),
|
|
58
|
-
`${role.name}.${resourceName}`,
|
|
59
|
-
]);
|
|
60
|
-
role.grantAction(targetActionPath);
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
//# sourceMappingURL=RoleResourceActionModel.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"RoleResourceActionModel.js","sourceRoot":"","sources":["../../src/model/RoleResourceActionModel.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAY,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAGrD,MAAM,OAAO,uBAAwB,SAAQ,KAAK;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,GAAG,GAAG,YAAY,IAAI,UAAU,EAAE,CAAC;YACnD,MAAM,YAAY,GAAG;gBACnB,MAAM;aAC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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","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,16 +0,0 @@
|
|
|
1
|
-
import { Model } from '@nocobase/database';
|
|
2
|
-
import { ACL, ACLRole } from '@nocobase/acl';
|
|
3
|
-
import { AssociationFieldsActions, GrantHelper } from '../server';
|
|
4
|
-
export declare class RoleResourceModel extends Model {
|
|
5
|
-
revoke(options: {
|
|
6
|
-
role: ACLRole;
|
|
7
|
-
resourceName: string;
|
|
8
|
-
grantHelper: GrantHelper;
|
|
9
|
-
}): Promise<void>;
|
|
10
|
-
writeToACL(options: {
|
|
11
|
-
acl: ACL;
|
|
12
|
-
associationFieldsActions: AssociationFieldsActions;
|
|
13
|
-
grantHelper: GrantHelper;
|
|
14
|
-
transaction: any;
|
|
15
|
-
}): Promise<void>;
|
|
16
|
-
}
|