@nocobase/plugin-acl 0.9.1-alpha.2 → 0.9.2-alpha.2
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/actions/available-actions.js +3 -8
- package/lib/actions/role-check.js +8 -27
- package/lib/actions/role-collections.js +21 -32
- package/lib/actions/user-setDefaultRole.js +2 -9
- package/lib/collections/roles-users.js +1 -1
- package/lib/collections/roles.js +5 -2
- package/lib/collections/rolesResources.js +1 -1
- package/lib/collections/rolesResourcesActions.js +1 -1
- package/lib/collections/rolesResourcesScopes.js +1 -1
- package/lib/collections/users.js +0 -5
- package/lib/index.js +0 -2
- package/lib/middlewares/setCurrentRole.js +0 -13
- package/lib/migrations/20221214072638-set-role-snippets.js +0 -10
- package/lib/model/RoleModel.js +3 -12
- package/lib/model/RoleResourceActionModel.js +9 -36
- package/lib/model/RoleResourceModel.js +12 -40
- package/lib/server.js +78 -282
- package/package.json +10 -7
|
@@ -4,55 +4,40 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.RoleResourceModel = void 0;
|
|
7
|
-
|
|
8
7
|
function _acl() {
|
|
9
8
|
const data = require("@nocobase/acl");
|
|
10
|
-
|
|
11
9
|
_acl = function _acl() {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function _database() {
|
|
19
15
|
const data = require("@nocobase/database");
|
|
20
|
-
|
|
21
16
|
_database = function _database() {
|
|
22
17
|
return data;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
return data;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
29
|
-
|
|
30
22
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
31
|
-
|
|
32
23
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
33
|
-
|
|
34
24
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
35
|
-
|
|
36
25
|
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
37
|
-
|
|
38
26
|
class RoleResourceModel extends _database().Model {
|
|
39
27
|
revoke(options) {
|
|
40
28
|
return _asyncToGenerator(function* () {
|
|
41
29
|
const role = options.role,
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
resourceName = options.resourceName,
|
|
31
|
+
grantHelper = options.grantHelper;
|
|
44
32
|
role.revokeResource(resourceName);
|
|
45
33
|
const targetActions = grantHelper.resourceTargetActionMap.get(`${role.name}.${resourceName}`) || [];
|
|
46
|
-
|
|
47
34
|
var _iterator = _createForOfIteratorHelper(targetActions),
|
|
48
|
-
|
|
49
|
-
|
|
35
|
+
_step;
|
|
50
36
|
try {
|
|
51
37
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
52
38
|
const targetAction = _step.value;
|
|
53
39
|
const targetActionResource = (grantHelper.targetActionResourceMap.get(targetAction) || []).filter(item => `${role.name}.${resourceName}` !== item);
|
|
54
40
|
grantHelper.targetActionResourceMap.set(targetAction, targetActionResource);
|
|
55
|
-
|
|
56
41
|
if (targetActionResource.length == 0) {
|
|
57
42
|
role.revokeAction(targetAction);
|
|
58
43
|
}
|
|
@@ -62,54 +47,43 @@ class RoleResourceModel extends _database().Model {
|
|
|
62
47
|
} finally {
|
|
63
48
|
_iterator.f();
|
|
64
49
|
}
|
|
65
|
-
|
|
66
50
|
grantHelper.resourceTargetActionMap.set(`${role.name}.${resourceName}`, []);
|
|
67
51
|
})();
|
|
68
52
|
}
|
|
69
|
-
|
|
70
53
|
writeToACL(options) {
|
|
71
54
|
var _this = this;
|
|
72
|
-
|
|
73
55
|
return _asyncToGenerator(function* () {
|
|
74
56
|
const acl = options.acl,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
57
|
+
associationFieldsActions = options.associationFieldsActions,
|
|
58
|
+
grantHelper = options.grantHelper;
|
|
78
59
|
const resourceName = _this.get('name');
|
|
79
|
-
|
|
80
60
|
const roleName = _this.get('roleName');
|
|
81
|
-
|
|
82
61
|
const role = acl.getRole(roleName);
|
|
83
|
-
|
|
84
62
|
if (!role) {
|
|
85
63
|
console.log(`${roleName} role does not exist`);
|
|
86
64
|
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
65
|
+
}
|
|
66
|
+
// revoke resource of role
|
|
90
67
|
yield _this.revoke({
|
|
91
68
|
role,
|
|
92
69
|
resourceName,
|
|
93
70
|
grantHelper
|
|
94
|
-
});
|
|
95
|
-
|
|
71
|
+
});
|
|
72
|
+
// @ts-ignore
|
|
96
73
|
if (_this.usingActionsConfig === false) {
|
|
97
74
|
return;
|
|
98
75
|
}
|
|
99
|
-
|
|
100
76
|
const resource = new (_acl().ACLResource)({
|
|
101
77
|
role,
|
|
102
78
|
name: resourceName
|
|
103
79
|
});
|
|
104
|
-
role.resources.set(resourceName, resource);
|
|
105
|
-
|
|
80
|
+
role.resources.set(resourceName, resource);
|
|
81
|
+
// @ts-ignore
|
|
106
82
|
const actions = yield _this.getActions({
|
|
107
83
|
transaction: options.transaction
|
|
108
84
|
});
|
|
109
|
-
|
|
110
85
|
var _iterator2 = _createForOfIteratorHelper(actions),
|
|
111
|
-
|
|
112
|
-
|
|
86
|
+
_step2;
|
|
113
87
|
try {
|
|
114
88
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
115
89
|
const action = _step2.value;
|
|
@@ -128,7 +102,5 @@ class RoleResourceModel extends _database().Model {
|
|
|
128
102
|
}
|
|
129
103
|
})();
|
|
130
104
|
}
|
|
131
|
-
|
|
132
105
|
}
|
|
133
|
-
|
|
134
106
|
exports.RoleResourceModel = RoleResourceModel;
|