@nocobase/acl 1.2.13-alpha → 1.3.0-alpha.20240710084543
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/package.json +4 -4
- package/lib/acl-available-action.d.ts +0 -24
- package/lib/acl-available-action.js +0 -44
- package/lib/acl-available-strategy.d.ts +0 -37
- package/lib/acl-available-strategy.js +0 -97
- package/lib/acl-resource.d.ts +0 -31
- package/lib/acl-resource.js +0 -100
- package/lib/acl-role.d.ts +0 -58
- package/lib/acl-role.js +0 -193
- package/lib/acl.d.ts +0 -121
- package/lib/acl.js +0 -422
- package/lib/allow-manager.d.ts +0 -21
- package/lib/allow-manager.js +0 -117
- package/lib/errors/index.d.ts +0 -9
- package/lib/errors/index.js +0 -30
- package/lib/errors/no-permission-error.d.ts +0 -10
- package/lib/errors/no-permission-error.js +0 -40
- package/lib/fixed-params-manager.d.ts +0 -18
- package/lib/fixed-params-manager.js +0 -71
- package/lib/index.d.ts +0 -15
- package/lib/index.js +0 -42
- package/lib/skip-middleware.d.ts +0 -14
- package/lib/skip-middleware.js +0 -47
- package/lib/snippet-manager.d.ts +0 -27
- package/lib/snippet-manager.js +0 -77
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/acl",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0-alpha.20240710084543",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "AGPL-3.0",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/resourcer": "1.
|
|
10
|
-
"@nocobase/utils": "1.
|
|
9
|
+
"@nocobase/resourcer": "1.3.0-alpha.20240710084543",
|
|
10
|
+
"@nocobase/utils": "1.3.0-alpha.20240710084543",
|
|
11
11
|
"minimatch": "^5.1.1"
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
@@ -15,5 +15,5 @@
|
|
|
15
15
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
16
16
|
"directory": "packages/acl"
|
|
17
17
|
},
|
|
18
|
-
"gitHead": "
|
|
18
|
+
"gitHead": "07a8b596fc64a9779a194cb9b0dc2ca7570ed9d4"
|
|
19
19
|
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
export interface AvailableActionOptions {
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated
|
|
12
|
-
*/
|
|
13
|
-
type?: 'new-data' | 'old-data';
|
|
14
|
-
displayName?: string;
|
|
15
|
-
aliases?: string[] | string;
|
|
16
|
-
resource?: string;
|
|
17
|
-
onNewRecord?: boolean;
|
|
18
|
-
allowConfigureFields?: boolean;
|
|
19
|
-
}
|
|
20
|
-
export declare class ACLAvailableAction {
|
|
21
|
-
name: string;
|
|
22
|
-
options: AvailableActionOptions;
|
|
23
|
-
constructor(name: string, options: AvailableActionOptions);
|
|
24
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var __defProp = Object.defineProperty;
|
|
11
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
15
|
-
var __export = (target, all) => {
|
|
16
|
-
for (var name in all)
|
|
17
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
18
|
-
};
|
|
19
|
-
var __copyProps = (to, from, except, desc) => {
|
|
20
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
-
for (let key of __getOwnPropNames(from))
|
|
22
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
24
|
-
}
|
|
25
|
-
return to;
|
|
26
|
-
};
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var acl_available_action_exports = {};
|
|
29
|
-
__export(acl_available_action_exports, {
|
|
30
|
-
ACLAvailableAction: () => ACLAvailableAction
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(acl_available_action_exports);
|
|
33
|
-
const _ACLAvailableAction = class _ACLAvailableAction {
|
|
34
|
-
constructor(name, options) {
|
|
35
|
-
this.name = name;
|
|
36
|
-
this.options = options;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
__name(_ACLAvailableAction, "ACLAvailableAction");
|
|
40
|
-
let ACLAvailableAction = _ACLAvailableAction;
|
|
41
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
-
0 && (module.exports = {
|
|
43
|
-
ACLAvailableAction
|
|
44
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
import { ACL } from './acl';
|
|
10
|
-
export interface AvailableStrategyOptions {
|
|
11
|
-
displayName?: string;
|
|
12
|
-
actions?: false | string | string[];
|
|
13
|
-
allowConfigure?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
resource?: '*';
|
|
18
|
-
}
|
|
19
|
-
export declare const predicate: {
|
|
20
|
-
own: {
|
|
21
|
-
filter: {
|
|
22
|
-
createdById: string;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
all: {};
|
|
26
|
-
};
|
|
27
|
-
export declare class ACLAvailableStrategy {
|
|
28
|
-
acl: ACL;
|
|
29
|
-
options: AvailableStrategyOptions;
|
|
30
|
-
actionsAsObject: {
|
|
31
|
-
[key: string]: string;
|
|
32
|
-
};
|
|
33
|
-
allowConfigure: boolean;
|
|
34
|
-
constructor(acl: ACL, options: AvailableStrategyOptions);
|
|
35
|
-
matchAction(actionName: string): any;
|
|
36
|
-
allow(resourceName: string, actionName: string): any;
|
|
37
|
-
}
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var __create = Object.create;
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
17
|
-
var __export = (target, all) => {
|
|
18
|
-
for (var name in all)
|
|
19
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
|
-
};
|
|
21
|
-
var __copyProps = (to, from, except, desc) => {
|
|
22
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
-
for (let key of __getOwnPropNames(from))
|
|
24
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
25
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
26
|
-
}
|
|
27
|
-
return to;
|
|
28
|
-
};
|
|
29
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
-
mod
|
|
36
|
-
));
|
|
37
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
-
var acl_available_strategy_exports = {};
|
|
39
|
-
__export(acl_available_strategy_exports, {
|
|
40
|
-
ACLAvailableStrategy: () => ACLAvailableStrategy,
|
|
41
|
-
predicate: () => predicate
|
|
42
|
-
});
|
|
43
|
-
module.exports = __toCommonJS(acl_available_strategy_exports);
|
|
44
|
-
var import_lodash = __toESM(require("lodash"));
|
|
45
|
-
const predicate = {
|
|
46
|
-
own: {
|
|
47
|
-
filter: {
|
|
48
|
-
createdById: "{{ ctx.state.currentUser.id }}"
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
all: {}
|
|
52
|
-
};
|
|
53
|
-
const _ACLAvailableStrategy = class _ACLAvailableStrategy {
|
|
54
|
-
acl;
|
|
55
|
-
options;
|
|
56
|
-
actionsAsObject;
|
|
57
|
-
allowConfigure;
|
|
58
|
-
constructor(acl, options) {
|
|
59
|
-
this.acl = acl;
|
|
60
|
-
this.options = options;
|
|
61
|
-
this.allowConfigure = options.allowConfigure;
|
|
62
|
-
let actions = this.options.actions;
|
|
63
|
-
if (import_lodash.default.isString(actions) && actions != "*") {
|
|
64
|
-
actions = [actions];
|
|
65
|
-
}
|
|
66
|
-
if (import_lodash.default.isArray(actions)) {
|
|
67
|
-
this.actionsAsObject = actions.reduce((carry, action) => {
|
|
68
|
-
const [actionName, predicate2] = action.split(":");
|
|
69
|
-
carry[actionName] = predicate2;
|
|
70
|
-
return carry;
|
|
71
|
-
}, {});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
matchAction(actionName) {
|
|
75
|
-
if (this.options.actions == "*") {
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
if (Object.prototype.hasOwnProperty.call(this.actionsAsObject || {}, actionName)) {
|
|
79
|
-
const predicateName = this.actionsAsObject[actionName];
|
|
80
|
-
if (predicateName) {
|
|
81
|
-
return import_lodash.default.cloneDeep(predicate[predicateName]);
|
|
82
|
-
}
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
return false;
|
|
86
|
-
}
|
|
87
|
-
allow(resourceName, actionName) {
|
|
88
|
-
return this.matchAction(this.acl.resolveActionAlias(actionName));
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
__name(_ACLAvailableStrategy, "ACLAvailableStrategy");
|
|
92
|
-
let ACLAvailableStrategy = _ACLAvailableStrategy;
|
|
93
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
94
|
-
0 && (module.exports = {
|
|
95
|
-
ACLAvailableStrategy,
|
|
96
|
-
predicate
|
|
97
|
-
});
|
package/lib/acl-resource.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
import { ACLRole, RoleActionParams } from './acl-role';
|
|
10
|
-
import { ACL } from './acl';
|
|
11
|
-
export type ResourceActions = {
|
|
12
|
-
[key: string]: RoleActionParams;
|
|
13
|
-
};
|
|
14
|
-
interface AclResourceOptions {
|
|
15
|
-
name: string;
|
|
16
|
-
role: ACLRole;
|
|
17
|
-
actions?: ResourceActions;
|
|
18
|
-
}
|
|
19
|
-
export declare class ACLResource {
|
|
20
|
-
actions: Map<string, RoleActionParams>;
|
|
21
|
-
acl: ACL;
|
|
22
|
-
role: ACLRole;
|
|
23
|
-
name: string;
|
|
24
|
-
constructor(options: AclResourceOptions);
|
|
25
|
-
getActions(): {};
|
|
26
|
-
getAction(name: string): RoleActionParams;
|
|
27
|
-
setAction(name: string, params: RoleActionParams): void;
|
|
28
|
-
setActions(actions: ResourceActions): void;
|
|
29
|
-
removeAction(name: string): void;
|
|
30
|
-
}
|
|
31
|
-
export {};
|
package/lib/acl-resource.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var __create = Object.create;
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
17
|
-
var __export = (target, all) => {
|
|
18
|
-
for (var name in all)
|
|
19
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
|
-
};
|
|
21
|
-
var __copyProps = (to, from, except, desc) => {
|
|
22
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
-
for (let key of __getOwnPropNames(from))
|
|
24
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
25
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
26
|
-
}
|
|
27
|
-
return to;
|
|
28
|
-
};
|
|
29
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
-
mod
|
|
36
|
-
));
|
|
37
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
-
var acl_resource_exports = {};
|
|
39
|
-
__export(acl_resource_exports, {
|
|
40
|
-
ACLResource: () => ACLResource
|
|
41
|
-
});
|
|
42
|
-
module.exports = __toCommonJS(acl_resource_exports);
|
|
43
|
-
var import_lodash = __toESM(require("lodash"));
|
|
44
|
-
const _ACLResource = class _ACLResource {
|
|
45
|
-
actions = /* @__PURE__ */ new Map();
|
|
46
|
-
acl;
|
|
47
|
-
role;
|
|
48
|
-
name;
|
|
49
|
-
constructor(options) {
|
|
50
|
-
this.acl = options.role.acl;
|
|
51
|
-
this.role = options.role;
|
|
52
|
-
this.name = options.name;
|
|
53
|
-
const actionsOption = options.actions || {};
|
|
54
|
-
for (const actionName of Object.keys(actionsOption)) {
|
|
55
|
-
this.actions.set(actionName, actionsOption[actionName]);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
getActions() {
|
|
59
|
-
return Array.from(this.actions.keys()).reduce((carry, key) => {
|
|
60
|
-
carry[key] = this.actions.get(key);
|
|
61
|
-
return carry;
|
|
62
|
-
}, {});
|
|
63
|
-
}
|
|
64
|
-
getAction(name) {
|
|
65
|
-
const result = this.actions.get(name) || this.actions.get(this.acl.resolveActionAlias(name));
|
|
66
|
-
if (!result) {
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
if (Array.isArray(result.fields) && result.fields.length > 0) {
|
|
70
|
-
result.fields = import_lodash.default.uniq(result.fields);
|
|
71
|
-
}
|
|
72
|
-
return import_lodash.default.cloneDeep(result);
|
|
73
|
-
}
|
|
74
|
-
setAction(name, params) {
|
|
75
|
-
const context = {
|
|
76
|
-
role: this.role,
|
|
77
|
-
acl: this.role.acl,
|
|
78
|
-
params: params || {},
|
|
79
|
-
path: `${this.name}:${name}`,
|
|
80
|
-
resourceName: this.name,
|
|
81
|
-
actionName: name
|
|
82
|
-
};
|
|
83
|
-
this.acl.emit("beforeGrantAction", context);
|
|
84
|
-
this.actions.set(name, context.params);
|
|
85
|
-
}
|
|
86
|
-
setActions(actions) {
|
|
87
|
-
for (const actionName of Object.keys(actions)) {
|
|
88
|
-
this.setAction(actionName, actions[actionName]);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
removeAction(name) {
|
|
92
|
-
this.actions.delete(name);
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
__name(_ACLResource, "ACLResource");
|
|
96
|
-
let ACLResource = _ACLResource;
|
|
97
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
98
|
-
0 && (module.exports = {
|
|
99
|
-
ACLResource
|
|
100
|
-
});
|
package/lib/acl-role.d.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
import { ACL, DefineOptions } from './acl';
|
|
10
|
-
import { ACLAvailableStrategy, AvailableStrategyOptions } from './acl-available-strategy';
|
|
11
|
-
import { ACLResource } from './acl-resource';
|
|
12
|
-
export interface RoleActionParams {
|
|
13
|
-
fields?: string[];
|
|
14
|
-
filter?: any;
|
|
15
|
-
own?: boolean;
|
|
16
|
-
whitelist?: string[];
|
|
17
|
-
blacklist?: string[];
|
|
18
|
-
[key: string]: any;
|
|
19
|
-
}
|
|
20
|
-
export interface ResourceActionsOptions {
|
|
21
|
-
[actionName: string]: RoleActionParams;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* @internal
|
|
25
|
-
*/
|
|
26
|
-
export declare class ACLRole {
|
|
27
|
-
acl: ACL;
|
|
28
|
-
name: string;
|
|
29
|
-
strategy: string | AvailableStrategyOptions;
|
|
30
|
-
resources: Map<string, ACLResource>;
|
|
31
|
-
snippets: Set<string>;
|
|
32
|
-
_snippetCache: {
|
|
33
|
-
params: any;
|
|
34
|
-
result: any;
|
|
35
|
-
};
|
|
36
|
-
constructor(acl: ACL, name: string);
|
|
37
|
-
_serializeSet(set: Set<string>): string;
|
|
38
|
-
getResource(name: string): ACLResource | undefined;
|
|
39
|
-
setStrategy(value: string | AvailableStrategyOptions): void;
|
|
40
|
-
getStrategy(): ACLAvailableStrategy;
|
|
41
|
-
getResourceActionsParams(resourceName: string): {};
|
|
42
|
-
revokeResource(resourceName: string): void;
|
|
43
|
-
grantAction(path: string, options?: RoleActionParams): void;
|
|
44
|
-
getActionParams(path: string): RoleActionParams;
|
|
45
|
-
revokeAction(path: string): void;
|
|
46
|
-
effectiveSnippets(): {
|
|
47
|
-
allowed: Array<string>;
|
|
48
|
-
rejected: Array<string>;
|
|
49
|
-
};
|
|
50
|
-
snippetAllowed(actionPath: string): boolean;
|
|
51
|
-
toJSON(): DefineOptions;
|
|
52
|
-
protected getResourceActionFromPath(path: string): {
|
|
53
|
-
resourceName: string;
|
|
54
|
-
actionName: string;
|
|
55
|
-
resource: ACLResource;
|
|
56
|
-
action: any;
|
|
57
|
-
};
|
|
58
|
-
}
|
package/lib/acl-role.js
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file is part of the NocoBase (R) project.
|
|
3
|
-
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
-
* Authors: NocoBase Team.
|
|
5
|
-
*
|
|
6
|
-
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
-
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
var __create = Object.create;
|
|
11
|
-
var __defProp = Object.defineProperty;
|
|
12
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
17
|
-
var __export = (target, all) => {
|
|
18
|
-
for (var name in all)
|
|
19
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
20
|
-
};
|
|
21
|
-
var __copyProps = (to, from, except, desc) => {
|
|
22
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
23
|
-
for (let key of __getOwnPropNames(from))
|
|
24
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
25
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
26
|
-
}
|
|
27
|
-
return to;
|
|
28
|
-
};
|
|
29
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
-
mod
|
|
36
|
-
));
|
|
37
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
-
var acl_role_exports = {};
|
|
39
|
-
__export(acl_role_exports, {
|
|
40
|
-
ACLRole: () => ACLRole
|
|
41
|
-
});
|
|
42
|
-
module.exports = __toCommonJS(acl_role_exports);
|
|
43
|
-
var import_acl_available_strategy = require("./acl-available-strategy");
|
|
44
|
-
var import_acl_resource = require("./acl-resource");
|
|
45
|
-
var import_lodash = __toESM(require("lodash"));
|
|
46
|
-
var import_minimatch = __toESM(require("minimatch"));
|
|
47
|
-
const _ACLRole = class _ACLRole {
|
|
48
|
-
constructor(acl, name) {
|
|
49
|
-
this.acl = acl;
|
|
50
|
-
this.name = name;
|
|
51
|
-
}
|
|
52
|
-
strategy;
|
|
53
|
-
resources = /* @__PURE__ */ new Map();
|
|
54
|
-
snippets = /* @__PURE__ */ new Set();
|
|
55
|
-
_snippetCache = {
|
|
56
|
-
params: null,
|
|
57
|
-
result: null
|
|
58
|
-
};
|
|
59
|
-
_serializeSet(set) {
|
|
60
|
-
return JSON.stringify([...set].sort());
|
|
61
|
-
}
|
|
62
|
-
getResource(name) {
|
|
63
|
-
return this.resources.get(name);
|
|
64
|
-
}
|
|
65
|
-
setStrategy(value) {
|
|
66
|
-
this.strategy = value;
|
|
67
|
-
}
|
|
68
|
-
getStrategy() {
|
|
69
|
-
if (!this.strategy) {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
return import_lodash.default.isString(this.strategy) ? this.acl.availableStrategy.get(this.strategy) : new import_acl_available_strategy.ACLAvailableStrategy(this.acl, this.strategy);
|
|
73
|
-
}
|
|
74
|
-
getResourceActionsParams(resourceName) {
|
|
75
|
-
const resource = this.getResource(resourceName);
|
|
76
|
-
return resource.getActions();
|
|
77
|
-
}
|
|
78
|
-
revokeResource(resourceName) {
|
|
79
|
-
for (const key of [...this.resources.keys()]) {
|
|
80
|
-
if (key === resourceName || key.includes(`${resourceName}.`)) {
|
|
81
|
-
this.resources.delete(key);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
grantAction(path, options) {
|
|
86
|
-
let { resource } = this.getResourceActionFromPath(path);
|
|
87
|
-
const { resourceName, actionName } = this.getResourceActionFromPath(path);
|
|
88
|
-
if (!resource) {
|
|
89
|
-
resource = new import_acl_resource.ACLResource({
|
|
90
|
-
role: this,
|
|
91
|
-
name: resourceName
|
|
92
|
-
});
|
|
93
|
-
this.resources.set(resourceName, resource);
|
|
94
|
-
}
|
|
95
|
-
resource.setAction(actionName, options);
|
|
96
|
-
}
|
|
97
|
-
getActionParams(path) {
|
|
98
|
-
const { action } = this.getResourceActionFromPath(path);
|
|
99
|
-
return action;
|
|
100
|
-
}
|
|
101
|
-
revokeAction(path) {
|
|
102
|
-
const { resource, actionName } = this.getResourceActionFromPath(path);
|
|
103
|
-
resource.removeAction(actionName);
|
|
104
|
-
}
|
|
105
|
-
effectiveSnippets() {
|
|
106
|
-
const currentParams = this._serializeSet(this.snippets);
|
|
107
|
-
if (this._snippetCache.params === currentParams) {
|
|
108
|
-
return this._snippetCache.result;
|
|
109
|
-
}
|
|
110
|
-
const allowedSnippets = /* @__PURE__ */ new Set();
|
|
111
|
-
const rejectedSnippets = /* @__PURE__ */ new Set();
|
|
112
|
-
const availableSnippets = this.acl.snippetManager.snippets;
|
|
113
|
-
for (let snippetRule of this.snippets) {
|
|
114
|
-
const negated = snippetRule.startsWith("!");
|
|
115
|
-
snippetRule = negated ? snippetRule.slice(1) : snippetRule;
|
|
116
|
-
for (const [_, availableSnippet] of availableSnippets) {
|
|
117
|
-
if ((0, import_minimatch.default)(availableSnippet.name, snippetRule)) {
|
|
118
|
-
if (negated) {
|
|
119
|
-
rejectedSnippets.add(availableSnippet.name);
|
|
120
|
-
} else {
|
|
121
|
-
allowedSnippets.add(availableSnippet.name);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
const effectiveSnippets = new Set([...allowedSnippets].filter((x) => !rejectedSnippets.has(x)));
|
|
127
|
-
this._snippetCache = {
|
|
128
|
-
params: currentParams,
|
|
129
|
-
result: {
|
|
130
|
-
allowed: [...effectiveSnippets],
|
|
131
|
-
rejected: [...rejectedSnippets]
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
return this._snippetCache.result;
|
|
135
|
-
}
|
|
136
|
-
snippetAllowed(actionPath) {
|
|
137
|
-
const effectiveSnippets = this.effectiveSnippets();
|
|
138
|
-
const getActions = /* @__PURE__ */ __name((snippets) => {
|
|
139
|
-
return snippets.map((snippetName) => this.acl.snippetManager.snippets.get(snippetName).actions).flat();
|
|
140
|
-
}, "getActions");
|
|
141
|
-
const allowedActions = getActions(effectiveSnippets.allowed);
|
|
142
|
-
const rejectedActions = getActions(effectiveSnippets.rejected);
|
|
143
|
-
const actionMatched = /* @__PURE__ */ __name((actionPath2, actionRule) => {
|
|
144
|
-
return (0, import_minimatch.default)(actionPath2, actionRule);
|
|
145
|
-
}, "actionMatched");
|
|
146
|
-
for (const action of allowedActions) {
|
|
147
|
-
if (actionMatched(actionPath, action)) {
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
for (const action of rejectedActions) {
|
|
152
|
-
if (actionMatched(actionPath, action)) {
|
|
153
|
-
return false;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
toJSON() {
|
|
159
|
-
const actions = {};
|
|
160
|
-
for (const resourceName of this.resources.keys()) {
|
|
161
|
-
const resourceActions = this.getResourceActionsParams(resourceName);
|
|
162
|
-
for (const actionName of Object.keys(resourceActions)) {
|
|
163
|
-
actions[`${resourceName}:${actionName}`] = resourceActions[actionName];
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return {
|
|
167
|
-
role: this.name,
|
|
168
|
-
strategy: this.strategy,
|
|
169
|
-
actions,
|
|
170
|
-
snippets: Array.from(this.snippets)
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
getResourceActionFromPath(path) {
|
|
174
|
-
const [resourceName, actionName] = path.split(":");
|
|
175
|
-
const resource = this.resources.get(resourceName);
|
|
176
|
-
let action = null;
|
|
177
|
-
if (resource) {
|
|
178
|
-
action = resource.getAction(actionName);
|
|
179
|
-
}
|
|
180
|
-
return {
|
|
181
|
-
resourceName,
|
|
182
|
-
actionName,
|
|
183
|
-
resource,
|
|
184
|
-
action
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
__name(_ACLRole, "ACLRole");
|
|
189
|
-
let ACLRole = _ACLRole;
|
|
190
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
191
|
-
0 && (module.exports = {
|
|
192
|
-
ACLRole
|
|
193
|
-
});
|