@nocobase/plugin-acl 0.9.1-alpha.1 → 0.9.2-alpha.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/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,17 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.availableActionResource = void 0;
|
|
7
|
-
|
|
8
7
|
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; }
|
|
9
|
-
|
|
10
8
|
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; }
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
9
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
10
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
11
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
14
12
|
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); } }
|
|
15
|
-
|
|
16
13
|
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); }); }; }
|
|
17
|
-
|
|
18
14
|
const availableActionResource = {
|
|
19
15
|
name: 'availableActions',
|
|
20
16
|
actions: {
|
|
@@ -33,7 +29,6 @@ const availableActionResource = {
|
|
|
33
29
|
yield next();
|
|
34
30
|
})();
|
|
35
31
|
}
|
|
36
|
-
|
|
37
32
|
}
|
|
38
33
|
};
|
|
39
34
|
exports.availableActionResource = availableActionResource;
|
|
@@ -4,43 +4,29 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.checkAction = checkAction;
|
|
7
|
-
|
|
8
7
|
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; }
|
|
9
|
-
|
|
10
8
|
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; }
|
|
11
|
-
|
|
12
|
-
function
|
|
13
|
-
|
|
9
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
10
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
11
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
14
12
|
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); } }
|
|
15
|
-
|
|
16
13
|
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); }); }; }
|
|
17
|
-
|
|
18
14
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
19
|
-
|
|
20
15
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
21
|
-
|
|
22
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
23
|
-
|
|
16
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
24
17
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
25
|
-
|
|
26
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(_e2) { throw _e2; }, 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(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
27
|
-
|
|
28
19
|
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); }
|
|
29
|
-
|
|
30
20
|
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; }
|
|
31
|
-
|
|
32
21
|
const map2obj = map => {
|
|
33
22
|
const obj = {};
|
|
34
|
-
|
|
35
23
|
var _iterator = _createForOfIteratorHelper(map),
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
_step;
|
|
38
25
|
try {
|
|
39
26
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
40
27
|
let _step$value = _slicedToArray(_step.value, 2),
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
28
|
+
key = _step$value[0],
|
|
29
|
+
value = _step$value[1];
|
|
44
30
|
obj[key] = value;
|
|
45
31
|
}
|
|
46
32
|
} catch (err) {
|
|
@@ -48,18 +34,14 @@ const map2obj = map => {
|
|
|
48
34
|
} finally {
|
|
49
35
|
_iterator.f();
|
|
50
36
|
}
|
|
51
|
-
|
|
52
37
|
return obj;
|
|
53
38
|
};
|
|
54
|
-
|
|
55
|
-
function checkAction(_x, _x2) {
|
|
39
|
+
function checkAction(_x2, _x3) {
|
|
56
40
|
return _checkAction.apply(this, arguments);
|
|
57
41
|
}
|
|
58
|
-
|
|
59
42
|
function _checkAction() {
|
|
60
43
|
_checkAction = _asyncToGenerator(function* (ctx, next) {
|
|
61
44
|
const currentRole = ctx.state.currentRole;
|
|
62
|
-
|
|
63
45
|
if (currentRole) {
|
|
64
46
|
const roleInstance = yield ctx.db.getRepository('roles').findOne({
|
|
65
47
|
filter: {
|
|
@@ -86,7 +68,6 @@ function _checkAction() {
|
|
|
86
68
|
} else {
|
|
87
69
|
throw new Error('Role not found');
|
|
88
70
|
}
|
|
89
|
-
|
|
90
71
|
yield next();
|
|
91
72
|
});
|
|
92
73
|
return _checkAction.apply(this, arguments);
|
|
@@ -4,27 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.roleCollectionsResource = void 0;
|
|
7
|
-
|
|
8
7
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
9
|
-
|
|
10
8
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11
|
-
|
|
12
9
|
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); }
|
|
13
|
-
|
|
14
10
|
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; }
|
|
15
|
-
|
|
16
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
17
|
-
|
|
11
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
18
12
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
19
|
-
|
|
20
13
|
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); } }
|
|
21
|
-
|
|
22
14
|
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); }); }; }
|
|
23
|
-
|
|
24
15
|
function totalPage(total, pageSize) {
|
|
25
16
|
return Math.ceil(total / pageSize);
|
|
26
17
|
}
|
|
27
|
-
|
|
28
18
|
const roleCollectionsResource = {
|
|
29
19
|
name: 'roles.collections',
|
|
30
20
|
actions: {
|
|
@@ -32,35 +22,35 @@ const roleCollectionsResource = {
|
|
|
32
22
|
return _asyncToGenerator(function* () {
|
|
33
23
|
const role = ctx.action.params.associatedIndex;
|
|
34
24
|
const _ctx$action$params = ctx.action.params,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
25
|
+
_ctx$action$params$pa = _ctx$action$params.page,
|
|
26
|
+
page = _ctx$action$params$pa === void 0 ? 1 : _ctx$action$params$pa,
|
|
27
|
+
_ctx$action$params$pa2 = _ctx$action$params.pageSize,
|
|
28
|
+
pageSize = _ctx$action$params$pa2 === void 0 ? 20 : _ctx$action$params$pa2;
|
|
39
29
|
const db = ctx.db;
|
|
40
30
|
const collectionRepository = db.getRepository('collections');
|
|
41
|
-
const fieldRepository = db.getRepository('fields');
|
|
42
|
-
|
|
31
|
+
const fieldRepository = db.getRepository('fields');
|
|
32
|
+
// all collections
|
|
43
33
|
const _yield$collectionRepo = yield collectionRepository.findAndCount({
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
34
|
+
filter: ctx.action.params.filter,
|
|
35
|
+
sort: 'sort'
|
|
36
|
+
}),
|
|
37
|
+
_yield$collectionRepo2 = _slicedToArray(_yield$collectionRepo, 2),
|
|
38
|
+
collections = _yield$collectionRepo2[0],
|
|
39
|
+
count = _yield$collectionRepo2[1];
|
|
40
|
+
// role collections
|
|
52
41
|
const roleResources = yield db.getRepository('rolesResources').find({
|
|
53
42
|
filter: {
|
|
54
43
|
roleName: role
|
|
55
44
|
}
|
|
56
|
-
});
|
|
57
|
-
|
|
45
|
+
});
|
|
46
|
+
// role collections
|
|
58
47
|
const roleResourcesNames = roleResources.map(roleResource => roleResource.get('name'));
|
|
59
48
|
const roleResourceActionResourceNames = roleResources.filter(roleResources => roleResources.get('usingActionsConfig')).map(roleResources => roleResources.get('name'));
|
|
60
49
|
const items = collections.map((collection, i) => {
|
|
61
50
|
const exists = roleResourcesNames.includes(collection.get('name'));
|
|
62
51
|
const usingConfig = roleResourceActionResourceNames.includes(collection.get('name')) ? 'resourceAction' : 'strategy';
|
|
63
|
-
const c = db.getCollection(collection.get('name'));
|
|
52
|
+
const c = db.getCollection(collection.get('name'));
|
|
53
|
+
// const children = [...c.fields.values()]
|
|
64
54
|
// .filter(
|
|
65
55
|
// (f) => f.options.interface && ['hasOne', 'hasMany', 'belongsTo', 'belongsToMany'].includes(f.options.type),
|
|
66
56
|
// )
|
|
@@ -81,7 +71,6 @@ const roleCollectionsResource = {
|
|
|
81
71
|
// exists,
|
|
82
72
|
// };
|
|
83
73
|
// });
|
|
84
|
-
|
|
85
74
|
return {
|
|
86
75
|
type: 'collection',
|
|
87
76
|
name: collection.get('name'),
|
|
@@ -89,10 +78,11 @@ const roleCollectionsResource = {
|
|
|
89
78
|
title: collection.get('title'),
|
|
90
79
|
roleName: role,
|
|
91
80
|
usingConfig,
|
|
92
|
-
exists
|
|
93
|
-
|
|
81
|
+
exists
|
|
82
|
+
// children: children.length > 0 ? children : null,
|
|
94
83
|
};
|
|
95
84
|
});
|
|
85
|
+
|
|
96
86
|
ctx.body = {
|
|
97
87
|
count,
|
|
98
88
|
rows: items,
|
|
@@ -103,7 +93,6 @@ const roleCollectionsResource = {
|
|
|
103
93
|
yield next();
|
|
104
94
|
})();
|
|
105
95
|
}
|
|
106
|
-
|
|
107
96
|
}
|
|
108
97
|
};
|
|
109
98
|
exports.roleCollectionsResource = roleCollectionsResource;
|
|
@@ -4,26 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.setDefaultRole = setDefaultRole;
|
|
7
|
-
|
|
8
7
|
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); } }
|
|
9
|
-
|
|
10
8
|
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); }); }; }
|
|
11
|
-
|
|
12
9
|
function setDefaultRole(_x, _x2) {
|
|
13
10
|
return _setDefaultRole.apply(this, arguments);
|
|
14
11
|
}
|
|
15
|
-
|
|
16
12
|
function _setDefaultRole() {
|
|
17
13
|
_setDefaultRole = _asyncToGenerator(function* (ctx, next) {
|
|
18
14
|
const roleName = ctx.action.params.values.roleName;
|
|
19
15
|
const db = ctx.db,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
currentUser = ctx.state.currentUser,
|
|
17
|
+
values = ctx.action.params.values;
|
|
23
18
|
if (values.roleName == 'anonymous') {
|
|
24
19
|
return next();
|
|
25
20
|
}
|
|
26
|
-
|
|
27
21
|
const repository = db.getRepository('rolesUsers');
|
|
28
22
|
yield db.sequelize.transaction( /*#__PURE__*/function () {
|
|
29
23
|
var _ref = _asyncToGenerator(function* (transaction) {
|
|
@@ -47,7 +41,6 @@ function _setDefaultRole() {
|
|
|
47
41
|
transaction
|
|
48
42
|
});
|
|
49
43
|
});
|
|
50
|
-
|
|
51
44
|
return function (_x3) {
|
|
52
45
|
return _ref.apply(this, arguments);
|
|
53
46
|
};
|
package/lib/collections/roles.js
CHANGED
|
@@ -5,8 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _default = {
|
|
8
|
-
namespace: 'acl',
|
|
9
|
-
duplicator:
|
|
8
|
+
namespace: 'acl.acl',
|
|
9
|
+
duplicator: {
|
|
10
|
+
dumpable: 'required',
|
|
11
|
+
with: 'uiSchemas'
|
|
12
|
+
},
|
|
10
13
|
name: 'roles',
|
|
11
14
|
title: '{{t("Roles")}}',
|
|
12
15
|
autoGenId: false,
|
package/lib/collections/users.js
CHANGED
|
@@ -4,17 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function _database() {
|
|
9
8
|
const data = require("@nocobase/database");
|
|
10
|
-
|
|
11
9
|
_database = function _database() {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
var _default = (0, _database().extend)({
|
|
19
15
|
name: 'users',
|
|
20
16
|
fields: [{
|
|
@@ -42,5 +38,4 @@ var _default = (0, _database().extend)({
|
|
|
42
38
|
}
|
|
43
39
|
}]
|
|
44
40
|
});
|
|
45
|
-
|
|
46
41
|
exports.default = _default;
|
package/lib/index.js
CHANGED
|
@@ -4,53 +4,40 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.setCurrentRole = setCurrentRole;
|
|
7
|
-
|
|
8
7
|
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); } }
|
|
9
|
-
|
|
10
8
|
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); }); }; }
|
|
11
|
-
|
|
12
9
|
function setCurrentRole(_x, _x2) {
|
|
13
10
|
return _setCurrentRole.apply(this, arguments);
|
|
14
11
|
}
|
|
15
|
-
|
|
16
12
|
function _setCurrentRole() {
|
|
17
13
|
_setCurrentRole = _asyncToGenerator(function* (ctx, next) {
|
|
18
14
|
let currentRole = ctx.get('X-Role');
|
|
19
|
-
|
|
20
15
|
if (currentRole === 'anonymous') {
|
|
21
16
|
ctx.state.currentRole = currentRole;
|
|
22
17
|
return next();
|
|
23
18
|
}
|
|
24
|
-
|
|
25
19
|
if (!ctx.state.currentUser) {
|
|
26
20
|
return next();
|
|
27
21
|
}
|
|
28
|
-
|
|
29
22
|
const repository = ctx.db.getRepository('users.roles', ctx.state.currentUser.id);
|
|
30
23
|
const roles = yield repository.find();
|
|
31
24
|
ctx.state.currentUser.setDataValue('roles', roles);
|
|
32
|
-
|
|
33
25
|
if (roles.length == 1) {
|
|
34
26
|
currentRole = roles[0].name;
|
|
35
27
|
} else if (roles.length > 1) {
|
|
36
28
|
const role = roles.find(item => item.name === currentRole);
|
|
37
|
-
|
|
38
29
|
if (!role) {
|
|
39
30
|
var _ref;
|
|
40
|
-
|
|
41
31
|
const defaultRole = roles.find(item => {
|
|
42
32
|
var _item$rolesUsers;
|
|
43
|
-
|
|
44
33
|
return item === null || item === void 0 ? void 0 : (_item$rolesUsers = item.rolesUsers) === null || _item$rolesUsers === void 0 ? void 0 : _item$rolesUsers.default;
|
|
45
34
|
});
|
|
46
35
|
currentRole = (_ref = defaultRole || roles[0]) === null || _ref === void 0 ? void 0 : _ref.name;
|
|
47
36
|
}
|
|
48
37
|
}
|
|
49
|
-
|
|
50
38
|
if (currentRole) {
|
|
51
39
|
ctx.state.currentRole = currentRole;
|
|
52
40
|
}
|
|
53
|
-
|
|
54
41
|
yield next();
|
|
55
42
|
});
|
|
56
43
|
return _setCurrentRole.apply(this, arguments);
|
|
@@ -4,25 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function _server() {
|
|
9
8
|
const data = require("@nocobase/server");
|
|
10
|
-
|
|
11
9
|
_server = function _server() {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
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); } }
|
|
19
|
-
|
|
20
15
|
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); }); }; }
|
|
21
|
-
|
|
22
16
|
class _default extends _server().Migration {
|
|
23
17
|
up() {
|
|
24
18
|
var _this = this;
|
|
25
|
-
|
|
26
19
|
return _asyncToGenerator(function* () {
|
|
27
20
|
yield _this.app.db.getRepository('roles').update({
|
|
28
21
|
filter: {
|
|
@@ -39,11 +32,8 @@ class _default extends _server().Migration {
|
|
|
39
32
|
});
|
|
40
33
|
})();
|
|
41
34
|
}
|
|
42
|
-
|
|
43
35
|
down() {
|
|
44
36
|
return _asyncToGenerator(function* () {})();
|
|
45
37
|
}
|
|
46
|
-
|
|
47
38
|
}
|
|
48
|
-
|
|
49
39
|
exports.default = _default;
|
package/lib/model/RoleModel.js
CHANGED
|
@@ -4,41 +4,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.RoleModel = void 0;
|
|
7
|
-
|
|
8
7
|
function _database() {
|
|
9
8
|
const data = require("@nocobase/database");
|
|
10
|
-
|
|
11
9
|
_database = function _database() {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
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
15
|
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
|
|
23
|
-
|
|
16
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
17
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
18
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
24
19
|
class RoleModel extends _database().Model {
|
|
25
20
|
writeToAcl(options) {
|
|
26
21
|
const acl = options.acl;
|
|
27
22
|
const roleName = this.get('name');
|
|
28
23
|
let role = acl.getRole(roleName);
|
|
29
|
-
|
|
30
24
|
if (!role) {
|
|
31
25
|
role = acl.define({
|
|
32
26
|
role: roleName
|
|
33
27
|
});
|
|
34
28
|
}
|
|
35
|
-
|
|
36
29
|
role.setStrategy(_objectSpread(_objectSpread({}, this.get('strategy') || {}), {}, {
|
|
37
30
|
allowConfigure: this.get('allowConfigure')
|
|
38
31
|
}));
|
|
39
32
|
role.snippets = new Set(this.get('snippets'));
|
|
40
33
|
}
|
|
41
|
-
|
|
42
34
|
}
|
|
43
|
-
|
|
44
35
|
exports.RoleModel = RoleModel;
|
|
@@ -4,84 +4,61 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.RoleResourceActionModel = void 0;
|
|
7
|
-
|
|
8
7
|
function _database() {
|
|
9
8
|
const data = require("@nocobase/database");
|
|
10
|
-
|
|
11
9
|
_database = function _database() {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
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
15
|
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
16
|
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
17
|
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
18
|
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
19
|
class RoleResourceActionModel extends _database().Model {
|
|
29
20
|
writeToACL(options) {
|
|
30
21
|
var _this = this;
|
|
31
|
-
|
|
32
22
|
return _asyncToGenerator(function* () {
|
|
33
23
|
// @ts-ignore
|
|
34
24
|
const db = _this.constructor.database;
|
|
35
25
|
const resourceName = options.resourceName,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
26
|
+
role = options.role,
|
|
27
|
+
acl = options.acl,
|
|
28
|
+
associationFieldsActions = options.associationFieldsActions,
|
|
29
|
+
grantHelper = options.grantHelper;
|
|
41
30
|
const actionName = _this.get('name');
|
|
42
|
-
|
|
43
31
|
const fields = _this.get('fields');
|
|
44
|
-
|
|
45
32
|
const actionPath = `${resourceName}:${actionName}`;
|
|
46
33
|
const actionParams = {
|
|
47
34
|
fields
|
|
48
|
-
};
|
|
49
|
-
|
|
35
|
+
};
|
|
36
|
+
// @ts-ignore
|
|
50
37
|
const scope = yield _this.getScope();
|
|
51
|
-
|
|
52
38
|
if (scope) {
|
|
53
39
|
actionParams['own'] = scope.get('key') === 'own';
|
|
54
40
|
actionParams['filter'] = scope.get('scope');
|
|
55
41
|
}
|
|
56
|
-
|
|
57
42
|
role.grantAction(actionPath, actionParams);
|
|
58
43
|
const collection = db.getCollection(resourceName);
|
|
59
|
-
|
|
60
44
|
if (!collection) {
|
|
61
45
|
return;
|
|
62
46
|
}
|
|
63
|
-
|
|
64
47
|
const availableAction = acl.resolveActionAlias(actionName);
|
|
65
|
-
|
|
66
48
|
var _iterator = _createForOfIteratorHelper(fields),
|
|
67
|
-
|
|
68
|
-
|
|
49
|
+
_step;
|
|
69
50
|
try {
|
|
70
51
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
71
52
|
var _associationFieldsAct;
|
|
72
|
-
|
|
73
53
|
const field = _step.value;
|
|
74
54
|
const collectionField = collection.getField(field);
|
|
75
|
-
|
|
76
55
|
if (!collectionField) {
|
|
77
56
|
console.log(`${field} does not exist`);
|
|
78
57
|
continue;
|
|
79
58
|
}
|
|
80
|
-
|
|
81
59
|
const fieldType = collectionField.get('type');
|
|
82
60
|
const fieldActions = associationFieldsActions === null || associationFieldsActions === void 0 ? void 0 : (_associationFieldsAct = associationFieldsActions[fieldType]) === null || _associationFieldsAct === void 0 ? void 0 : _associationFieldsAct[availableAction];
|
|
83
61
|
const fieldTarget = collectionField.get('target');
|
|
84
|
-
|
|
85
62
|
if (fieldActions) {
|
|
86
63
|
// grant association actions to role
|
|
87
64
|
const associationActions = fieldActions.associationActions || [];
|
|
@@ -93,12 +70,10 @@ class RoleResourceActionModel extends _database().Model {
|
|
|
93
70
|
targetActions.forEach(targetAction => {
|
|
94
71
|
const targetActionPath = `${fieldTarget}:${targetAction}`;
|
|
95
72
|
const existsAction = role.getActionParams(targetActionPath);
|
|
96
|
-
|
|
97
73
|
if (existsAction) {
|
|
98
74
|
return;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
75
|
+
}
|
|
76
|
+
// set resource target action with current resourceName
|
|
102
77
|
grantHelper.resourceTargetActionMap.set(`${role.name}.${resourceName}`, [...(grantHelper.resourceTargetActionMap.get(resourceName) || []), targetActionPath]);
|
|
103
78
|
grantHelper.targetActionResourceMap.set(targetActionPath, [...(grantHelper.targetActionResourceMap.get(targetActionPath) || []), `${role.name}.${resourceName}`]);
|
|
104
79
|
role.grantAction(targetActionPath);
|
|
@@ -112,7 +87,5 @@ class RoleResourceActionModel extends _database().Model {
|
|
|
112
87
|
}
|
|
113
88
|
})();
|
|
114
89
|
}
|
|
115
|
-
|
|
116
90
|
}
|
|
117
|
-
|
|
118
91
|
exports.RoleResourceActionModel = RoleResourceActionModel;
|