@nocobase/plugin-acl 0.7.0-alpha.8 → 0.7.0-alpha.82

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.
Files changed (69) hide show
  1. package/lib/actions/available-actions.js +35 -25
  2. package/lib/actions/role-check.js +85 -38
  3. package/lib/actions/role-collections.js +78 -53
  4. package/lib/collections/roles.js +70 -78
  5. package/lib/collections/rolesResources.js +27 -30
  6. package/lib/collections/rolesResourcesActions.js +26 -27
  7. package/lib/collections/rolesResourcesScopes.js +21 -22
  8. package/lib/index.js +14 -8
  9. package/lib/model/RoleModel.js +39 -15
  10. package/lib/model/RoleResourceActionModel.js +103 -66
  11. package/lib/model/RoleResourceModel.js +125 -56
  12. package/lib/server.js +609 -351
  13. package/package.json +5 -10
  14. package/src/__tests__/acl.test.ts +50 -0
  15. package/src/__tests__/own.test.ts +5 -6
  16. package/src/actions/role-collections.ts +15 -5
  17. package/src/model/RoleResourceActionModel.ts +4 -2
  18. package/src/model/RoleResourceModel.ts +12 -4
  19. package/src/server.ts +5 -0
  20. package/esm/actions/available-actions.d.ts +0 -7
  21. package/esm/actions/available-actions.js +0 -26
  22. package/esm/actions/available-actions.js.map +0 -1
  23. package/esm/actions/role-check.d.ts +0 -1
  24. package/esm/actions/role-check.js +0 -38
  25. package/esm/actions/role-check.js.map +0 -1
  26. package/esm/actions/role-collections.d.ts +0 -7
  27. package/esm/actions/role-collections.js +0 -54
  28. package/esm/actions/role-collections.js.map +0 -1
  29. package/esm/collections/roles.d.ts +0 -3
  30. package/esm/collections/roles.js +0 -78
  31. package/esm/collections/roles.js.map +0 -1
  32. package/esm/collections/rolesResources.d.ts +0 -3
  33. package/esm/collections/rolesResources.js +0 -30
  34. package/esm/collections/rolesResources.js.map +0 -1
  35. package/esm/collections/rolesResourcesActions.d.ts +0 -3
  36. package/esm/collections/rolesResourcesActions.js +0 -27
  37. package/esm/collections/rolesResourcesActions.js.map +0 -1
  38. package/esm/collections/rolesResourcesScopes.d.ts +0 -3
  39. package/esm/collections/rolesResourcesScopes.js +0 -22
  40. package/esm/collections/rolesResourcesScopes.js.map +0 -1
  41. package/esm/index.d.ts +0 -1
  42. package/esm/index.js +0 -2
  43. package/esm/index.js.map +0 -1
  44. package/esm/model/RoleModel.d.ts +0 -7
  45. package/esm/model/RoleModel.js +0 -15
  46. package/esm/model/RoleModel.js.map +0 -1
  47. package/esm/model/RoleResourceActionModel.d.ts +0 -12
  48. package/esm/model/RoleResourceActionModel.js +0 -65
  49. package/esm/model/RoleResourceActionModel.js.map +0 -1
  50. package/esm/model/RoleResourceModel.d.ts +0 -16
  51. package/esm/model/RoleResourceModel.js +0 -55
  52. package/esm/model/RoleResourceModel.js.map +0 -1
  53. package/esm/server.d.ts +0 -33
  54. package/esm/server.js +0 -366
  55. package/esm/server.js.map +0 -1
  56. package/lib/actions/available-actions.js.map +0 -1
  57. package/lib/actions/role-check.js.map +0 -1
  58. package/lib/actions/role-collections.js.map +0 -1
  59. package/lib/collections/roles.js.map +0 -1
  60. package/lib/collections/rolesResources.js.map +0 -1
  61. package/lib/collections/rolesResourcesActions.js.map +0 -1
  62. package/lib/collections/rolesResourcesScopes.js.map +0 -1
  63. package/lib/index.js.map +0 -1
  64. package/lib/model/RoleModel.js.map +0 -1
  65. package/lib/model/RoleResourceActionModel.js.map +0 -1
  66. package/lib/model/RoleResourceModel.js.map +0 -1
  67. package/lib/server.js.map +0 -1
  68. package/tsconfig.build.json +0 -9
  69. package/tsconfig.json +0 -5
@@ -1,24 +1,23 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = {
4
- name: 'rolesResourcesScopes',
5
- fields: [
6
- {
7
- type: 'uid',
8
- name: 'key',
9
- },
10
- {
11
- type: 'string',
12
- name: 'name',
13
- },
14
- {
15
- type: 'string',
16
- name: 'resourceName',
17
- },
18
- {
19
- type: 'json',
20
- name: 'scope',
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
- //# sourceMappingURL=rolesResourcesScopes.js.map
23
+ exports.default = _default;
package/lib/index.js CHANGED
@@ -1,9 +1,15 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = void 0;
7
- var server_1 = require("./server");
8
- Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(server_1).default; } });
9
- //# sourceMappingURL=index.js.map
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 }; }
@@ -1,19 +1,43 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
3
6
  exports.RoleModel = void 0;
4
- const database_1 = require("@nocobase/database");
5
- class RoleModel extends database_1.Model {
6
- writeToAcl(options) {
7
- const { acl } = options;
8
- const roleName = this.get('name');
9
- let role = acl.getRole(roleName);
10
- if (!role) {
11
- role = acl.define({
12
- role: roleName,
13
- });
14
- }
15
- role.setStrategy(Object.assign(Object.assign({}, (this.get('strategy') || {})), { allowConfigure: this.get('allowConfigure') }));
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
- exports.RoleModel = RoleModel;
19
- //# sourceMappingURL=RoleModel.js.map
42
+
43
+ exports.RoleModel = RoleModel;
@@ -1,69 +1,106 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
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
- const database_1 = require("@nocobase/database");
14
- class RoleResourceActionModel extends database_1.Model {
15
- writeToACL(options) {
16
- var _a;
17
- return __awaiter(this, void 0, void 0, function* () {
18
- // @ts-ignore
19
- const db = this.constructor.database;
20
- const { resourceName, role, acl, associationFieldsActions, grantHelper } = options;
21
- const actionName = this.get('name');
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
- exports.RoleResourceActionModel = RoleResourceActionModel;
69
- //# sourceMappingURL=RoleResourceActionModel.js.map
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
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
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
- const database_1 = require("@nocobase/database");
14
- class RoleResourceModel extends database_1.Model {
15
- revoke(options) {
16
- return __awaiter(this, void 0, void 0, function* () {
17
- const { role, resourceName, grantHelper } = options;
18
- role.revokeResource(resourceName);
19
- const targetActions = grantHelper.resourceTargetActionMap.get(resourceName) || [];
20
- for (const targetAction of targetActions) {
21
- const targetActionResource = (grantHelper.targetActionResourceMap.get(targetAction) || []).filter((item) => resourceName !== item);
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
- exports.RoleResourceModel = RoleResourceModel;
59
- //# sourceMappingURL=RoleResourceModel.js.map
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;