@nocobase/acl 0.21.0-alpha.7 → 0.21.0-alpha.9
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 +1 -0
- package/lib/acl.js +32 -8
- package/package.json +4 -4
package/lib/acl.d.ts
CHANGED
package/lib/acl.js
CHANGED
|
@@ -154,14 +154,14 @@ const _ACL = class _ACL extends import_events.default {
|
|
|
154
154
|
this.addListener("beforeGrantAction", listener);
|
|
155
155
|
}
|
|
156
156
|
can(options) {
|
|
157
|
-
const { role, resource, action } = options;
|
|
157
|
+
const { role, resource, action, rawResourceName } = options;
|
|
158
158
|
const aclRole = this.roles.get(role);
|
|
159
159
|
if (!aclRole) {
|
|
160
160
|
return null;
|
|
161
161
|
}
|
|
162
|
-
const actionPath = `${resource}:${action}`;
|
|
162
|
+
const actionPath = `${rawResourceName ? rawResourceName : resource}:${action}`;
|
|
163
163
|
const snippetAllowed = aclRole.snippetAllowed(actionPath);
|
|
164
|
-
const fixedParams = this.fixedParamsManager.getParams(resource, action);
|
|
164
|
+
const fixedParams = this.fixedParamsManager.getParams(rawResourceName ? rawResourceName : resource, action);
|
|
165
165
|
const mergeParams = /* @__PURE__ */ __name((result) => {
|
|
166
166
|
const params = result["params"] || {};
|
|
167
167
|
const mergedParams = (0, import_utils.assign)(params, fixedParams);
|
|
@@ -258,13 +258,25 @@ const _ACL = class _ACL extends import_events.default {
|
|
|
258
258
|
const acl = this;
|
|
259
259
|
return /* @__PURE__ */ __name(async function ACLMiddleware(ctx, next) {
|
|
260
260
|
const roleName = ctx.state.currentRole || "anonymous";
|
|
261
|
-
const { resourceName, actionName } = ctx.action;
|
|
261
|
+
const { resourceName: rawResourceName, actionName } = ctx.action;
|
|
262
|
+
let resourceName = rawResourceName;
|
|
263
|
+
if (rawResourceName.includes(".")) {
|
|
264
|
+
resourceName = rawResourceName.split(".").pop();
|
|
265
|
+
}
|
|
266
|
+
if (ctx.getCurrentRepository) {
|
|
267
|
+
const currentRepository = ctx.getCurrentRepository();
|
|
268
|
+
if (currentRepository && currentRepository.targetCollection) {
|
|
269
|
+
resourceName = ctx.getCurrentRepository().targetCollection.name;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
262
272
|
ctx.can = (options) => {
|
|
263
273
|
const canResult = acl.can({ role: roleName, ...options });
|
|
264
274
|
return canResult;
|
|
265
275
|
};
|
|
266
276
|
ctx.permission = {
|
|
267
|
-
can: ctx.can({ resource: resourceName, action: actionName })
|
|
277
|
+
can: ctx.can({ resource: resourceName, action: actionName, rawResourceName }),
|
|
278
|
+
resourceName,
|
|
279
|
+
actionName
|
|
268
280
|
};
|
|
269
281
|
return await (0, import_koa_compose.default)(acl.middlewares.nodes)(ctx, next);
|
|
270
282
|
}, "ACLMiddleware");
|
|
@@ -274,7 +286,17 @@ const _ACL = class _ACL extends import_events.default {
|
|
|
274
286
|
*/
|
|
275
287
|
async getActionParams(ctx) {
|
|
276
288
|
const roleName = ctx.state.currentRole || "anonymous";
|
|
277
|
-
const { resourceName, actionName } = ctx.action;
|
|
289
|
+
const { resourceName: rawResourceName, actionName } = ctx.action;
|
|
290
|
+
let resourceName = rawResourceName;
|
|
291
|
+
if (rawResourceName.includes(".")) {
|
|
292
|
+
resourceName = rawResourceName.split(".").pop();
|
|
293
|
+
}
|
|
294
|
+
if (ctx.getCurrentRepository) {
|
|
295
|
+
const currentRepository = ctx.getCurrentRepository();
|
|
296
|
+
if (currentRepository && currentRepository.targetCollection) {
|
|
297
|
+
resourceName = ctx.getCurrentRepository().targetCollection.name;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
278
300
|
ctx.can = (options) => {
|
|
279
301
|
const can = this.can({ role: roleName, ...options });
|
|
280
302
|
if (!can) {
|
|
@@ -283,7 +305,9 @@ const _ACL = class _ACL extends import_events.default {
|
|
|
283
305
|
return import_lodash.default.cloneDeep(can);
|
|
284
306
|
};
|
|
285
307
|
ctx.permission = {
|
|
286
|
-
can: ctx.can({ resource: resourceName, action: actionName })
|
|
308
|
+
can: ctx.can({ resource: resourceName, action: actionName, rawResourceName }),
|
|
309
|
+
resourceName,
|
|
310
|
+
actionName
|
|
287
311
|
};
|
|
288
312
|
await (0, import_koa_compose.default)(this.middlewares.nodes)(ctx, async () => {
|
|
289
313
|
});
|
|
@@ -313,7 +337,7 @@ const _ACL = class _ACL extends import_events.default {
|
|
|
313
337
|
async (ctx, next) => {
|
|
314
338
|
var _a, _b, _c, _d;
|
|
315
339
|
const resourcerAction = ctx.action;
|
|
316
|
-
const { resourceName, actionName } = ctx.
|
|
340
|
+
const { resourceName, actionName } = ctx.permission;
|
|
317
341
|
const permission = ctx.permission;
|
|
318
342
|
((_a = ctx.log) == null ? void 0 : _a.info) && ctx.log.info("ctx permission", permission);
|
|
319
343
|
if ((!permission.can || typeof permission.can !== "object") && !permission.skip) {
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/acl",
|
|
3
|
-
"version": "0.21.0-alpha.
|
|
3
|
+
"version": "0.21.0-alpha.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"types": "./lib/index.d.ts",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/resourcer": "0.21.0-alpha.
|
|
10
|
-
"@nocobase/utils": "0.21.0-alpha.
|
|
9
|
+
"@nocobase/resourcer": "0.21.0-alpha.9",
|
|
10
|
+
"@nocobase/utils": "0.21.0-alpha.9",
|
|
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": "a6fe6c4ee532c04e5a50ec777bf76436ca624cbd"
|
|
19
19
|
}
|