@opengis/admin 0.1.98 → 0.1.99

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. package/dist/{IconChevronDown-irxwDmQp.js → IconChevronDown-CHEXfG3v.js} +1 -1
  2. package/dist/{add-page-UtwEANeW.js → add-page-DGnHyxhv.js} +1 -1
  3. package/dist/{admin-interface-PJfd31TQ.js → admin-interface-D2IezdVx.js} +2 -2
  4. package/dist/{admin-view-BuVQ8ziq.js → admin-view-CtPrS-pT.js} +2 -2
  5. package/dist/admin.js +1 -1
  6. package/dist/admin.umd.cjs +51 -51
  7. package/dist/{card-view-BpcpqR_U.js → card-view-WP8gH2Ul.js} +1 -1
  8. package/dist/{edit-page-Bd6VW9hb.js → edit-page-0YrQy_VE.js} +1 -1
  9. package/dist/{import-file-eH-_Imyb.js → import-file-DoWm0VXP.js} +4952 -4894
  10. package/module/settings/card/admin.accounts.table/index.yml +8 -0
  11. package/module/settings/card/admin.accounts.table/rules.hbs +19 -0
  12. package/module/settings/card/admin.accounts.table/users.hbs +14 -0
  13. package/module/settings/card/admin.roles.table/access.hbs +3 -24
  14. package/module/settings/card/admin.roles.table/general_info.hbs +1 -17
  15. package/module/settings/card/admin.roles.table/index.yml +4 -1
  16. package/module/settings/card/admin.roles.table/users.hbs +6 -27
  17. package/module/settings/card/admin.routes.table/general_info.hbs +14 -41
  18. package/module/settings/card/admin.routes.table/groups.hbs +12 -0
  19. package/module/settings/card/admin.routes.table/index.yml +3 -0
  20. package/module/settings/card/admin.routes.table/users.hbs +16 -33
  21. package/module/settings/card/admin.users.table/context.hbs +15 -0
  22. package/module/settings/card/admin.users.table/general_info.hbs +13 -26
  23. package/module/settings/card/admin.users.table/index.yml +17 -7
  24. package/module/settings/card/admin.users.table/last_login.hbs +10 -0
  25. package/module/settings/card/admin.users.table/logs.hbs +11 -31
  26. package/module/settings/card/admin.users.table/routes.hbs +8 -0
  27. package/module/settings/card/admin.users.table/user_roles.hbs +13 -25
  28. package/module/settings/form/admin.accounts.form.json +13 -0
  29. package/module/settings/form/admin.rules.form.json +31 -0
  30. package/module/settings/form/admin.user_roles.form.json +0 -8
  31. package/module/settings/form/admin.user_roles_card.form.json +14 -0
  32. package/module/settings/form/admin.users.form.json +2 -2
  33. package/module/settings/form/context.account_grants.form.json +24 -0
  34. package/module/settings/form/context.account_users.form.json +12 -0
  35. package/module/settings/menu.json +24 -0
  36. package/module/settings/select/core.accounts.sql +1 -0
  37. package/module/settings/select/core.roles.sql +1 -1
  38. package/module/settings/select/core.rules.sql +1 -0
  39. package/module/settings/select/core.user_uid.sql +0 -1
  40. package/module/settings/table/admin.accounts.table.json +42 -0
  41. package/module/settings/table/admin.roles.table.json +1 -1
  42. package/module/settings/table/admin.routes.table.json +9 -4
  43. package/module/settings/table/admin.rules.table.json +77 -0
  44. package/module/settings/table/admin.users.table.json +17 -6
  45. package/module/settings/table/context.account_grants.table.json +68 -0
  46. package/module/settings/table/context.account_users.table.json +38 -0
  47. package/package.json +4 -3
  48. package/server/helpers/core/select.js +4 -6
  49. package/server/helpers/list/tableList.js +9 -6
  50. package/server/routes/access/controllers/access.group.js +1 -1
  51. package/server/routes/access/controllers/access.group.post.js +4 -4
  52. package/server/routes/data/controllers/cardData.js +11 -0
  53. package/server/routes/data/controllers/tableData.js +13 -4
  54. package/server/routes/menu/controllers/getMenu.js +12 -25
  55. package/module/settings/select/core.roles.json +0 -3
@@ -12,6 +12,12 @@
12
12
  "ua": "Користувачі",
13
13
  "en": "Users"
14
14
  },
15
+ {
16
+ "path": "admin.accounts",
17
+ "table": "admin.accounts.table",
18
+ "ua": "Організації",
19
+ "en": "Accounts"
20
+ },
15
21
  {
16
22
  "path": "admin.roles",
17
23
  "table": "admin.roles.table",
@@ -23,6 +29,12 @@
23
29
  "table": "admin.routes.table",
24
30
  "ua": "Інтерфейси",
25
31
  "en": "Routes"
32
+ },
33
+ {
34
+ "path": "admin.rules",
35
+ "table": "admin.rules.table",
36
+ "ua": "Повноваження",
37
+ "en": "Rules"
26
38
  }
27
39
  ]
28
40
  },
@@ -55,6 +67,18 @@
55
67
  "table": "admin.custom_column.table",
56
68
  "ua": "Налаштування користувацьких колонок",
57
69
  "en": "User custom column settings"
70
+ },
71
+ {
72
+ "path": "context.account_grants",
73
+ "table": "context.account_grants.table",
74
+ "ua": "Налаштування організацій",
75
+ "en": "Account settings"
76
+ },
77
+ {
78
+ "path": "context.account_users",
79
+ "table": "context.account_users.table",
80
+ "ua": "Користувачі/Організації",
81
+ "en": "Contact/Account"
58
82
  }
59
83
  ]
60
84
  }
@@ -0,0 +1 @@
1
+ select account_id, account_name from admin.accounts order by account_name
@@ -1 +1 @@
1
- select role_id, name from admin.roles order by name
1
+ select role_id, name from admin.roles
@@ -0,0 +1 @@
1
+ select rule_id, rule_name from admin.rules
@@ -1,2 +1 @@
1
1
  select uid, coalesce(coalesce(sur_name,'')||coalesce(' '||user_name,'') ||coalesce(' '||father_name,''),login) as text from admin.users
2
- order by coalesce(coalesce(sur_name,'')||coalesce(' '||user_name,'') ||coalesce(' '||father_name,''),login)
@@ -0,0 +1,42 @@
1
+ {
2
+ "ua": "Організації",
3
+ "key": "account_id",
4
+ "form": "admin.accounts.form",
5
+ "table": "admin.accounts",
6
+ "order": "cdate desc",
7
+ "access": "admin",
8
+ "meta": {
9
+ "search": "account_name"
10
+ },
11
+ "actions": ["add", "edit", "del"],
12
+ "columns": [
13
+ {
14
+ "name": "account_name",
15
+ "format": "Text",
16
+ "ua": "Назва"
17
+ },
18
+ {
19
+ "name": "description",
20
+ "format": "Text",
21
+ "ua": "Опис"
22
+ },
23
+ {
24
+ "name": "uid",
25
+ "format": "Select",
26
+ "data": "core.user_uid",
27
+ "ua": "Хто створив"
28
+ },
29
+ {
30
+ "name": "cdate",
31
+ "format": "Date",
32
+ "ua": "Дата створення"
33
+ }
34
+ ],
35
+ "filters": [
36
+ {
37
+ "ua": "Назва",
38
+ "name": "account_name",
39
+ "type": "text"
40
+ }
41
+ ]
42
+ }
@@ -15,7 +15,7 @@
15
15
  "name": "user_count"
16
16
  },
17
17
  {
18
- "sql": "select count(route_id) as routes_count from admin.access where role_id=t.role_id",
18
+ "sql": "select count(route_id) as routes_count from admin.role_access where role_id=t.role_id",
19
19
  "name": "routes_count"
20
20
  }
21
21
  ],
@@ -6,12 +6,12 @@
6
6
  "access": "admin",
7
7
  "sql": [
8
8
  {
9
- "sql1": "select count(user_uid) as user_count from admin.access where route_id=t.route_id",
10
- "name": "user_count"
9
+ "sql": "select count(role_id) as roles_count, array_agg(role_id) as role_ids from admin.role_access where route_id=t.route_id",
10
+ "name": "r"
11
11
  },
12
12
  {
13
- "sql": "select count(role_id) as roles_count from admin.access where route_id=t.route_id",
14
- "name": "roles_count"
13
+ "sql": "select count(user_uid) as user_count from admin.user_roles where role_id= any(r.role_ids)",
14
+ "name": "u"
15
15
  }
16
16
  ],
17
17
  "columns": [
@@ -30,6 +30,11 @@
30
30
  "format": "text",
31
31
  "title": "Кількість груп"
32
32
  },
33
+ {
34
+ "name": "user_count",
35
+ "format": "text",
36
+ "title": "Кількість користувачів"
37
+ },
33
38
  {
34
39
  "name": "enabled",
35
40
  "format": "Check",
@@ -0,0 +1,77 @@
1
+ {
2
+ "ua": "Повноваження",
3
+ "key": "rule_id",
4
+ "form": "admin.rules.form",
5
+ "table": "admin.rules",
6
+ "access": "admin",
7
+ "meta": {
8
+ "search": "rule_name"
9
+ },
10
+ "actions": [
11
+ "add",
12
+ "edit",
13
+ "del"
14
+ ],
15
+ "columns": [
16
+ {
17
+ "name": "rule_name",
18
+ "format": "Text",
19
+ "ua": "Назва"
20
+ },
21
+ {
22
+ "name": "attr",
23
+ "format": "Text",
24
+ "ua": "Колонка"
25
+ },
26
+ {
27
+ "name": "rule_type",
28
+ "format": "text",
29
+ "data": "core.rule_type",
30
+ "ua": "Тип повноваження"
31
+ },
32
+ {
33
+ "name": "rule_query",
34
+ "format": "Text",
35
+ "ua": "Запит"
36
+ },
37
+ {
38
+ "name": "CLS",
39
+ "format": "Text",
40
+ "ua": "CLS"
41
+ },
42
+ {
43
+ "name": "routes",
44
+ "format": "Text",
45
+ "ua": "Роути"
46
+ },
47
+ {
48
+ "name": "uid",
49
+ "format": "Select",
50
+ "data": "core.user_uid",
51
+ "ua": "Хто створив"
52
+ },
53
+ {
54
+ "name": "cdate",
55
+ "format": "Date",
56
+ "ua": "Дата створення"
57
+ }
58
+ ],
59
+ "filters": [
60
+ {
61
+ "ua": "Назва",
62
+ "name": "name",
63
+ "type": "text"
64
+ },
65
+ {
66
+ "ua": "Тип повноваження",
67
+ "name": "type",
68
+ "type": "text"
69
+ },
70
+ {
71
+ "ua": "Хто створив",
72
+ "name": "uid",
73
+ "type": "select",
74
+ "data": "core.user_uid"
75
+ }
76
+ ]
77
+ }
@@ -15,17 +15,17 @@
15
15
  "search": "sur_name,user_name,uid,father_name,email,phone,login"
16
16
  },
17
17
  "sql": [
18
- {
19
- "sql": "select count(*) as group_count from admin.user_roles where user_uid=t.uid and (case when expiration is not null then expiration > CURRENT_DATE else 1=1 end)",
20
- "name": "group_count_sql"
21
- },
22
18
  {
23
19
  "sql": "select concat(user_name, ' ', sur_name, ' ', father_name, ' ') as full_name",
24
20
  "name": "full_name_sql"
25
21
  },
26
22
  {
27
- "sql": "select string_agg(name,',') as groups from admin.roles where role_id in (select role_id from admin.user_roles where user_uid=t.uid)",
28
- "name": "group_list_sql"
23
+ "sql": "select string_agg(name,',') as groups,count(*) as group_count, array_agg(role_id) as role_ids from admin.roles r where role_id in (select role_id from admin.user_roles where user_uid=t.uid)",
24
+ "name": "gr"
25
+ },
26
+ {
27
+ "sql": "select count(*) as route_count from admin.role_access r where role_id = any(gr.role_ids)",
28
+ "name": "routes"
29
29
  }
30
30
  ],
31
31
  "columns": [
@@ -37,6 +37,12 @@
37
37
  {
38
38
  "ua": "Логін",
39
39
  "name": "login",
40
+ "hidden": true,
41
+ "format": "text"
42
+ },
43
+ {
44
+ "ua": "Права",
45
+ "name": "user_type",
40
46
  "format": "text"
41
47
  },
42
48
  {
@@ -56,6 +62,11 @@
56
62
  "ua": "Кількість груп",
57
63
  "format": "text"
58
64
  },
65
+ {
66
+ "name": "route_count",
67
+ "ua": "Кількість Інтерфейсів",
68
+ "format": "text"
69
+ },
59
70
  {
60
71
  "name": "groups",
61
72
  "ua": "Групи",
@@ -0,0 +1,68 @@
1
+ {
2
+ "key": "ag_id",
3
+ "ua": "Організації/Права",
4
+ "table": "admin.account_grants",
5
+ "form": "context.account_grants.form",
6
+ "order": "cdate desc",
7
+ "access": "admin",
8
+ "actions": [
9
+ "add",
10
+ "edit",
11
+ "del"
12
+ ],
13
+ "columns": [
14
+ {
15
+ "name": "account_id",
16
+ "ua": "id Організації",
17
+ "format": "Select",
18
+ "data": "core.accounts"
19
+ },
20
+ {
21
+ "name": "rule_id",
22
+ "ua": "id Правила",
23
+ "data": "core.rules",
24
+ "format": "Select"
25
+ },
26
+ {
27
+ "name": "routes",
28
+ "ua": "Роути",
29
+ "format": "Text"
30
+ },
31
+ {
32
+ "name": "values",
33
+ "ua": "Значення",
34
+ "format": "Text"
35
+ },
36
+ {
37
+ "name": "grants_doc_id",
38
+ "ua": "id Документу",
39
+ "format": "Text"
40
+ },
41
+ {
42
+ "name": "grant_scan",
43
+ "ua": "id Скану",
44
+ "format": "Text"
45
+ },
46
+ {
47
+ "name": "expire_date",
48
+ "ua": "Дата закінчення дії дозволу",
49
+ "format": "Date"
50
+ },
51
+ {
52
+ "name": "actions",
53
+ "ua": "Дії",
54
+ "format": "Text"
55
+ },
56
+ {
57
+ "name": "uid",
58
+ "format": "Select",
59
+ "data": "core.user_uid",
60
+ "ua": "Хто створив"
61
+ },
62
+ {
63
+ "name": "cdate",
64
+ "ua": "Дата створення",
65
+ "format": "Dat"
66
+ }
67
+ ]
68
+ }
@@ -0,0 +1,38 @@
1
+ {
2
+ "key": "au_id",
3
+ "ua": "Користувачі/Організації",
4
+ "table": "admin.account_users",
5
+ "form": "context.account_users.form",
6
+ "order": "cdate desc",
7
+ "access": "admin",
8
+ "actions": [
9
+ "add",
10
+ "edit",
11
+ "del"
12
+ ],
13
+ "columns": [
14
+ {
15
+ "name": "account_id",
16
+ "format": "Select",
17
+ "data": "core.accounts",
18
+ "ua": "id Організації"
19
+ },
20
+ {
21
+ "name": "user_id",
22
+ "format": "Select",
23
+ "data": "core.user_uid",
24
+ "ua": "id Користувача"
25
+ },
26
+ {
27
+ "name": "uid",
28
+ "format": "Select",
29
+ "data": "core.user_uid",
30
+ "ua": "Хто створив"
31
+ },
32
+ {
33
+ "name": "cdate",
34
+ "format": "date",
35
+ "ua": "Дата створення"
36
+ }
37
+ ]
38
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/admin",
3
- "version": "0.1.98",
3
+ "version": "0.1.99",
4
4
  "description": "This project Softpro Admin",
5
5
  "main": "dist/admin.js",
6
6
  "type": "module",
@@ -22,7 +22,8 @@
22
22
  "build-app": "cross-env APP=true vite build",
23
23
  "admin": "cross-env NODE_ENV=admin npm run start",
24
24
  "prod": "cross-env NODE_ENV=production npm run start",
25
- "start": "node --watch-path=server server vite ",
25
+ "debug": "node --watch-path=server server",
26
+ "start": "node server",
26
27
  "docs:dev": "vitepress dev docs",
27
28
  "docs:build": "vitepress build docs",
28
29
  "docs:preview": "vitepress preview docs"
@@ -79,4 +80,4 @@
79
80
  "vitepress-plugin-tabs": "^0.5.0",
80
81
  "vitepress-sidebar": "^1.22.0"
81
82
  }
82
- }
83
+ }
@@ -17,6 +17,7 @@ export default async function select(ids, options) {
17
17
 
18
18
  if (!classifier) return `Не знайдено класифікатор ${data}`;
19
19
 
20
+ const arr = classifier.arr || []
20
21
  if (classifier.sql && typeof classifier.sql === 'string') {
21
22
 
22
23
 
@@ -30,16 +31,13 @@ export default async function select(ids, options) {
30
31
  const values = [idsArray.map(id => String(id))];
31
32
 
32
33
  const { rows } = await pg.query(sql, values);
33
- classifier.arr = rows;
34
+ Object.assign(arr, rows)
34
35
 
35
36
  }
36
-
37
- if (!Array.isArray(classifier?.arr) || !classifier.arr.length || !classifier.arr.every(item => typeof item === 'object' && item !== null)) {
38
- return ids;
39
- }
37
+ if (!arr.length) return idsArray
40
38
 
41
39
  const results = idsArray.map(id => {
42
- const result = classifier.arr.find(el => String(el.id) == String(id));
40
+ const result = arr.find(el => String(el.id) == String(id));
43
41
  return result ? result.text : '';
44
42
  });
45
43
 
@@ -3,12 +3,12 @@ import { handlebarsSync, setToken, handlebars } from '@opengis/fastify-table/uti
3
3
  import button from '../utils/button.js';
4
4
  import buttonDel from '../utils/buttonDel.js';
5
5
 
6
- function format(d, key, data) {
6
+ function format(d, key, data, hash) {
7
7
  if (!key?.includes) return '';
8
8
  if (d === true) return 'так';
9
9
  if (d === false) return 'ні';
10
10
  if (key === 'actions') {
11
- return button(d, 'редагувати') + buttonDel(d)
11
+ return (hash.form ? button(d, 'редагувати') : '') + buttonDel(d)
12
12
  }
13
13
  if (key.includes('{{')) {
14
14
  return handlebarsSync.compile(key)(data);
@@ -25,7 +25,7 @@ export default async function tableList(data, opt) {
25
25
  return noDataText
26
26
  }
27
27
  if (!hash.columns) return 'columns empty'
28
- const keys = hash.columns.split(',').map(el => hash.comma ? el.trim().replace(new RegExp(hash.comma, 'g'), ',') : el.trim()).concat(hash.uid && hash.table && hash.form && !hash.noactions ? ['Дії', 'actions'] : []);
28
+ const keys = hash.columns.split(hash.divider || ',').map(el => hash.comma ? el.trim().replace(new RegExp(hash.comma, 'g'), ',') : el.trim()).concat(hash.uid && hash.table && hash.id && !hash.noactions ? ['Дії', 'actions'] : []);
29
29
 
30
30
  const result = [];
31
31
  result.push('<thead> <tr>');
@@ -36,6 +36,9 @@ export default async function tableList(data, opt) {
36
36
  const name = keys[i];
37
37
 
38
38
  // check hbs
39
+ if (name.includes('{{')) {
40
+ console.log(hash)
41
+ }
39
42
  const nameHBS = name.includes('{{') ? handlebarsSync.compile(name)({ ...data, hash }) : false;
40
43
  // console.log(name, data, nameHBS)
41
44
  skip[name] = name.includes('{{') && !nameHBS;
@@ -50,7 +53,7 @@ export default async function tableList(data, opt) {
50
53
  result.push('</tr></thead>');
51
54
 
52
55
  // body
53
- for (let k = 0; k < data.length; k += 2) {
56
+ for (let k = 0; k < data.length; k += 1) {
54
57
  const row = data[k];
55
58
  result.push('<tbody><tr class="border-t border-gray-200">');
56
59
  const obj = { form: hash.form, table: hash.table, id: row[hash.id] }
@@ -59,13 +62,13 @@ export default async function tableList(data, opt) {
59
62
 
60
63
  const name = keys[i];
61
64
  const key = keys[i + 1];
62
-
65
+ if (!key) continue;
63
66
  if (skip[name]) continue;
64
67
 
65
68
  const tokenData = key == 'actions' ? token : null;
66
69
  const d1 = ['{{format', '{{select', '{{badge', '{{#ifCond'].filter(el => key.includes(el)).length ? await handlebars.compile(key)({ ...row, token, hash }) || '-' : null
67
70
  result.push(`<td >
68
- <div class="px-[20px] py-[12px] text-start font-medium text-[14px] text-black">${d1 || format(tokenData || row[key], key, row)}</div>
71
+ <div class="px-[20px] py-[12px] text-start font-medium text-[14px] text-black">${d1 || format(tokenData || row[key], key, row, hash)}</div>
69
72
  </td>`);
70
73
 
71
74
  }
@@ -18,7 +18,7 @@ export default async function accessGroup({
18
18
  if (check) return check;
19
19
 
20
20
  const { rows: routes = [] } = await pg.query(`select a.route_id as path, b.actions from admin.routes a
21
- left join admin.access b on a.route_id=b.route_id
21
+ left join admin.role_access b on a.route_id=b.route_id
22
22
  where b.role_id=$1`, [params.id]);
23
23
 
24
24
  const { rows: users = [] } = await pg.query(`select user_uid as id, user_name as name, access_granted,
@@ -21,15 +21,15 @@ export default async function accessGroupPost({
21
21
  }
22
22
 
23
23
  if (routes?.length) {
24
- // delete from admin.access where role_id=$1;
25
- await pg.query(`delete from admin.access where role_id=$1;`, [id]);
26
24
 
25
+ await pg.query(`delete from admin.role_access where role_id=$1;`, [id]);
27
26
 
28
- const q = `insert into admin.access(role_id,route_id,actions) values ($1,$2,$3)`;
27
+
28
+ const q = `insert into admin.role_access(role_id,route_id,actions) values ($1,$2,$3)`;
29
29
  await Promise.all(routes.filter(el => el.actions).map(el => pg.query(q, [id, el.path, el.actions])))
30
30
 
31
31
  const { rows } = await pg.query(`select a.route_id as path, b.actions as actions from admin.routes a
32
- left join admin.access b on a.route_id=b.route_id
32
+ left join admin.role_access b on a.route_id=b.route_id
33
33
  where b.role_id=$1`, [id]);
34
34
 
35
35
  if (!users?.length) {
@@ -30,6 +30,17 @@ export default async function getCardData(req) {
30
30
  index.panels?.filter(el => el.items).forEach(el => {
31
31
  el.items = el.items?.filter(el => conditions(el.conditions, rows[0]));
32
32
  })
33
+
34
+ // title, count
35
+ index.panels?.filter(el => el.items).forEach(async el => {
36
+ const filtered = el.items.filter(el => el.count?.toLowerCase?.().includes('select'));
37
+ const data = await Promise.all(filtered.map(el => pg.query(el.count).then(el => el.rows[0] || {})))
38
+ filtered.forEach((el, i) => {
39
+ Object.assign(el, data[i] || {}, data[i].count ? {} : { count: undefined })
40
+ })
41
+ })
42
+
43
+
33
44
  // tokens result
34
45
  const tokens = {};
35
46
  if (index?.tokens && typeof index?.tokens === 'object' && !Array.isArray(index?.tokens)) {
@@ -3,17 +3,26 @@ import { getOpt } from '@opengis/fastify-table/utils.js';
3
3
  // import getData from '../../../../../../npm/fastify-table/server/routes/table/controllers/data.js';
4
4
 
5
5
  export default async function getTableData(req) {
6
- //const time = Date.now();
6
+ const { user } = req
7
7
  const tokenData = await getOpt(req.params.table, req.user?.uid);
8
8
  if (tokenData) {
9
9
  const { rows } = await req.pg.query(`select ${tokenData.columns || '*'} from ${tokenData.table} where ${tokenData.query || 'true'} limit 10`)
10
10
  return { rows }
11
11
  }
12
+
13
+ // Це можна 1 раз на старті
12
14
  const interfaceName = req.headers?.referer?.match(/.*\/([^?]+)/)?.[1];
13
- const { query = '1=1' } = interfaceName ? await req.pg.query(`select query from admin.routes where route_id=$1`, [interfaceName])
14
- .then((res1) => res1.rows?.[0] || {}) : {};
15
+ const { query } = interfaceName ?
16
+ await req.pg.query(`select query from admin.routes where route_id=$1`, [interfaceName])
17
+ .then((res1) => res1.rows?.[0] || {}) : {};
18
+
19
+ // це можна від користувача
20
+ const { rows = [] } = await req.pg.query(`select attr,(select rule_values from admin.account_grants where account_id in (select account_id from admin.account_users where user_uid=$2) and rule_id=r.rule_id limit 1) from admin.rules r where (select route_id from admin.routes where $1 in (alias,table_name)) = any(routes)`, [req.params.table, user.uid]);
21
+
22
+
23
+ const context = rows.filter(el => el.rule_values).map(el => `${el.attr} = any ('{${el.rule_values}}')`).join(' and ')
24
+ req.params.query = [query, context].filter(el => el).join(' and ') || ' true ';
15
25
 
16
- req.params.query = query;
17
26
  const res = await getData(req);
18
27
 
19
28
  return res;
@@ -35,34 +35,21 @@ export default async function adminMenu({ user = {}, session, pg = pgClients.cli
35
35
  const menus = isProduction && menuCache.length ? menuCache : await readMenu();
36
36
 
37
37
  // update user access
38
- if (session && user?.uid) {
39
- const { type, gl = [] } = await pg.query(`select user_type as type, b.gl from admin.users a
40
- left join lateral (
41
- select array_agg(role_id) as gl from admin.user_roles where user_uid=a.uid
42
- )b on 1=1 where uid=$1`, [user.uid]).then(el => el.rows[0] || {});
43
- /* const { interfaces = [] } = await pg.query(`select array_agg(route_id) as interfaces from admin.access
38
+ if (session && user?.uid && user.type !== 'admin') {
39
+ const { type, gl = [], routes = [] } = await pg.query(`select user_type as type, b.gl,routes from admin.users a
40
+ left join lateral ( select array_agg(role_id) as gl from admin.user_roles where user_uid=a.uid)b on 1=1
41
+ left join lateral ( select array_agg(route_id) as routes from admin.role_access where role_id=any(b.gl))r on 1=1
42
+ where uid=$1`, [user.uid]).then(el => el.rows[0] || {});
43
+ /* const { interfaces = [] } = await pg.query(`select array_agg(route_id) as interfaces from admin.role_access
44
44
  where user_uid=$1 or role_id=any($2::text[])`, [user.uid, gl]).then((res) => res.rows?.[0] || {}); */
45
- Object.assign(user, { type, group_list: gl });
45
+
46
+ Object.assign(user, { type, group_list: gl, routes });
46
47
  session?.set?.('passport', { user });
48
+ const userMenus = menus.map(el => (el.menu ? { ...el, menu: el.menu.filter(item => routes.includes(item.path)) } : el))
49
+ return userMenus.filter(el => el.menu?.length || routes.includes(el.path))
47
50
  }
48
- return menus;
49
51
 
50
- if (req) {
51
- const user = req?.session?.passport?.user || {};
52
- const userMenu = await Promise.all(menus.map(async (menu) => {
53
- if (menu?.menu?.length) {
54
- const submenu = await Promise.all(menu.menu?.map(async (submenu) => {
55
- const access = await getAccess({ table: submenu?.table, user });
56
- return { ...submenu, access };
57
- }));
58
- return { ...menu, menu: submenu.filter((e) => e?.access), access: submenu.filter((e) => e?.access?.actions?.includes('get'))?.length };
59
- } else if (menu?.table) {
60
- const access = await getAccess({ table: menu?.table, user });
61
- return { ...menu, access };
62
- }
63
- return menu;
64
- }));
65
- return userMenu.filter((e) => e?.access)?.map((e) => ({ ...e, menu: e?.menu ? e?.menu?.filter((el) => el?.access?.actions?.includes('get')) : undefined }));
66
- }
67
52
  return menus;
53
+
54
+
68
55
  }
@@ -1,3 +0,0 @@
1
- {
2
- "count": 1000
3
- }