@nocobase/acl 2.0.0-alpha.5 → 2.0.0-alpha.51
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.js +9 -3
- package/lib/allow-manager.d.ts +2 -0
- package/lib/allow-manager.js +13 -3
- package/package.json +4 -4
package/lib/acl.js
CHANGED
|
@@ -48,9 +48,9 @@ var import_acl_available_action = require("./acl-available-action");
|
|
|
48
48
|
var import_acl_available_strategy = require("./acl-available-strategy");
|
|
49
49
|
var import_acl_role = require("./acl-role");
|
|
50
50
|
var import_allow_manager = require("./allow-manager");
|
|
51
|
+
var import_no_permission_error = require("./errors/no-permission-error");
|
|
51
52
|
var import_fixed_params_manager = __toESM(require("./fixed-params-manager"));
|
|
52
53
|
var import_snippet_manager = __toESM(require("./snippet-manager"));
|
|
53
|
-
var import_no_permission_error = require("./errors/no-permission-error");
|
|
54
54
|
var import_utils2 = require("./utils");
|
|
55
55
|
const _ACL = class _ACL extends import_events.default {
|
|
56
56
|
/**
|
|
@@ -262,6 +262,9 @@ const _ACL = class _ACL extends import_events.default {
|
|
|
262
262
|
* @deprecated
|
|
263
263
|
*/
|
|
264
264
|
skip(resourceName, actionNames, condition) {
|
|
265
|
+
if (!condition) {
|
|
266
|
+
condition = "public";
|
|
267
|
+
}
|
|
265
268
|
if (!Array.isArray(actionNames)) {
|
|
266
269
|
actionNames = [actionNames];
|
|
267
270
|
}
|
|
@@ -297,6 +300,7 @@ const _ACL = class _ACL extends import_events.default {
|
|
|
297
300
|
middleware() {
|
|
298
301
|
const acl = this;
|
|
299
302
|
return /* @__PURE__ */ __name(async function ACLMiddleware(ctx, next) {
|
|
303
|
+
ctx.acl = acl;
|
|
300
304
|
const roleName = ctx.state.currentRole || "anonymous";
|
|
301
305
|
const { resourceName: rawResourceName, actionName } = ctx.action;
|
|
302
306
|
let resourceName = rawResourceName;
|
|
@@ -464,9 +468,11 @@ const _ACL = class _ACL extends import_events.default {
|
|
|
464
468
|
__name(_ACL, "ACL");
|
|
465
469
|
let ACL = _ACL;
|
|
466
470
|
function getUser(ctx) {
|
|
471
|
+
const dataSource = ctx.app.dataSourceManager.dataSources.get("main");
|
|
472
|
+
const db = dataSource.collectionManager.db;
|
|
467
473
|
return async ({ fields }) => {
|
|
468
474
|
var _a, _b;
|
|
469
|
-
const userFields = fields.filter((f) => f &&
|
|
475
|
+
const userFields = fields.filter((f) => f && db.getFieldByPath("users." + f));
|
|
470
476
|
(_a = ctx.logger) == null ? void 0 : _a.info("filter-parse: ", { userFields });
|
|
471
477
|
if (!ctx.state.currentUser) {
|
|
472
478
|
return;
|
|
@@ -474,7 +480,7 @@ function getUser(ctx) {
|
|
|
474
480
|
if (!userFields.length) {
|
|
475
481
|
return;
|
|
476
482
|
}
|
|
477
|
-
const user = await
|
|
483
|
+
const user = await db.getRepository("users").findOne({
|
|
478
484
|
filterByTk: ctx.state.currentUser.id,
|
|
479
485
|
fields: userFields
|
|
480
486
|
});
|
package/lib/allow-manager.d.ts
CHANGED
|
@@ -12,10 +12,12 @@ export declare class AllowManager {
|
|
|
12
12
|
acl: ACL;
|
|
13
13
|
protected skipActions: Map<string, Map<string, string | true | ConditionFunc>>;
|
|
14
14
|
protected registeredCondition: Map<string, ConditionFunc>;
|
|
15
|
+
isPublicCondition: () => boolean;
|
|
15
16
|
constructor(acl: ACL);
|
|
16
17
|
allow(resourceName: string, actionName: string, condition?: string | ConditionFunc): void;
|
|
17
18
|
getAllowedConditions(resourceName: string, actionName: string): Array<ConditionFunc | true>;
|
|
18
19
|
registerAllowCondition(name: string, condition: ConditionFunc): void;
|
|
20
|
+
isPublic(resourceName: string, actionName: string, ctx: any): Promise<boolean>;
|
|
19
21
|
isAllowed(resourceName: string, actionName: string, ctx: any): Promise<boolean>;
|
|
20
22
|
aclMiddleware(): (ctx: any, next: any) => Promise<void>;
|
|
21
23
|
}
|
package/lib/allow-manager.js
CHANGED
|
@@ -36,9 +36,7 @@ const _AllowManager = class _AllowManager {
|
|
|
36
36
|
this.registerAllowCondition("loggedIn", (ctx) => {
|
|
37
37
|
return ctx.state.currentUser;
|
|
38
38
|
});
|
|
39
|
-
this.registerAllowCondition("public",
|
|
40
|
-
return true;
|
|
41
|
-
});
|
|
39
|
+
this.registerAllowCondition("public", this.isPublicCondition);
|
|
42
40
|
this.registerAllowCondition("allowConfigure", async (ctx) => {
|
|
43
41
|
var _a;
|
|
44
42
|
const roleName = ctx.state.currentRole;
|
|
@@ -54,6 +52,9 @@ const _AllowManager = class _AllowManager {
|
|
|
54
52
|
}
|
|
55
53
|
skipActions = /* @__PURE__ */ new Map();
|
|
56
54
|
registeredCondition = /* @__PURE__ */ new Map();
|
|
55
|
+
isPublicCondition = /* @__PURE__ */ __name(() => {
|
|
56
|
+
return true;
|
|
57
|
+
}, "isPublicCondition");
|
|
57
58
|
allow(resourceName, actionName, condition) {
|
|
58
59
|
const actionMap = this.skipActions.get(resourceName) || /* @__PURE__ */ new Map();
|
|
59
60
|
actionMap.set(actionName, condition || true);
|
|
@@ -78,6 +79,15 @@ const _AllowManager = class _AllowManager {
|
|
|
78
79
|
registerAllowCondition(name, condition) {
|
|
79
80
|
this.registeredCondition.set(name, condition);
|
|
80
81
|
}
|
|
82
|
+
async isPublic(resourceName, actionName, ctx) {
|
|
83
|
+
const skippedConditions = this.getAllowedConditions(resourceName, actionName);
|
|
84
|
+
for (const skippedCondition of skippedConditions) {
|
|
85
|
+
if (skippedCondition === this.isPublicCondition) {
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
81
91
|
async isAllowed(resourceName, actionName, ctx) {
|
|
82
92
|
const skippedConditions = this.getAllowedConditions(resourceName, actionName);
|
|
83
93
|
for (const skippedCondition of skippedConditions) {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/acl",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.51",
|
|
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": "2.0.0-alpha.
|
|
10
|
-
"@nocobase/utils": "2.0.0-alpha.
|
|
9
|
+
"@nocobase/resourcer": "2.0.0-alpha.51",
|
|
10
|
+
"@nocobase/utils": "2.0.0-alpha.51",
|
|
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": "a1e34dd97f370d54f3d80a6b83ab7ddb9c72dc18"
|
|
19
19
|
}
|