@nocobase/plugin-acl 0.7.0-alpha.56 → 0.7.0-alpha.59

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.
@@ -5,22 +5,48 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.roleCollectionsResource = void 0;
7
7
 
8
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
9
+
10
+ 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
+ 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
+ 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
+
18
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
19
+
8
20
  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
21
 
10
22
  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
23
 
24
+ function totalPage(total, pageSize) {
25
+ return Math.ceil(total / pageSize);
26
+ }
27
+
12
28
  const roleCollectionsResource = {
13
29
  name: 'roles.collections',
14
30
  actions: {
15
31
  list(ctx, next) {
16
32
  return _asyncToGenerator(function* () {
17
33
  const role = ctx.action.params.associatedIndex;
34
+ const _ctx$action$params = ctx.action.params,
35
+ _ctx$action$params$pa = _ctx$action$params.page,
36
+ page = _ctx$action$params$pa === void 0 ? 1 : _ctx$action$params$pa,
37
+ _ctx$action$params$pa2 = _ctx$action$params.pageSize,
38
+ pageSize = _ctx$action$params$pa2 === void 0 ? 20 : _ctx$action$params$pa2;
18
39
  const db = ctx.db;
19
40
  const collectionRepository = db.getRepository('collections'); // all collections
20
41
 
21
- const collections = yield collectionRepository.find({
22
- filter: ctx.action.params.filter
23
- }); // role collections
42
+ const _yield$collectionRepo = yield collectionRepository.findAndCount({
43
+ filter: ctx.action.params.filter,
44
+ sort: 'sort'
45
+ }),
46
+ _yield$collectionRepo2 = _slicedToArray(_yield$collectionRepo, 2),
47
+ collections = _yield$collectionRepo2[0],
48
+ count = _yield$collectionRepo2[1]; // role collections
49
+
24
50
 
25
51
  const roleResources = yield db.getRepository('rolesResources').find({
26
52
  filter: {
@@ -30,17 +56,23 @@ const roleCollectionsResource = {
30
56
 
31
57
  const roleResourcesNames = roleResources.map(roleResource => roleResource.get('name'));
32
58
  const roleResourceActionResourceNames = roleResources.filter(roleResources => roleResources.get('usingActionsConfig')).map(roleResources => roleResources.get('name'));
33
- ctx.body = collections.map(collection => {
34
- const exists = roleResourcesNames.includes(collection.get('name'));
35
- const usingConfig = roleResourceActionResourceNames.includes(collection.get('name')) ? 'resourceAction' : 'strategy';
36
- return {
37
- name: collection.get('name'),
38
- title: collection.get('title'),
39
- roleName: role,
40
- usingConfig,
41
- exists
42
- };
43
- }).sort((a, b) => a.name > b.name ? 1 : -1);
59
+ ctx.body = {
60
+ count,
61
+ rows: collections.map(collection => {
62
+ const exists = roleResourcesNames.includes(collection.get('name'));
63
+ const usingConfig = roleResourceActionResourceNames.includes(collection.get('name')) ? 'resourceAction' : 'strategy';
64
+ return {
65
+ name: collection.get('name'),
66
+ title: collection.get('title'),
67
+ roleName: role,
68
+ usingConfig,
69
+ exists
70
+ };
71
+ }),
72
+ page: Number(page),
73
+ pageSize: Number(pageSize),
74
+ totalPage: totalPage(count, pageSize)
75
+ };
44
76
  yield next();
45
77
  })();
46
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/plugin-acl",
3
- "version": "0.7.0-alpha.56",
3
+ "version": "0.7.0-alpha.59",
4
4
  "description": "",
5
5
  "license": "Apache-2.0",
6
6
  "licenses": [
@@ -12,14 +12,14 @@
12
12
  "main": "./lib/index.js",
13
13
  "types": "./lib/index.d.ts",
14
14
  "dependencies": {
15
- "@nocobase/acl": "0.7.0-alpha.56",
16
- "@nocobase/database": "0.7.0-alpha.56",
17
- "@nocobase/server": "0.7.0-alpha.56"
15
+ "@nocobase/acl": "0.7.0-alpha.59",
16
+ "@nocobase/database": "0.7.0-alpha.59",
17
+ "@nocobase/server": "0.7.0-alpha.59"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
21
21
  "url": "git+https://github.com/nocobase/nocobase.git",
22
22
  "directory": "packages/plugins/acl"
23
23
  },
24
- "gitHead": "9a8c05e8fb26029f1d1ba68408a8bddac0e67a76"
24
+ "gitHead": "c90e5aee4c8257a3ab7ff492e69cb568cccff8b5"
25
25
  }
@@ -2,18 +2,24 @@ import { Database } from '@nocobase/database';
2
2
 
3
3
  type UsingConfigType = 'strategy' | 'resourceAction';
4
4
 
5
+ function totalPage(total, pageSize): number {
6
+ return Math.ceil(total / pageSize);
7
+ }
8
+
5
9
  const roleCollectionsResource = {
6
10
  name: 'roles.collections',
7
11
  actions: {
8
12
  async list(ctx, next) {
9
13
  const role = ctx.action.params.associatedIndex;
14
+ const { page = 1, pageSize = 20 } = ctx.action.params;
10
15
 
11
16
  const db: Database = ctx.db;
12
17
  const collectionRepository = db.getRepository('collections');
13
18
 
14
19
  // all collections
15
- const collections = await collectionRepository.find({
20
+ const [collections, count] = await collectionRepository.findAndCount({
16
21
  filter: ctx.action.params.filter,
22
+ sort: 'sort',
17
23
  });
18
24
 
19
25
  // role collections
@@ -29,8 +35,9 @@ const roleCollectionsResource = {
29
35
  .filter((roleResources) => roleResources.get('usingActionsConfig'))
30
36
  .map((roleResources) => roleResources.get('name'));
31
37
 
32
- ctx.body = collections
33
- .map((collection) => {
38
+ ctx.body = {
39
+ count,
40
+ rows: collections.map((collection) => {
34
41
  const exists = roleResourcesNames.includes(collection.get('name'));
35
42
 
36
43
  const usingConfig: UsingConfigType = roleResourceActionResourceNames.includes(collection.get('name'))
@@ -44,8 +51,11 @@ const roleCollectionsResource = {
44
51
  usingConfig,
45
52
  exists,
46
53
  };
47
- })
48
- .sort((a, b) => (a.name > b.name ? 1 : -1));
54
+ }),
55
+ page: Number(page),
56
+ pageSize: Number(pageSize),
57
+ totalPage: totalPage(count, pageSize),
58
+ };
49
59
 
50
60
  await next();
51
61
  },