@nocobase/plugin-acl 0.21.0-alpha.9 → 1.0.0-alpha.2
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/dist/externalVersion.js +8 -8
- package/dist/server/middlewares/with-acl-meta.js +4 -3
- package/dist/server/migrations/20221214072638-set-role-snippets.js +1 -0
- package/dist/server/model/RoleResourceActionModel.d.ts +0 -3
- package/dist/server/model/RoleResourceActionModel.js +1 -42
- package/dist/server/model/RoleResourceModel.d.ts +0 -4
- package/dist/server/model/RoleResourceModel.js +4 -17
- package/dist/server/server.d.ts +3 -21
- package/dist/server/server.js +2 -66
- package/package.json +10 -10
package/dist/externalVersion.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
"@nocobase/client": "0.
|
|
2
|
+
"@nocobase/client": "1.0.0-alpha.2",
|
|
3
3
|
"react": "18.2.0",
|
|
4
4
|
"@formily/shared": "2.3.0",
|
|
5
5
|
"antd": "5.12.8",
|
|
6
6
|
"@formily/react": "2.3.0",
|
|
7
7
|
"@ant-design/icons": "5.2.6",
|
|
8
8
|
"react-i18next": "11.18.6",
|
|
9
|
-
"@nocobase/utils": "0.
|
|
10
|
-
"@nocobase/actions": "0.
|
|
11
|
-
"@nocobase/cache": "0.
|
|
12
|
-
"@nocobase/database": "0.
|
|
13
|
-
"@nocobase/server": "0.
|
|
9
|
+
"@nocobase/utils": "1.0.0-alpha.2",
|
|
10
|
+
"@nocobase/actions": "1.0.0-alpha.2",
|
|
11
|
+
"@nocobase/cache": "1.0.0-alpha.2",
|
|
12
|
+
"@nocobase/database": "1.0.0-alpha.2",
|
|
13
|
+
"@nocobase/server": "1.0.0-alpha.2",
|
|
14
14
|
"async-mutex": "0.3.2",
|
|
15
15
|
"lodash": "4.17.21",
|
|
16
|
-
"@nocobase/test": "0.
|
|
16
|
+
"@nocobase/test": "1.0.0-alpha.2",
|
|
17
17
|
"@formily/core": "2.3.0",
|
|
18
18
|
"ahooks": "3.7.8",
|
|
19
19
|
"@formily/antd-v5": "1.1.9",
|
|
20
20
|
"antd-style": "3.4.5",
|
|
21
|
-
"@nocobase/acl": "0.
|
|
21
|
+
"@nocobase/acl": "1.0.0-alpha.2"
|
|
22
22
|
};
|
|
@@ -31,8 +31,9 @@ __export(with_acl_meta_exports, {
|
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(with_acl_meta_exports);
|
|
33
33
|
var import_lodash = __toESM(require("lodash"));
|
|
34
|
-
var import_acl = require("@nocobase/acl");
|
|
35
34
|
var import_database = require("@nocobase/database");
|
|
35
|
+
class NoPermissionError extends Error {
|
|
36
|
+
}
|
|
36
37
|
function createWithACLMetaMiddleware() {
|
|
37
38
|
return async (ctx, next) => {
|
|
38
39
|
var _a, _b, _c, _d;
|
|
@@ -109,13 +110,13 @@ function createWithACLMetaMiddleware() {
|
|
|
109
110
|
},
|
|
110
111
|
permission: {},
|
|
111
112
|
throw(...args) {
|
|
112
|
-
throw new
|
|
113
|
+
throw new NoPermissionError(...args);
|
|
113
114
|
}
|
|
114
115
|
};
|
|
115
116
|
try {
|
|
116
117
|
await acl.getActionParams(actionCtx);
|
|
117
118
|
} catch (e) {
|
|
118
|
-
if (e instanceof
|
|
119
|
+
if (e instanceof NoPermissionError) {
|
|
119
120
|
continue;
|
|
120
121
|
}
|
|
121
122
|
throw e;
|
|
@@ -21,6 +21,7 @@ __export(set_role_snippets_exports, {
|
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(set_role_snippets_exports);
|
|
23
23
|
var import_server = require("@nocobase/server");
|
|
24
|
+
/* istanbul ignore file -- @preserve */
|
|
24
25
|
class set_role_snippets_default extends import_server.Migration {
|
|
25
26
|
appVersion = "<0.9.0-alpha.1";
|
|
26
27
|
async up() {
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { ACL, ACLRole } from '@nocobase/acl';
|
|
2
2
|
import { Model } from '@nocobase/database';
|
|
3
|
-
import { AssociationFieldsActions, GrantHelper } from '../server';
|
|
4
3
|
export declare class RoleResourceActionModel extends Model {
|
|
5
4
|
writeToACL(options: {
|
|
6
5
|
acl: ACL;
|
|
7
6
|
role: ACLRole;
|
|
8
7
|
resourceName: string;
|
|
9
|
-
associationFieldsActions: AssociationFieldsActions;
|
|
10
|
-
grantHelper: GrantHelper;
|
|
11
8
|
}): Promise<void>;
|
|
12
9
|
}
|
|
@@ -23,9 +23,7 @@ module.exports = __toCommonJS(RoleResourceActionModel_exports);
|
|
|
23
23
|
var import_database = require("@nocobase/database");
|
|
24
24
|
class RoleResourceActionModel extends import_database.Model {
|
|
25
25
|
async writeToACL(options) {
|
|
26
|
-
|
|
27
|
-
const db = this.constructor.database;
|
|
28
|
-
const { resourceName, role, acl, associationFieldsActions, grantHelper } = options;
|
|
26
|
+
const { resourceName, role } = options;
|
|
29
27
|
const actionName = this.get("name");
|
|
30
28
|
const fields = this.get("fields");
|
|
31
29
|
const actionPath = `${resourceName}:${actionName}`;
|
|
@@ -38,45 +36,6 @@ class RoleResourceActionModel extends import_database.Model {
|
|
|
38
36
|
actionParams["filter"] = scope.get("scope");
|
|
39
37
|
}
|
|
40
38
|
role.grantAction(actionPath, actionParams);
|
|
41
|
-
const collection = db.getCollection(resourceName);
|
|
42
|
-
if (!collection) {
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
const availableAction = acl.resolveActionAlias(actionName);
|
|
46
|
-
for (const field of fields) {
|
|
47
|
-
const collectionField = collection.getField(field);
|
|
48
|
-
if (!collectionField) {
|
|
49
|
-
console.log(`field ${field} does not exist at ${collection.name}`);
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
const fieldType = collectionField.get("type");
|
|
53
|
-
const fieldActions = (_a = associationFieldsActions == null ? void 0 : associationFieldsActions[fieldType]) == null ? void 0 : _a[availableAction];
|
|
54
|
-
const fieldTarget = collectionField.get("target");
|
|
55
|
-
if (fieldActions) {
|
|
56
|
-
const associationActions = fieldActions.associationActions || [];
|
|
57
|
-
associationActions.forEach((associationAction) => {
|
|
58
|
-
const actionName2 = `${resourceName}.${collectionField.get("name")}:${associationAction}`;
|
|
59
|
-
role.grantAction(actionName2);
|
|
60
|
-
});
|
|
61
|
-
const targetActions = fieldActions.targetActions || [];
|
|
62
|
-
targetActions.forEach((targetAction) => {
|
|
63
|
-
const targetActionPath = `${fieldTarget}:${targetAction}`;
|
|
64
|
-
const existsAction = role.getActionParams(targetActionPath);
|
|
65
|
-
if (existsAction) {
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
grantHelper.resourceTargetActionMap.set(`${role.name}.${resourceName}`, [
|
|
69
|
-
...grantHelper.resourceTargetActionMap.get(resourceName) || [],
|
|
70
|
-
targetActionPath
|
|
71
|
-
]);
|
|
72
|
-
grantHelper.targetActionResourceMap.set(targetActionPath, [
|
|
73
|
-
...grantHelper.targetActionResourceMap.get(targetActionPath) || [],
|
|
74
|
-
`${role.name}.${resourceName}`
|
|
75
|
-
]);
|
|
76
|
-
role.grantAction(targetActionPath);
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
39
|
}
|
|
81
40
|
}
|
|
82
41
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { ACL, ACLRole } from '@nocobase/acl';
|
|
2
2
|
import { Model } from '@nocobase/database';
|
|
3
|
-
import { AssociationFieldsActions, GrantHelper } from '../server';
|
|
4
3
|
export declare class RoleResourceModel extends Model {
|
|
5
4
|
revoke(options: {
|
|
6
5
|
role: ACLRole;
|
|
7
6
|
resourceName: string;
|
|
8
|
-
grantHelper: GrantHelper;
|
|
9
7
|
}): Promise<void>;
|
|
10
8
|
writeToACL(options: {
|
|
11
9
|
acl: ACL;
|
|
12
|
-
associationFieldsActions: AssociationFieldsActions;
|
|
13
|
-
grantHelper: GrantHelper;
|
|
14
10
|
transaction: any;
|
|
15
11
|
}): Promise<void>;
|
|
16
12
|
}
|
|
@@ -24,22 +24,11 @@ var import_acl = require("@nocobase/acl");
|
|
|
24
24
|
var import_database = require("@nocobase/database");
|
|
25
25
|
class RoleResourceModel extends import_database.Model {
|
|
26
26
|
async revoke(options) {
|
|
27
|
-
const { role, resourceName
|
|
27
|
+
const { role, resourceName } = options;
|
|
28
28
|
role.revokeResource(resourceName);
|
|
29
|
-
const targetActions = grantHelper.resourceTargetActionMap.get(`${role.name}.${resourceName}`) || [];
|
|
30
|
-
for (const targetAction of targetActions) {
|
|
31
|
-
const targetActionResource = (grantHelper.targetActionResourceMap.get(targetAction) || []).filter(
|
|
32
|
-
(item) => `${role.name}.${resourceName}` !== item
|
|
33
|
-
);
|
|
34
|
-
grantHelper.targetActionResourceMap.set(targetAction, targetActionResource);
|
|
35
|
-
if (targetActionResource.length == 0) {
|
|
36
|
-
role.revokeAction(targetAction);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
grantHelper.resourceTargetActionMap.set(`${role.name}.${resourceName}`, []);
|
|
40
29
|
}
|
|
41
30
|
async writeToACL(options) {
|
|
42
|
-
const { acl
|
|
31
|
+
const { acl } = options;
|
|
43
32
|
const resourceName = this.get("name");
|
|
44
33
|
const roleName = this.get("roleName");
|
|
45
34
|
const role = acl.getRole(roleName);
|
|
@@ -47,7 +36,7 @@ class RoleResourceModel extends import_database.Model {
|
|
|
47
36
|
console.log(`${roleName} role does not exist`);
|
|
48
37
|
return;
|
|
49
38
|
}
|
|
50
|
-
await this.revoke({ role, resourceName
|
|
39
|
+
await this.revoke({ role, resourceName });
|
|
51
40
|
if (this.usingActionsConfig === false) {
|
|
52
41
|
return;
|
|
53
42
|
}
|
|
@@ -63,9 +52,7 @@ class RoleResourceModel extends import_database.Model {
|
|
|
63
52
|
await action.writeToACL({
|
|
64
53
|
acl,
|
|
65
54
|
role,
|
|
66
|
-
resourceName
|
|
67
|
-
associationFieldsActions,
|
|
68
|
-
grantHelper: options.grantHelper
|
|
55
|
+
resourceName
|
|
69
56
|
});
|
|
70
57
|
}
|
|
71
58
|
}
|
package/dist/server/server.d.ts
CHANGED
|
@@ -1,30 +1,12 @@
|
|
|
1
|
+
import { Transaction } from '@nocobase/database';
|
|
1
2
|
import { Plugin } from '@nocobase/server';
|
|
2
3
|
import { RoleModel } from './model/RoleModel';
|
|
3
4
|
import { RoleResourceActionModel } from './model/RoleResourceActionModel';
|
|
4
5
|
import { RoleResourceModel } from './model/RoleResourceModel';
|
|
5
|
-
export interface AssociationFieldAction {
|
|
6
|
-
associationActions: string[];
|
|
7
|
-
targetActions?: string[];
|
|
8
|
-
}
|
|
9
|
-
interface AssociationFieldActions {
|
|
10
|
-
[availableActionName: string]: AssociationFieldAction;
|
|
11
|
-
}
|
|
12
|
-
export interface AssociationFieldsActions {
|
|
13
|
-
[associationType: string]: AssociationFieldActions;
|
|
14
|
-
}
|
|
15
|
-
export declare class GrantHelper {
|
|
16
|
-
resourceTargetActionMap: Map<string, string[]>;
|
|
17
|
-
targetActionResourceMap: Map<string, string[]>;
|
|
18
|
-
constructor();
|
|
19
|
-
}
|
|
20
6
|
export declare class PluginACLServer extends Plugin {
|
|
21
|
-
associationFieldsActions: AssociationFieldsActions;
|
|
22
|
-
grantHelper: GrantHelper;
|
|
23
7
|
get acl(): import("@nocobase/acl").ACL;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
writeResourceToACL(resourceModel: RoleResourceModel, transaction: any): Promise<void>;
|
|
27
|
-
writeActionToACL(actionModel: RoleResourceActionModel, transaction: any): Promise<void>;
|
|
8
|
+
writeResourceToACL(resourceModel: RoleResourceModel, transaction: Transaction): Promise<void>;
|
|
9
|
+
writeActionToACL(actionModel: RoleResourceActionModel, transaction: Transaction): Promise<void>;
|
|
28
10
|
writeRolesToACL(options: any): Promise<void>;
|
|
29
11
|
writeRoleToACL(role: RoleModel, options?: any): Promise<void>;
|
|
30
12
|
beforeLoad(): Promise<void>;
|
package/dist/server/server.js
CHANGED
|
@@ -27,7 +27,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
28
|
var server_exports = {};
|
|
29
29
|
__export(server_exports, {
|
|
30
|
-
GrantHelper: () => GrantHelper,
|
|
31
30
|
PluginACLServer: () => PluginACLServer,
|
|
32
31
|
default: () => server_default
|
|
33
32
|
});
|
|
@@ -47,74 +46,14 @@ var import_with_acl_meta = require("./middlewares/with-acl-meta");
|
|
|
47
46
|
var import_RoleModel = require("./model/RoleModel");
|
|
48
47
|
var import_RoleResourceActionModel = require("./model/RoleResourceActionModel");
|
|
49
48
|
var import_RoleResourceModel = require("./model/RoleResourceModel");
|
|
50
|
-
class GrantHelper {
|
|
51
|
-
resourceTargetActionMap = /* @__PURE__ */ new Map();
|
|
52
|
-
targetActionResourceMap = /* @__PURE__ */ new Map();
|
|
53
|
-
constructor() {
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
49
|
class PluginACLServer extends import_server.Plugin {
|
|
57
|
-
// association field actions config
|
|
58
|
-
associationFieldsActions = {};
|
|
59
|
-
grantHelper = new GrantHelper();
|
|
60
50
|
get acl() {
|
|
61
51
|
return this.app.acl;
|
|
62
52
|
}
|
|
63
|
-
registerAssociationFieldAction(associationType, value) {
|
|
64
|
-
this.associationFieldsActions[associationType] = value;
|
|
65
|
-
}
|
|
66
|
-
registerAssociationFieldsActions() {
|
|
67
|
-
this.registerAssociationFieldAction("hasOne", {
|
|
68
|
-
view: {
|
|
69
|
-
associationActions: ["list", "get", "view"]
|
|
70
|
-
},
|
|
71
|
-
create: {
|
|
72
|
-
associationActions: ["create", "set"]
|
|
73
|
-
},
|
|
74
|
-
update: {
|
|
75
|
-
associationActions: ["update", "remove", "set"]
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
this.registerAssociationFieldAction("hasMany", {
|
|
79
|
-
view: {
|
|
80
|
-
associationActions: ["list", "get", "view"]
|
|
81
|
-
},
|
|
82
|
-
create: {
|
|
83
|
-
associationActions: ["create", "set", "add"]
|
|
84
|
-
},
|
|
85
|
-
update: {
|
|
86
|
-
associationActions: ["update", "remove", "set"]
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
this.registerAssociationFieldAction("belongsTo", {
|
|
90
|
-
view: {
|
|
91
|
-
associationActions: ["list", "get", "view"]
|
|
92
|
-
},
|
|
93
|
-
create: {
|
|
94
|
-
associationActions: ["create", "set"]
|
|
95
|
-
},
|
|
96
|
-
update: {
|
|
97
|
-
associationActions: ["update", "remove", "set"]
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
this.registerAssociationFieldAction("belongsToMany", {
|
|
101
|
-
view: {
|
|
102
|
-
associationActions: ["list", "get", "view"]
|
|
103
|
-
},
|
|
104
|
-
create: {
|
|
105
|
-
associationActions: ["create", "set", "add"]
|
|
106
|
-
},
|
|
107
|
-
update: {
|
|
108
|
-
associationActions: ["update", "remove", "set", "toggle"]
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
53
|
async writeResourceToACL(resourceModel, transaction) {
|
|
113
54
|
await resourceModel.writeToACL({
|
|
114
55
|
acl: this.acl,
|
|
115
|
-
|
|
116
|
-
transaction,
|
|
117
|
-
grantHelper: this.grantHelper
|
|
56
|
+
transaction
|
|
118
57
|
});
|
|
119
58
|
}
|
|
120
59
|
async writeActionToACL(actionModel, transaction) {
|
|
@@ -123,9 +62,7 @@ class PluginACLServer extends import_server.Plugin {
|
|
|
123
62
|
await actionModel.writeToACL({
|
|
124
63
|
acl: this.acl,
|
|
125
64
|
role,
|
|
126
|
-
resourceName: resource.get("name")
|
|
127
|
-
associationFieldsActions: this.associationFieldsActions,
|
|
128
|
-
grantHelper: this.grantHelper
|
|
65
|
+
resourceName: resource.get("name")
|
|
129
66
|
});
|
|
130
67
|
}
|
|
131
68
|
async writeRolesToACL(options) {
|
|
@@ -587,6 +524,5 @@ class PluginACLServer extends import_server.Plugin {
|
|
|
587
524
|
var server_default = PluginACLServer;
|
|
588
525
|
// Annotate the CommonJS export names for ESM import in node:
|
|
589
526
|
0 && (module.exports = {
|
|
590
|
-
GrantHelper,
|
|
591
527
|
PluginACLServer
|
|
592
528
|
});
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"displayName.zh-CN": "权限控制",
|
|
5
5
|
"description": "Based on roles, resources, and actions, access control can precisely manage interface configuration permissions, data operation permissions, menu access permissions, and plugin permissions.",
|
|
6
6
|
"description.zh-CN": "基于角色、资源和操作的权限控制,可以精确控制界面配置权限、数据操作权限、菜单访问权限、插件权限。",
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "1.0.0-alpha.2",
|
|
8
8
|
"license": "AGPL-3.0",
|
|
9
9
|
"main": "./dist/server/index.js",
|
|
10
10
|
"homepage": "https://docs.nocobase.com/handbook/acl",
|
|
@@ -20,19 +20,19 @@
|
|
|
20
20
|
"react-dom": "^18.2.0"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
|
-
"@nocobase/acl": "
|
|
24
|
-
"@nocobase/actions": "
|
|
25
|
-
"@nocobase/cache": "
|
|
26
|
-
"@nocobase/client": "
|
|
27
|
-
"@nocobase/database": "
|
|
28
|
-
"@nocobase/server": "
|
|
29
|
-
"@nocobase/test": "
|
|
30
|
-
"@nocobase/utils": "
|
|
23
|
+
"@nocobase/acl": "1.x",
|
|
24
|
+
"@nocobase/actions": "1.x",
|
|
25
|
+
"@nocobase/cache": "1.x",
|
|
26
|
+
"@nocobase/client": "1.x",
|
|
27
|
+
"@nocobase/database": "1.x",
|
|
28
|
+
"@nocobase/server": "1.x",
|
|
29
|
+
"@nocobase/test": "1.x",
|
|
30
|
+
"@nocobase/utils": "1.x"
|
|
31
31
|
},
|
|
32
32
|
"repository": {
|
|
33
33
|
"type": "git",
|
|
34
34
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
35
35
|
"directory": "packages/plugins/acl"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "f89dbc9e67d58404a2e484a5e124f739f340dcf8"
|
|
38
38
|
}
|