@nocobase/acl 1.7.0-beta.8 → 1.8.0-beta.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-role.js +5 -5
- package/lib/acl.d.ts +5 -1
- package/lib/acl.js +59 -8
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/utils/acl-role.d.ts +4 -0
- package/lib/utils/acl-role.js +257 -0
- package/lib/utils/index.d.ts +9 -0
- package/lib/utils/index.js +30 -0
- package/package.json +4 -4
package/lib/acl-role.js
CHANGED
|
@@ -40,10 +40,10 @@ __export(acl_role_exports, {
|
|
|
40
40
|
ACLRole: () => ACLRole
|
|
41
41
|
});
|
|
42
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
43
|
var import_lodash = __toESM(require("lodash"));
|
|
46
44
|
var import_minimatch = __toESM(require("minimatch"));
|
|
45
|
+
var import_acl_available_strategy = require("./acl-available-strategy");
|
|
46
|
+
var import_acl_resource = require("./acl-resource");
|
|
47
47
|
const _ACLRole = class _ACLRole {
|
|
48
48
|
constructor(acl, name) {
|
|
49
49
|
this.acl = acl;
|
|
@@ -113,7 +113,7 @@ const _ACLRole = class _ACLRole {
|
|
|
113
113
|
for (let snippetRule of this.snippets) {
|
|
114
114
|
const negated = snippetRule.startsWith("!");
|
|
115
115
|
snippetRule = negated ? snippetRule.slice(1) : snippetRule;
|
|
116
|
-
for (const [
|
|
116
|
+
for (const [_2, availableSnippet] of availableSnippets) {
|
|
117
117
|
if ((0, import_minimatch.default)(availableSnippet.name, snippetRule)) {
|
|
118
118
|
if (negated) {
|
|
119
119
|
rejectedSnippets.add(availableSnippet.name);
|
|
@@ -163,12 +163,12 @@ const _ACLRole = class _ACLRole {
|
|
|
163
163
|
actions[`${resourceName}:${actionName}`] = resourceActions[actionName];
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
|
-
return {
|
|
166
|
+
return import_lodash.default.cloneDeep({
|
|
167
167
|
role: this.name,
|
|
168
168
|
strategy: this.strategy,
|
|
169
169
|
actions,
|
|
170
170
|
snippets: Array.from(this.snippets)
|
|
171
|
-
};
|
|
171
|
+
});
|
|
172
172
|
}
|
|
173
173
|
getResourceActionFromPath(path) {
|
|
174
174
|
const [resourceName, actionName] = path.split(":");
|
package/lib/acl.d.ts
CHANGED
|
@@ -45,11 +45,12 @@ export interface ListenerContext {
|
|
|
45
45
|
}
|
|
46
46
|
type Listener = (ctx: ListenerContext) => void;
|
|
47
47
|
interface CanArgs {
|
|
48
|
-
role
|
|
48
|
+
role?: string;
|
|
49
49
|
resource: string;
|
|
50
50
|
action: string;
|
|
51
51
|
rawResourceName?: string;
|
|
52
52
|
ctx?: any;
|
|
53
|
+
roles?: string[];
|
|
53
54
|
}
|
|
54
55
|
export declare class ACL extends EventEmitter {
|
|
55
56
|
/**
|
|
@@ -83,6 +84,7 @@ export declare class ACL extends EventEmitter {
|
|
|
83
84
|
removeStrategyResource(resource: string): void;
|
|
84
85
|
define(options: DefineOptions): ACLRole;
|
|
85
86
|
getRole(name: string): ACLRole;
|
|
87
|
+
getRoles(names: string[]): ACLRole[];
|
|
86
88
|
removeRole(name: string): boolean;
|
|
87
89
|
setAvailableAction(name: string, options?: AvailableActionOptions): void;
|
|
88
90
|
getAvailableAction(name: string): ACLAvailableAction;
|
|
@@ -90,6 +92,8 @@ export declare class ACL extends EventEmitter {
|
|
|
90
92
|
setAvailableStrategy(name: string, options: AvailableStrategyOptions): void;
|
|
91
93
|
beforeGrantAction(listener?: Listener): void;
|
|
92
94
|
can(options: CanArgs): CanResult | null;
|
|
95
|
+
private getCanByRoles;
|
|
96
|
+
private getCanByRole;
|
|
93
97
|
/**
|
|
94
98
|
* @internal
|
|
95
99
|
*/
|
package/lib/acl.js
CHANGED
|
@@ -51,6 +51,7 @@ 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
53
|
var import_no_permission_error = require("./errors/no-permission-error");
|
|
54
|
+
var import_utils2 = require("./utils");
|
|
54
55
|
const _ACL = class _ACL extends import_events.default {
|
|
55
56
|
/**
|
|
56
57
|
* @internal
|
|
@@ -132,6 +133,9 @@ const _ACL = class _ACL extends import_events.default {
|
|
|
132
133
|
getRole(name) {
|
|
133
134
|
return this.roles.get(name);
|
|
134
135
|
}
|
|
136
|
+
getRoles(names) {
|
|
137
|
+
return names.map((name) => this.getRole(name)).filter((x) => Boolean(x));
|
|
138
|
+
}
|
|
135
139
|
removeRole(name) {
|
|
136
140
|
return this.roles.delete(name);
|
|
137
141
|
}
|
|
@@ -158,6 +162,32 @@ const _ACL = class _ACL extends import_events.default {
|
|
|
158
162
|
this.addListener("beforeGrantAction", listener);
|
|
159
163
|
}
|
|
160
164
|
can(options) {
|
|
165
|
+
var _a;
|
|
166
|
+
if (options.role) {
|
|
167
|
+
return import_lodash.default.cloneDeep(this.getCanByRole(options));
|
|
168
|
+
}
|
|
169
|
+
if ((_a = options.roles) == null ? void 0 : _a.length) {
|
|
170
|
+
return import_lodash.default.cloneDeep(this.getCanByRoles(options));
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
getCanByRoles(options) {
|
|
175
|
+
let canResult = null;
|
|
176
|
+
for (const role of options.roles) {
|
|
177
|
+
const result = this.getCanByRole({
|
|
178
|
+
role,
|
|
179
|
+
...options
|
|
180
|
+
});
|
|
181
|
+
if (!canResult) {
|
|
182
|
+
canResult = result;
|
|
183
|
+
canResult && (0, import_utils2.removeEmptyParams)(canResult.params);
|
|
184
|
+
} else if (canResult && result) {
|
|
185
|
+
canResult.params = (0, import_utils2.mergeAclActionParams)(canResult.params, result.params);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return canResult;
|
|
189
|
+
}
|
|
190
|
+
getCanByRole(options) {
|
|
161
191
|
const { role, resource, action, rawResourceName } = options;
|
|
162
192
|
const aclRole = this.roles.get(role);
|
|
163
193
|
if (!aclRole) {
|
|
@@ -277,8 +307,12 @@ const _ACL = class _ACL extends import_events.default {
|
|
|
277
307
|
}
|
|
278
308
|
}
|
|
279
309
|
ctx.can = (options) => {
|
|
280
|
-
const
|
|
281
|
-
|
|
310
|
+
const roles = ctx.state.currentRoles || [roleName];
|
|
311
|
+
const can = acl.can({ roles, ...options });
|
|
312
|
+
if (!can) {
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
return can;
|
|
282
316
|
};
|
|
283
317
|
ctx.permission = {
|
|
284
318
|
can: ctx.can({ resource: resourceName, action: actionName, rawResourceName }),
|
|
@@ -292,7 +326,8 @@ const _ACL = class _ACL extends import_events.default {
|
|
|
292
326
|
* @internal
|
|
293
327
|
*/
|
|
294
328
|
async getActionParams(ctx) {
|
|
295
|
-
|
|
329
|
+
var _a;
|
|
330
|
+
const roleNames = ((_a = ctx.state.currentRoles) == null ? void 0 : _a.length) ? ctx.state.currentRoles : "anonymous";
|
|
296
331
|
const { resourceName: rawResourceName, actionName } = ctx.action;
|
|
297
332
|
let resourceName = rawResourceName;
|
|
298
333
|
if (rawResourceName.includes(".")) {
|
|
@@ -305,11 +340,11 @@ const _ACL = class _ACL extends import_events.default {
|
|
|
305
340
|
}
|
|
306
341
|
}
|
|
307
342
|
ctx.can = (options) => {
|
|
308
|
-
const can = this.can({
|
|
309
|
-
if (
|
|
310
|
-
return
|
|
343
|
+
const can = this.can({ roles: roleNames, ...options });
|
|
344
|
+
if (can) {
|
|
345
|
+
return import_lodash.default.cloneDeep(can);
|
|
311
346
|
}
|
|
312
|
-
return
|
|
347
|
+
return null;
|
|
313
348
|
};
|
|
314
349
|
ctx.permission = {
|
|
315
350
|
can: ctx.can({ resource: resourceName, action: actionName, rawResourceName }),
|
|
@@ -329,13 +364,29 @@ const _ACL = class _ACL extends import_events.default {
|
|
|
329
364
|
* @internal
|
|
330
365
|
*/
|
|
331
366
|
filterParams(ctx, resourceName, params) {
|
|
332
|
-
var _a;
|
|
367
|
+
var _a, _b, _c;
|
|
333
368
|
if ((_a = params == null ? void 0 : params.filter) == null ? void 0 : _a.createdById) {
|
|
334
369
|
const collection = ctx.db.getCollection(resourceName);
|
|
335
370
|
if (!collection || !collection.getField("createdById")) {
|
|
336
371
|
throw new import_no_permission_error.NoPermissionError("createdById field not found");
|
|
337
372
|
}
|
|
338
373
|
}
|
|
374
|
+
if ((_c = (_b = params == null ? void 0 : params.filter) == null ? void 0 : _b.$or) == null ? void 0 : _c.length) {
|
|
375
|
+
const checkCreatedById = /* @__PURE__ */ __name((items) => {
|
|
376
|
+
return items.some(
|
|
377
|
+
(x) => {
|
|
378
|
+
var _a2, _b2;
|
|
379
|
+
return "createdById" in x || ((_a2 = x.$or) == null ? void 0 : _a2.some((y) => "createdById" in y)) || ((_b2 = x.$and) == null ? void 0 : _b2.some((y) => "createdById" in y));
|
|
380
|
+
}
|
|
381
|
+
);
|
|
382
|
+
}, "checkCreatedById");
|
|
383
|
+
if (checkCreatedById(params.filter.$or)) {
|
|
384
|
+
const collection = ctx.db.getCollection(resourceName);
|
|
385
|
+
if (!collection || !collection.getField("createdById")) {
|
|
386
|
+
throw new import_no_permission_error.NoPermissionError("createdById field not found");
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
339
390
|
return params;
|
|
340
391
|
}
|
|
341
392
|
addCoreMiddleware() {
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -30,6 +30,7 @@ __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
32
|
__reExport(src_exports, require("./errors"), module.exports);
|
|
33
|
+
__reExport(src_exports, require("./utils"), module.exports);
|
|
33
34
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
35
|
0 && (module.exports = {
|
|
35
36
|
...require("./acl"),
|
|
@@ -38,5 +39,6 @@ __reExport(src_exports, require("./errors"), module.exports);
|
|
|
38
39
|
...require("./acl-resource"),
|
|
39
40
|
...require("./acl-role"),
|
|
40
41
|
...require("./skip-middleware"),
|
|
41
|
-
...require("./errors")
|
|
42
|
+
...require("./errors"),
|
|
43
|
+
...require("./utils")
|
|
42
44
|
});
|
|
@@ -0,0 +1,257 @@
|
|
|
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
|
+
mergeAclActionParams: () => mergeAclActionParams,
|
|
41
|
+
mergeRole: () => mergeRole,
|
|
42
|
+
removeEmptyParams: () => removeEmptyParams
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(acl_role_exports);
|
|
45
|
+
var import_utils = require("@nocobase/utils");
|
|
46
|
+
var import_lodash = __toESM(require("lodash"));
|
|
47
|
+
function mergeRole(roles) {
|
|
48
|
+
const result = {
|
|
49
|
+
roles: [],
|
|
50
|
+
strategy: {},
|
|
51
|
+
actions: null,
|
|
52
|
+
snippets: [],
|
|
53
|
+
resources: null
|
|
54
|
+
};
|
|
55
|
+
const allSnippets = [];
|
|
56
|
+
for (const role of roles) {
|
|
57
|
+
const jsonRole = role.toJSON();
|
|
58
|
+
result.roles = mergeRoleNames(result.roles, jsonRole.role);
|
|
59
|
+
result.strategy = mergeRoleStrategy(result.strategy, jsonRole.strategy);
|
|
60
|
+
result.actions = mergeRoleActions(result.actions, jsonRole.actions);
|
|
61
|
+
result.resources = mergeRoleResources(result.resources, [...role.resources.keys()]);
|
|
62
|
+
if (import_lodash.default.isArray(jsonRole.snippets)) {
|
|
63
|
+
allSnippets.push(jsonRole.snippets);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
result.snippets = mergeRoleSnippets(allSnippets);
|
|
67
|
+
adjustActionByStrategy(roles, result);
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
__name(mergeRole, "mergeRole");
|
|
71
|
+
function adjustActionByStrategy(roles, result) {
|
|
72
|
+
const { actions, strategy } = result;
|
|
73
|
+
const actionSet = getAdjustActions(roles);
|
|
74
|
+
if (!import_lodash.default.isEmpty(actions) && !import_lodash.default.isEmpty(strategy == null ? void 0 : strategy.actions) && !import_lodash.default.isEmpty(result.resources)) {
|
|
75
|
+
for (const resource of result.resources) {
|
|
76
|
+
for (const action of strategy.actions) {
|
|
77
|
+
if (actionSet.has(action)) {
|
|
78
|
+
actions[`${resource}:${action}`] = {};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
__name(adjustActionByStrategy, "adjustActionByStrategy");
|
|
85
|
+
function getAdjustActions(roles) {
|
|
86
|
+
var _a;
|
|
87
|
+
const actionSet = /* @__PURE__ */ new Set();
|
|
88
|
+
for (const role of roles) {
|
|
89
|
+
const jsonRole = role.toJSON();
|
|
90
|
+
if (!import_lodash.default.isEmpty((_a = jsonRole.strategy) == null ? void 0 : _a["actions"]) && import_lodash.default.isEmpty(jsonRole.actions)) {
|
|
91
|
+
jsonRole.strategy["actions"].forEach((x) => !x.includes("own") && actionSet.add(x));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return actionSet;
|
|
95
|
+
}
|
|
96
|
+
__name(getAdjustActions, "getAdjustActions");
|
|
97
|
+
function mergeRoleNames(sourceRoleNames, newRoleName) {
|
|
98
|
+
return newRoleName ? sourceRoleNames.concat(newRoleName) : sourceRoleNames;
|
|
99
|
+
}
|
|
100
|
+
__name(mergeRoleNames, "mergeRoleNames");
|
|
101
|
+
function mergeRoleStrategy(sourceStrategy, newStrategy) {
|
|
102
|
+
if (!newStrategy) {
|
|
103
|
+
return sourceStrategy;
|
|
104
|
+
}
|
|
105
|
+
if (import_lodash.default.isArray(newStrategy.actions)) {
|
|
106
|
+
if (!sourceStrategy.actions) {
|
|
107
|
+
sourceStrategy.actions = newStrategy.actions;
|
|
108
|
+
} else {
|
|
109
|
+
const actions = sourceStrategy.actions.concat(newStrategy.actions);
|
|
110
|
+
return {
|
|
111
|
+
...sourceStrategy,
|
|
112
|
+
actions: [...new Set(actions)]
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return sourceStrategy;
|
|
117
|
+
}
|
|
118
|
+
__name(mergeRoleStrategy, "mergeRoleStrategy");
|
|
119
|
+
function mergeRoleActions(sourceActions, newActions) {
|
|
120
|
+
if (import_lodash.default.isEmpty(sourceActions)) return newActions;
|
|
121
|
+
if (import_lodash.default.isEmpty(newActions)) return sourceActions;
|
|
122
|
+
const result = {};
|
|
123
|
+
[...new Set(Reflect.ownKeys(sourceActions).concat(Reflect.ownKeys(newActions)))].forEach((key) => {
|
|
124
|
+
if (import_lodash.default.has(sourceActions, key) && import_lodash.default.has(newActions, key)) {
|
|
125
|
+
result[key] = mergeAclActionParams(sourceActions[key], newActions[key]);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
result[key] = import_lodash.default.has(sourceActions, key) ? sourceActions[key] : newActions[key];
|
|
129
|
+
});
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
__name(mergeRoleActions, "mergeRoleActions");
|
|
133
|
+
function mergeRoleSnippets(allRoleSnippets) {
|
|
134
|
+
if (!allRoleSnippets.length) {
|
|
135
|
+
return [];
|
|
136
|
+
}
|
|
137
|
+
const allSnippets = allRoleSnippets.flat();
|
|
138
|
+
const isExclusion = /* @__PURE__ */ __name((value) => value.startsWith("!"), "isExclusion");
|
|
139
|
+
const includes = new Set(allSnippets.filter((x) => !isExclusion(x)));
|
|
140
|
+
const excludes = new Set(allSnippets.filter(isExclusion));
|
|
141
|
+
const domainRoleMap = /* @__PURE__ */ new Map();
|
|
142
|
+
allRoleSnippets.forEach((roleSnippets, i) => {
|
|
143
|
+
roleSnippets.filter((x) => x.endsWith(".*") && !isExclusion(x)).forEach((include) => {
|
|
144
|
+
const domain = include.slice(0, -1);
|
|
145
|
+
if (!domainRoleMap.has(domain)) {
|
|
146
|
+
domainRoleMap.set(domain, /* @__PURE__ */ new Set());
|
|
147
|
+
}
|
|
148
|
+
domainRoleMap.get(domain).add(i);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
const excludesSet = /* @__PURE__ */ new Set();
|
|
152
|
+
for (const snippet of excludes) {
|
|
153
|
+
if (allRoleSnippets.every((x) => x.includes(snippet))) {
|
|
154
|
+
excludesSet.add(snippet);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
for (const [domain, indexes] of domainRoleMap.entries()) {
|
|
158
|
+
const fullDomain = `${domain}.*`;
|
|
159
|
+
if (includes.has(fullDomain)) {
|
|
160
|
+
excludesSet.delete(`!${fullDomain}`);
|
|
161
|
+
}
|
|
162
|
+
for (const roleIndex of indexes) {
|
|
163
|
+
for (const exclude of allRoleSnippets[roleIndex]) {
|
|
164
|
+
if (exclude.startsWith(`!${domain}`) && exclude !== `!${fullDomain}`) {
|
|
165
|
+
if ([...indexes].every((i) => allRoleSnippets[i].includes(exclude))) {
|
|
166
|
+
excludesSet.add(exclude);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (includes.size > 0) {
|
|
173
|
+
for (const x of [...excludesSet]) {
|
|
174
|
+
const exactMatch = x.slice(1);
|
|
175
|
+
const segments = exactMatch.split(".");
|
|
176
|
+
if (segments.length > 1 && segments[1] !== "*") {
|
|
177
|
+
const parentDomain = segments[0] + ".*";
|
|
178
|
+
if (!includes.has(parentDomain)) {
|
|
179
|
+
excludesSet.delete(x);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return [...includes, ...excludesSet];
|
|
185
|
+
}
|
|
186
|
+
__name(mergeRoleSnippets, "mergeRoleSnippets");
|
|
187
|
+
function mergeRoleResources(sourceResources, newResources) {
|
|
188
|
+
if (sourceResources === null) {
|
|
189
|
+
return newResources;
|
|
190
|
+
}
|
|
191
|
+
return [...new Set(sourceResources.concat(newResources))];
|
|
192
|
+
}
|
|
193
|
+
__name(mergeRoleResources, "mergeRoleResources");
|
|
194
|
+
function mergeAclActionParams(sourceParams, targetParams) {
|
|
195
|
+
if (import_lodash.default.isEmpty(sourceParams) || import_lodash.default.isEmpty(targetParams)) {
|
|
196
|
+
return {};
|
|
197
|
+
}
|
|
198
|
+
removeUnmatchedParams(sourceParams, targetParams, ["fields", "whitelist", "appends"]);
|
|
199
|
+
const andMerge = /* @__PURE__ */ __name((x, y) => {
|
|
200
|
+
if (import_lodash.default.isEmpty(x) || import_lodash.default.isEmpty(y)) {
|
|
201
|
+
return [];
|
|
202
|
+
}
|
|
203
|
+
return import_lodash.default.uniq(x.concat(y)).filter(Boolean);
|
|
204
|
+
}, "andMerge");
|
|
205
|
+
const mergedParams = (0, import_utils.assign)(targetParams, sourceParams, {
|
|
206
|
+
own: /* @__PURE__ */ __name((x, y) => x || y, "own"),
|
|
207
|
+
filter: /* @__PURE__ */ __name((x, y) => {
|
|
208
|
+
if (import_lodash.default.isEmpty(x) || import_lodash.default.isEmpty(y)) {
|
|
209
|
+
return {};
|
|
210
|
+
}
|
|
211
|
+
const xHasOr = import_lodash.default.has(x, "$or"), yHasOr = import_lodash.default.has(y, "$or");
|
|
212
|
+
let $or = [x, y];
|
|
213
|
+
if (xHasOr && !yHasOr) {
|
|
214
|
+
$or = [...x.$or, y];
|
|
215
|
+
} else if (!xHasOr && yHasOr) {
|
|
216
|
+
$or = [x, ...y.$or];
|
|
217
|
+
} else if (xHasOr && yHasOr) {
|
|
218
|
+
$or = [...x.$or, ...y.$or];
|
|
219
|
+
}
|
|
220
|
+
return { $or: import_lodash.default.uniqWith($or, import_lodash.default.isEqual) };
|
|
221
|
+
}, "filter"),
|
|
222
|
+
fields: andMerge,
|
|
223
|
+
whitelist: andMerge,
|
|
224
|
+
appends: "union"
|
|
225
|
+
});
|
|
226
|
+
removeEmptyParams(mergedParams);
|
|
227
|
+
return mergedParams;
|
|
228
|
+
}
|
|
229
|
+
__name(mergeAclActionParams, "mergeAclActionParams");
|
|
230
|
+
function removeEmptyParams(params) {
|
|
231
|
+
if (!import_lodash.default.isObject(params)) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
Object.keys(params).forEach((key) => {
|
|
235
|
+
if (import_lodash.default.isEmpty(params[key])) {
|
|
236
|
+
delete params[key];
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
__name(removeEmptyParams, "removeEmptyParams");
|
|
241
|
+
function removeUnmatchedParams(source, target, keys) {
|
|
242
|
+
for (const key of keys) {
|
|
243
|
+
if (import_lodash.default.has(source, key) && !import_lodash.default.has(target, key)) {
|
|
244
|
+
delete source[key];
|
|
245
|
+
}
|
|
246
|
+
if (!import_lodash.default.has(source, key) && import_lodash.default.has(target, key)) {
|
|
247
|
+
delete target[key];
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
__name(removeUnmatchedParams, "removeUnmatchedParams");
|
|
252
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
253
|
+
0 && (module.exports = {
|
|
254
|
+
mergeAclActionParams,
|
|
255
|
+
mergeRole,
|
|
256
|
+
removeEmptyParams
|
|
257
|
+
});
|
|
@@ -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 './acl-role';
|
|
@@ -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 utils_exports = {};
|
|
25
|
+
module.exports = __toCommonJS(utils_exports);
|
|
26
|
+
__reExport(utils_exports, require("./acl-role"), module.exports);
|
|
27
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
28
|
+
0 && (module.exports = {
|
|
29
|
+
...require("./acl-role")
|
|
30
|
+
});
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/acl",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0-beta.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.
|
|
10
|
-
"@nocobase/utils": "1.
|
|
9
|
+
"@nocobase/resourcer": "1.8.0-beta.1",
|
|
10
|
+
"@nocobase/utils": "1.8.0-beta.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": "103935669123174f2942247202e3d9ff15f0d4ed"
|
|
19
19
|
}
|