@nocobase/acl 1.0.0-alpha.8 → 1.0.1-alpha.1
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/acl.d.ts +5 -0
- package/lib/acl.js +47 -19
- package/lib/errors/index.d.ts +9 -0
- package/lib/errors/index.js +30 -0
- package/lib/errors/no-permission-error.d.ts +10 -0
- package/lib/errors/no-permission-error.js +40 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/snippet-manager.js +4 -0
- package/package.json +4 -4
package/lib/acl.d.ts
CHANGED
|
@@ -75,7 +75,12 @@ export declare class ACL extends EventEmitter {
|
|
|
75
75
|
protected availableActions: Map<string, ACLAvailableAction>;
|
|
76
76
|
protected fixedParamsManager: FixedParamsManager;
|
|
77
77
|
protected middlewares: Toposort<any>;
|
|
78
|
+
protected strategyResources: Set<string> | null;
|
|
78
79
|
constructor();
|
|
80
|
+
setStrategyResources(resources: Array<string> | null): void;
|
|
81
|
+
getStrategyResources(): string[];
|
|
82
|
+
appendStrategyResource(resource: string): void;
|
|
83
|
+
removeStrategyResource(resource: string): void;
|
|
79
84
|
define(options: DefineOptions): ACLRole;
|
|
80
85
|
getRole(name: string): ACLRole;
|
|
81
86
|
removeRole(name: string): boolean;
|
package/lib/acl.js
CHANGED
|
@@ -50,6 +50,7 @@ var import_acl_role = require("./acl-role");
|
|
|
50
50
|
var import_allow_manager = require("./allow-manager");
|
|
51
51
|
var import_fixed_params_manager = __toESM(require("./fixed-params-manager"));
|
|
52
52
|
var import_snippet_manager = __toESM(require("./snippet-manager"));
|
|
53
|
+
var import_no_permission_error = require("./errors/no-permission-error");
|
|
53
54
|
const _ACL = class _ACL extends import_events.default {
|
|
54
55
|
/**
|
|
55
56
|
* @internal
|
|
@@ -74,6 +75,7 @@ const _ACL = class _ACL extends import_events.default {
|
|
|
74
75
|
availableActions = /* @__PURE__ */ new Map();
|
|
75
76
|
fixedParamsManager = new import_fixed_params_manager.default();
|
|
76
77
|
middlewares;
|
|
78
|
+
strategyResources = null;
|
|
77
79
|
constructor() {
|
|
78
80
|
super();
|
|
79
81
|
this.middlewares = new import_utils.Toposort();
|
|
@@ -99,6 +101,21 @@ const _ACL = class _ACL extends import_events.default {
|
|
|
99
101
|
});
|
|
100
102
|
this.addCoreMiddleware();
|
|
101
103
|
}
|
|
104
|
+
setStrategyResources(resources) {
|
|
105
|
+
this.strategyResources = new Set(resources);
|
|
106
|
+
}
|
|
107
|
+
getStrategyResources() {
|
|
108
|
+
return this.strategyResources ? [...this.strategyResources] : null;
|
|
109
|
+
}
|
|
110
|
+
appendStrategyResource(resource) {
|
|
111
|
+
if (!this.strategyResources) {
|
|
112
|
+
this.strategyResources = /* @__PURE__ */ new Set();
|
|
113
|
+
}
|
|
114
|
+
this.strategyResources.add(resource);
|
|
115
|
+
}
|
|
116
|
+
removeStrategyResource(resource) {
|
|
117
|
+
this.strategyResources.delete(resource);
|
|
118
|
+
}
|
|
102
119
|
define(options) {
|
|
103
120
|
const roleName = options.role;
|
|
104
121
|
const role = new import_acl_role.ACLRole(this, roleName);
|
|
@@ -177,7 +194,10 @@ const _ACL = class _ACL extends import_events.default {
|
|
|
177
194
|
if (!roleStrategy && !snippetAllowed) {
|
|
178
195
|
return null;
|
|
179
196
|
}
|
|
180
|
-
let roleStrategyParams
|
|
197
|
+
let roleStrategyParams;
|
|
198
|
+
if (this.strategyResources === null || this.strategyResources.has(resource)) {
|
|
199
|
+
roleStrategyParams = roleStrategy == null ? void 0 : roleStrategy.allow(resource, this.resolveActionAlias(action));
|
|
200
|
+
}
|
|
181
201
|
if (!roleStrategyParams && snippetAllowed) {
|
|
182
202
|
roleStrategyParams = {};
|
|
183
203
|
}
|
|
@@ -313,7 +333,7 @@ const _ACL = class _ACL extends import_events.default {
|
|
|
313
333
|
if ((_a = params == null ? void 0 : params.filter) == null ? void 0 : _a.createdById) {
|
|
314
334
|
const collection = ctx.db.getCollection(resourceName);
|
|
315
335
|
if (!collection || !collection.getField("createdById")) {
|
|
316
|
-
|
|
336
|
+
throw new import_no_permission_error.NoPermissionError("createdById field not found");
|
|
317
337
|
}
|
|
318
338
|
}
|
|
319
339
|
return params;
|
|
@@ -333,24 +353,32 @@ const _ACL = class _ACL extends import_events.default {
|
|
|
333
353
|
}
|
|
334
354
|
const params = ((_b = permission.can) == null ? void 0 : _b.params) || acl.fixedParamsManager.getParams(resourceName, actionName);
|
|
335
355
|
((_c = ctx.log) == null ? void 0 : _c.debug) && ctx.log.debug("acl params", params);
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
356
|
+
try {
|
|
357
|
+
if (params && resourcerAction.mergeParams) {
|
|
358
|
+
const filteredParams = acl.filterParams(ctx, resourceName, params);
|
|
359
|
+
const parsedParams = await acl.parseJsonTemplate(filteredParams, ctx);
|
|
360
|
+
ctx.permission.parsedParams = parsedParams;
|
|
361
|
+
((_d = ctx.log) == null ? void 0 : _d.debug) && ctx.log.debug("acl parsedParams", parsedParams);
|
|
362
|
+
ctx.permission.rawParams = import_lodash.default.cloneDeep(resourcerAction.params);
|
|
363
|
+
resourcerAction.mergeParams(parsedParams, {
|
|
364
|
+
appends: (x, y) => {
|
|
365
|
+
if (!x) {
|
|
366
|
+
return [];
|
|
367
|
+
}
|
|
368
|
+
if (!y) {
|
|
369
|
+
return x;
|
|
370
|
+
}
|
|
371
|
+
return x.filter((i) => y.includes(i.split(".").shift()));
|
|
349
372
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
353
|
-
|
|
373
|
+
});
|
|
374
|
+
ctx.permission.mergedParams = import_lodash.default.cloneDeep(resourcerAction.params);
|
|
375
|
+
}
|
|
376
|
+
} catch (e) {
|
|
377
|
+
if (e instanceof import_no_permission_error.NoPermissionError) {
|
|
378
|
+
ctx.throw(403, "No permissions");
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
throw e;
|
|
354
382
|
}
|
|
355
383
|
await next();
|
|
356
384
|
},
|
|
@@ -0,0 +1,9 @@
|
|
|
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 * from './no-permission-error';
|
|
@@ -0,0 +1,30 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var errors_exports = {};
|
|
25
|
+
module.exports = __toCommonJS(errors_exports);
|
|
26
|
+
__reExport(errors_exports, require("./no-permission-error"), module.exports);
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
...require("./no-permission-error")
|
|
30
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
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 declare class NoPermissionError extends Error {
|
|
10
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 no_permission_error_exports = {};
|
|
29
|
+
__export(no_permission_error_exports, {
|
|
30
|
+
NoPermissionError: () => NoPermissionError
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(no_permission_error_exports);
|
|
33
|
+
const _NoPermissionError = class _NoPermissionError extends Error {
|
|
34
|
+
};
|
|
35
|
+
__name(_NoPermissionError, "NoPermissionError");
|
|
36
|
+
let NoPermissionError = _NoPermissionError;
|
|
37
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
+
0 && (module.exports = {
|
|
39
|
+
NoPermissionError
|
|
40
|
+
});
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -29,6 +29,7 @@ __reExport(src_exports, require("./acl-available-strategy"), module.exports);
|
|
|
29
29
|
__reExport(src_exports, require("./acl-resource"), module.exports);
|
|
30
30
|
__reExport(src_exports, require("./acl-role"), module.exports);
|
|
31
31
|
__reExport(src_exports, require("./skip-middleware"), module.exports);
|
|
32
|
+
__reExport(src_exports, require("./errors"), module.exports);
|
|
32
33
|
// Annotate the CommonJS export names for ESM import in node:
|
|
33
34
|
0 && (module.exports = {
|
|
34
35
|
...require("./acl"),
|
|
@@ -36,5 +37,6 @@ __reExport(src_exports, require("./skip-middleware"), module.exports);
|
|
|
36
37
|
...require("./acl-available-strategy"),
|
|
37
38
|
...require("./acl-resource"),
|
|
38
39
|
...require("./acl-role"),
|
|
39
|
-
...require("./skip-middleware")
|
|
40
|
+
...require("./skip-middleware"),
|
|
41
|
+
...require("./errors")
|
|
40
42
|
});
|
package/lib/snippet-manager.js
CHANGED
|
@@ -52,6 +52,10 @@ let Snippet = _Snippet;
|
|
|
52
52
|
const _SnippetManager = class _SnippetManager {
|
|
53
53
|
snippets = /* @__PURE__ */ new Map();
|
|
54
54
|
register(snippet) {
|
|
55
|
+
snippet.name = snippet.name.replace(".*", "");
|
|
56
|
+
if (snippet.name.includes("*") || snippet.name.endsWith(".")) {
|
|
57
|
+
throw new Error(`Invalid snippet name: ${snippet.name}, name should not include * or end with dot.`);
|
|
58
|
+
}
|
|
55
59
|
this.snippets.set(snippet.name, snippet);
|
|
56
60
|
}
|
|
57
61
|
allow(actionPath, snippetName) {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/acl",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1-alpha.1",
|
|
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.0.
|
|
10
|
-
"@nocobase/utils": "1.0.
|
|
9
|
+
"@nocobase/resourcer": "1.0.1-alpha.1",
|
|
10
|
+
"@nocobase/utils": "1.0.1-alpha.1",
|
|
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": "d24aa16987a4068f857ae073fcce18f3cb490660"
|
|
19
19
|
}
|