@nocobase/plugin-acl 0.7.0-alpha.7 → 0.7.0-alpha.70
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 +35 -25
- package/lib/actions/role-check.js +85 -38
- package/lib/actions/role-collections.js +78 -53
- package/lib/collections/roles.js +70 -78
- package/lib/collections/rolesResources.js +27 -30
- package/lib/collections/rolesResourcesActions.js +26 -27
- package/lib/collections/rolesResourcesScopes.js +21 -22
- package/lib/index.js +14 -8
- package/lib/model/RoleModel.js +39 -15
- package/lib/model/RoleResourceActionModel.js +103 -66
- package/lib/model/RoleResourceModel.js +125 -56
- package/lib/server.js +609 -351
- package/package.json +5 -10
- package/src/__tests__/acl.test.ts +50 -0
- package/src/__tests__/own.test.ts +5 -6
- package/src/actions/role-collections.ts +15 -5
- package/src/model/RoleResourceActionModel.ts +4 -2
- package/src/model/RoleResourceModel.ts +12 -4
- package/src/server.ts +5 -0
- package/esm/actions/available-actions.d.ts +0 -7
- package/esm/actions/available-actions.js +0 -26
- package/esm/actions/available-actions.js.map +0 -1
- package/esm/actions/role-check.d.ts +0 -1
- package/esm/actions/role-check.js +0 -38
- package/esm/actions/role-check.js.map +0 -1
- package/esm/actions/role-collections.d.ts +0 -7
- package/esm/actions/role-collections.js +0 -54
- package/esm/actions/role-collections.js.map +0 -1
- package/esm/collections/roles.d.ts +0 -3
- package/esm/collections/roles.js +0 -78
- package/esm/collections/roles.js.map +0 -1
- package/esm/collections/rolesResources.d.ts +0 -3
- package/esm/collections/rolesResources.js +0 -30
- package/esm/collections/rolesResources.js.map +0 -1
- package/esm/collections/rolesResourcesActions.d.ts +0 -3
- package/esm/collections/rolesResourcesActions.js +0 -27
- package/esm/collections/rolesResourcesActions.js.map +0 -1
- package/esm/collections/rolesResourcesScopes.d.ts +0 -3
- package/esm/collections/rolesResourcesScopes.js +0 -22
- package/esm/collections/rolesResourcesScopes.js.map +0 -1
- package/esm/index.d.ts +0 -1
- package/esm/index.js +0 -2
- package/esm/index.js.map +0 -1
- package/esm/model/RoleModel.d.ts +0 -7
- package/esm/model/RoleModel.js +0 -15
- package/esm/model/RoleModel.js.map +0 -1
- package/esm/model/RoleResourceActionModel.d.ts +0 -12
- package/esm/model/RoleResourceActionModel.js +0 -65
- package/esm/model/RoleResourceActionModel.js.map +0 -1
- package/esm/model/RoleResourceModel.d.ts +0 -16
- package/esm/model/RoleResourceModel.js +0 -55
- package/esm/model/RoleResourceModel.js.map +0 -1
- package/esm/server.d.ts +0 -33
- package/esm/server.js +0 -366
- package/esm/server.js.map +0 -1
- package/lib/actions/available-actions.js.map +0 -1
- package/lib/actions/role-check.js.map +0 -1
- package/lib/actions/role-collections.js.map +0 -1
- package/lib/collections/roles.js.map +0 -1
- package/lib/collections/rolesResources.js.map +0 -1
- package/lib/collections/rolesResourcesActions.js.map +0 -1
- package/lib/collections/rolesResourcesScopes.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/model/RoleModel.js.map +0 -1
- package/lib/model/RoleResourceActionModel.js.map +0 -1
- package/lib/model/RoleResourceModel.js.map +0 -1
- package/lib/server.js.map +0 -1
- package/tsconfig.build.json +0 -9
- package/tsconfig.json +0 -5
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
exports
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
],
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = {
|
|
8
|
+
name: 'rolesResourcesScopes',
|
|
9
|
+
fields: [{
|
|
10
|
+
type: 'uid',
|
|
11
|
+
name: 'key'
|
|
12
|
+
}, {
|
|
13
|
+
type: 'string',
|
|
14
|
+
name: 'name'
|
|
15
|
+
}, {
|
|
16
|
+
type: 'string',
|
|
17
|
+
name: 'resourceName'
|
|
18
|
+
}, {
|
|
19
|
+
type: 'json',
|
|
20
|
+
name: 'scope'
|
|
21
|
+
}]
|
|
23
22
|
};
|
|
24
|
-
|
|
23
|
+
exports.default = _default;
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "default", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _server.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
var _server = _interopRequireDefault(require("./server"));
|
|
14
|
+
|
|
15
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/lib/model/RoleModel.js
CHANGED
|
@@ -1,19 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
3
6
|
exports.RoleModel = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
|
|
8
|
+
function _database() {
|
|
9
|
+
const data = require("@nocobase/database");
|
|
10
|
+
|
|
11
|
+
_database = function _database() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
+
|
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
+
|
|
22
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
23
|
+
|
|
24
|
+
class RoleModel extends _database().Model {
|
|
25
|
+
writeToAcl(options) {
|
|
26
|
+
const acl = options.acl;
|
|
27
|
+
const roleName = this.get('name');
|
|
28
|
+
let role = acl.getRole(roleName);
|
|
29
|
+
|
|
30
|
+
if (!role) {
|
|
31
|
+
role = acl.define({
|
|
32
|
+
role: roleName
|
|
33
|
+
});
|
|
16
34
|
}
|
|
35
|
+
|
|
36
|
+
role.setStrategy(_objectSpread(_objectSpread({}, this.get('strategy') || {}), {}, {
|
|
37
|
+
allowConfigure: this.get('allowConfigure')
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
|
|
17
41
|
}
|
|
18
|
-
|
|
19
|
-
|
|
42
|
+
|
|
43
|
+
exports.RoleModel = RoleModel;
|
|
@@ -1,69 +1,106 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
12
6
|
exports.RoleResourceActionModel = void 0;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const fields = this.get('fields');
|
|
23
|
-
const actionPath = `${resourceName}:${actionName}`;
|
|
24
|
-
const actionParams = {
|
|
25
|
-
fields,
|
|
26
|
-
};
|
|
27
|
-
// @ts-ignore
|
|
28
|
-
const scope = yield this.getScope();
|
|
29
|
-
if (scope) {
|
|
30
|
-
actionParams['own'] = scope.get('key') === 'own';
|
|
31
|
-
actionParams['filter'] = scope.get('scope');
|
|
32
|
-
}
|
|
33
|
-
role.grantAction(actionPath, actionParams);
|
|
34
|
-
const collection = db.getCollection(resourceName);
|
|
35
|
-
if (!collection) {
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
const availableAction = acl.resolveActionAlias(actionName);
|
|
39
|
-
for (const field of fields) {
|
|
40
|
-
const collectionField = collection.getField(field);
|
|
41
|
-
const fieldType = collectionField.get('interface');
|
|
42
|
-
const fieldActions = (_a = associationFieldsActions === null || associationFieldsActions === void 0 ? void 0 : associationFieldsActions[fieldType]) === null || _a === void 0 ? void 0 : _a[availableAction];
|
|
43
|
-
const fieldTarget = collectionField.get('target');
|
|
44
|
-
if (fieldActions) {
|
|
45
|
-
const associationActions = fieldActions.associationActions || [];
|
|
46
|
-
associationActions.forEach((associationAction) => {
|
|
47
|
-
const actionName = `${resourceName}.${fieldTarget}:${associationAction}`;
|
|
48
|
-
role.grantAction(actionName);
|
|
49
|
-
});
|
|
50
|
-
const targetActions = fieldActions.targetActions || [];
|
|
51
|
-
targetActions.forEach((targetAction) => {
|
|
52
|
-
const targetActionPath = `${fieldTarget}:${targetAction}`;
|
|
53
|
-
grantHelper.resourceTargetActionMap.set(resourceName, [
|
|
54
|
-
...(grantHelper.resourceTargetActionMap.get(resourceName) || []),
|
|
55
|
-
targetActionPath,
|
|
56
|
-
]);
|
|
57
|
-
grantHelper.targetActionResourceMap.set(targetActionPath, [
|
|
58
|
-
...(grantHelper.targetActionResourceMap.get(targetActionPath) || []),
|
|
59
|
-
resourceName,
|
|
60
|
-
]);
|
|
61
|
-
role.grantAction(targetActionPath);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
7
|
+
|
|
8
|
+
function _database() {
|
|
9
|
+
const data = require("@nocobase/database");
|
|
10
|
+
|
|
11
|
+
_database = function _database() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
67
16
|
}
|
|
68
|
-
|
|
69
|
-
|
|
17
|
+
|
|
18
|
+
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; } } }; }
|
|
19
|
+
|
|
20
|
+
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); }
|
|
21
|
+
|
|
22
|
+
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; }
|
|
23
|
+
|
|
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); } }
|
|
25
|
+
|
|
26
|
+
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); }); }; }
|
|
27
|
+
|
|
28
|
+
class RoleResourceActionModel extends _database().Model {
|
|
29
|
+
writeToACL(options) {
|
|
30
|
+
var _this = this;
|
|
31
|
+
|
|
32
|
+
return _asyncToGenerator(function* () {
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
const db = _this.constructor.database;
|
|
35
|
+
const resourceName = options.resourceName,
|
|
36
|
+
role = options.role,
|
|
37
|
+
acl = options.acl,
|
|
38
|
+
associationFieldsActions = options.associationFieldsActions,
|
|
39
|
+
grantHelper = options.grantHelper;
|
|
40
|
+
|
|
41
|
+
const actionName = _this.get('name');
|
|
42
|
+
|
|
43
|
+
const fields = _this.get('fields');
|
|
44
|
+
|
|
45
|
+
const actionPath = `${resourceName}:${actionName}`;
|
|
46
|
+
const actionParams = {
|
|
47
|
+
fields
|
|
48
|
+
}; // @ts-ignore
|
|
49
|
+
|
|
50
|
+
const scope = yield _this.getScope();
|
|
51
|
+
|
|
52
|
+
if (scope) {
|
|
53
|
+
actionParams['own'] = scope.get('key') === 'own';
|
|
54
|
+
actionParams['filter'] = scope.get('scope');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
role.grantAction(actionPath, actionParams);
|
|
58
|
+
const collection = db.getCollection(resourceName);
|
|
59
|
+
|
|
60
|
+
if (!collection) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const availableAction = acl.resolveActionAlias(actionName);
|
|
65
|
+
|
|
66
|
+
var _iterator = _createForOfIteratorHelper(fields),
|
|
67
|
+
_step;
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
71
|
+
var _associationFieldsAct;
|
|
72
|
+
|
|
73
|
+
const field = _step.value;
|
|
74
|
+
const collectionField = collection.getField(field);
|
|
75
|
+
const fieldType = collectionField.get('interface');
|
|
76
|
+
const fieldActions = associationFieldsActions === null || associationFieldsActions === void 0 ? void 0 : (_associationFieldsAct = associationFieldsActions[fieldType]) === null || _associationFieldsAct === void 0 ? void 0 : _associationFieldsAct[availableAction];
|
|
77
|
+
const fieldTarget = collectionField.get('target');
|
|
78
|
+
|
|
79
|
+
if (fieldActions) {
|
|
80
|
+
// grant association actions to role
|
|
81
|
+
const associationActions = fieldActions.associationActions || [];
|
|
82
|
+
associationActions.forEach(associationAction => {
|
|
83
|
+
const actionName = `${resourceName}.${fieldTarget}:${associationAction}`;
|
|
84
|
+
role.grantAction(actionName);
|
|
85
|
+
});
|
|
86
|
+
const targetActions = fieldActions.targetActions || [];
|
|
87
|
+
targetActions.forEach(targetAction => {
|
|
88
|
+
const targetActionPath = `${fieldTarget}:${targetAction}`; // set resource target action with current resourceName
|
|
89
|
+
|
|
90
|
+
grantHelper.resourceTargetActionMap.set(`${role.name}.${resourceName}`, [...(grantHelper.resourceTargetActionMap.get(resourceName) || []), targetActionPath]);
|
|
91
|
+
grantHelper.targetActionResourceMap.set(targetActionPath, [...(grantHelper.targetActionResourceMap.get(targetActionPath) || []), `${role.name}.${resourceName}`]);
|
|
92
|
+
role.grantAction(targetActionPath);
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
} catch (err) {
|
|
97
|
+
_iterator.e(err);
|
|
98
|
+
} finally {
|
|
99
|
+
_iterator.f();
|
|
100
|
+
}
|
|
101
|
+
})();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
exports.RoleResourceActionModel = RoleResourceActionModel;
|
|
@@ -1,59 +1,128 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
12
6
|
exports.RoleResourceModel = void 0;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
grantHelper.targetActionResourceMap.set(targetAction, targetActionResource);
|
|
23
|
-
if (targetActionResource.length == 0) {
|
|
24
|
-
role.revokeAction(targetAction);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
grantHelper.resourceTargetActionMap.set(resourceName, []);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
writeToACL(options) {
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
const { acl, associationFieldsActions, grantHelper } = options;
|
|
33
|
-
const resourceName = this.get('name');
|
|
34
|
-
const roleName = this.get('roleName');
|
|
35
|
-
const role = acl.getRole(roleName);
|
|
36
|
-
// revoke resource of role
|
|
37
|
-
yield this.revoke({ role, resourceName, grantHelper });
|
|
38
|
-
// @ts-ignore
|
|
39
|
-
if (this.usingActionsConfig === false) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
// @ts-ignore
|
|
43
|
-
const actions = yield this.getActions({
|
|
44
|
-
transaction: options.transaction,
|
|
45
|
-
});
|
|
46
|
-
for (const action of actions) {
|
|
47
|
-
yield action.writeToACL({
|
|
48
|
-
acl,
|
|
49
|
-
role,
|
|
50
|
-
resourceName,
|
|
51
|
-
associationFieldsActions,
|
|
52
|
-
grantHelper: options.grantHelper,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}
|
|
7
|
+
|
|
8
|
+
function _database() {
|
|
9
|
+
const data = require("@nocobase/database");
|
|
10
|
+
|
|
11
|
+
_database = function _database() {
|
|
12
|
+
return data;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
return data;
|
|
57
16
|
}
|
|
58
|
-
|
|
59
|
-
|
|
17
|
+
|
|
18
|
+
function _acl() {
|
|
19
|
+
const data = require("@nocobase/acl");
|
|
20
|
+
|
|
21
|
+
_acl = function _acl() {
|
|
22
|
+
return data;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return data;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
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
|
+
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
|
+
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
|
+
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
|
+
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
|
+
class RoleResourceModel extends _database().Model {
|
|
39
|
+
revoke(options) {
|
|
40
|
+
return _asyncToGenerator(function* () {
|
|
41
|
+
const role = options.role,
|
|
42
|
+
resourceName = options.resourceName,
|
|
43
|
+
grantHelper = options.grantHelper;
|
|
44
|
+
role.revokeResource(resourceName);
|
|
45
|
+
const targetActions = grantHelper.resourceTargetActionMap.get(`${role.name}.${resourceName}`) || [];
|
|
46
|
+
|
|
47
|
+
var _iterator = _createForOfIteratorHelper(targetActions),
|
|
48
|
+
_step;
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
52
|
+
const targetAction = _step.value;
|
|
53
|
+
const targetActionResource = (grantHelper.targetActionResourceMap.get(targetAction) || []).filter(item => `${role.name}.${resourceName}` !== item);
|
|
54
|
+
grantHelper.targetActionResourceMap.set(targetAction, targetActionResource);
|
|
55
|
+
|
|
56
|
+
if (targetActionResource.length == 0) {
|
|
57
|
+
role.revokeAction(targetAction);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
} catch (err) {
|
|
61
|
+
_iterator.e(err);
|
|
62
|
+
} finally {
|
|
63
|
+
_iterator.f();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
grantHelper.resourceTargetActionMap.set(`${role.name}.${resourceName}`, []);
|
|
67
|
+
})();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
writeToACL(options) {
|
|
71
|
+
var _this = this;
|
|
72
|
+
|
|
73
|
+
return _asyncToGenerator(function* () {
|
|
74
|
+
const acl = options.acl,
|
|
75
|
+
associationFieldsActions = options.associationFieldsActions,
|
|
76
|
+
grantHelper = options.grantHelper;
|
|
77
|
+
|
|
78
|
+
const resourceName = _this.get('name');
|
|
79
|
+
|
|
80
|
+
const roleName = _this.get('roleName');
|
|
81
|
+
|
|
82
|
+
const role = acl.getRole(roleName); // revoke resource of role
|
|
83
|
+
|
|
84
|
+
yield _this.revoke({
|
|
85
|
+
role,
|
|
86
|
+
resourceName,
|
|
87
|
+
grantHelper
|
|
88
|
+
}); // @ts-ignore
|
|
89
|
+
|
|
90
|
+
if (_this.usingActionsConfig === false) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const resource = new (_acl().ACLResource)({
|
|
95
|
+
role,
|
|
96
|
+
name: resourceName
|
|
97
|
+
});
|
|
98
|
+
role.resources.set(resourceName, resource); // @ts-ignore
|
|
99
|
+
|
|
100
|
+
const actions = yield _this.getActions({
|
|
101
|
+
transaction: options.transaction
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
var _iterator2 = _createForOfIteratorHelper(actions),
|
|
105
|
+
_step2;
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
109
|
+
const action = _step2.value;
|
|
110
|
+
yield action.writeToACL({
|
|
111
|
+
acl,
|
|
112
|
+
role,
|
|
113
|
+
resourceName,
|
|
114
|
+
associationFieldsActions,
|
|
115
|
+
grantHelper: options.grantHelper
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
} catch (err) {
|
|
119
|
+
_iterator2.e(err);
|
|
120
|
+
} finally {
|
|
121
|
+
_iterator2.f();
|
|
122
|
+
}
|
|
123
|
+
})();
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
exports.RoleResourceModel = RoleResourceModel;
|