@opengis/fastify-table 2.0.51 → 2.0.53

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.
@@ -82,3 +82,19 @@ else
82
82
  end if;
83
83
 
84
84
  end $$
85
+
86
+ CREATE OR REPLACE FUNCTION array_intersect(
87
+ anyarray,
88
+ anyarray)
89
+ RETURNS anyarray
90
+ LANGUAGE 'sql'
91
+ COST 100
92
+ VOLATILE PARALLEL UNSAFE
93
+ AS $BODY$
94
+
95
+ SELECT ARRAY(
96
+ SELECT UNNEST($1)
97
+ INTERSECT
98
+ SELECT UNNEST($2)
99
+ );
100
+ $BODY$;
@@ -1,2 +1,2 @@
1
- export default function getSelect(name: any, pg?: any): Promise<any>;
1
+ export default function getSelect(name: any, pg?: any, nocache?: boolean): Promise<any>;
2
2
  //# sourceMappingURL=getSelect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getSelect.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/table/funcs/getSelect.ts"],"names":[],"mappings":"AAYA,wBAA8B,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,MAAmB,gBA6BvE"}
1
+ {"version":3,"file":"getSelect.d.ts","sourceRoot":"","sources":["../../../../../server/plugins/table/funcs/getSelect.ts"],"names":[],"mappings":"AAYA,wBAA8B,SAAS,CACrC,IAAI,EAAE,GAAG,EACT,EAAE,MAAmB,EACrB,OAAO,UAAQ,gBAgChB"}
@@ -7,9 +7,10 @@ const sqls = {
7
7
  json: `select json_agg(json_build_object('id', code, 'text', name, 'icon', icon, 'color', color)) as data from admin.user_cls where parent=$1
8
8
  union all select json_agg(json_build_object('id', code, 'text', name, 'icon', icon, 'color', color)) as data from admin.cls where parent=$1`,
9
9
  };
10
- export default async function getSelect(name, pg = pgClients.client) {
11
- if (loadCls[name] && !config.local)
10
+ export default async function getSelect(name, pg = pgClients.client, nocache = false) {
11
+ if (loadCls[name] && !config.local && !nocache) {
12
12
  return loadCls[name];
13
+ }
13
14
  const clsDataGIT = await getTemplate(["cls", "select"], name);
14
15
  const { type } = pg.pk?.["admin.user_cls"]
15
16
  ? await pg
@@ -8,7 +8,7 @@ const selectMeta = {};
8
8
  export default async function getSelectMeta({ name, pg = pgClients.client, nocache, parent, }) {
9
9
  if (selectMeta[name] && !nocache)
10
10
  return selectMeta[name];
11
- const cls = await getSelect(name, pg);
11
+ const cls = await getSelect(name, pg, nocache);
12
12
  const db = typeof cls?.db === "string" ? { database: cls.db } : cls?.db;
13
13
  const pg1 = cls?.db ? getPG(db) : pg;
14
14
  if (!pg1?.pk)
@@ -1 +1 @@
1
- {"version":3,"file":"getUserInfo.d.ts","sourceRoot":"","sources":["../../../../../../server/routes/auth/controllers/core/getUserInfo.ts"],"names":[],"mappings":"AAMA,wBAA8B,WAAW,CAAC,GAAG,EAAE,GAAG,eAgDjD"}
1
+ {"version":3,"file":"getUserInfo.d.ts","sourceRoot":"","sources":["../../../../../../server/routes/auth/controllers/core/getUserInfo.ts"],"names":[],"mappings":"AAiCA,wBAA8B,WAAW,CAAC,GAAG,EAAE,GAAG,eAyDjD"}
@@ -2,6 +2,32 @@ import config from "../../../../../config.js";
2
2
  import { applyHook } from "../../../../../utils.js";
3
3
  import getRedis from "../../../../plugins/redis/funcs/getRedis.js";
4
4
  const rclient2 = getRedis({ db: 2 });
5
+ const q = `select
6
+
7
+ a.route_id as id,
8
+ /* coalesce(d.actions, array['view', 'edit','add','del']) as role_actions,
9
+ coalesce(b.actions, array['view']) as interface_actions, */
10
+ array_intersect(coalesce(b.actions, array['view']), coalesce(d.actions, array['view', 'edit','add','del'])) as actions,
11
+ b.scope,
12
+ c.role_id,
13
+ c.name as role_name
14
+
15
+ from admin.routes a
16
+ left join admin.role_access b on
17
+ a.route_id=b.route_id
18
+ left join admin.roles c on
19
+ b.role_id=c.role_id
20
+ and c.enabled
21
+ left join admin.user_roles d on
22
+ c.role_id=d.role_id
23
+ and (
24
+ case when
25
+ d.expiration is not null
26
+ then d.expiration > CURRENT_DATE
27
+ else 1=1
28
+ end
29
+ )
30
+ where $1 in (b.user_uid, d.user_uid)`;
5
31
  export default async function getUserInfo(req) {
6
32
  const payload = {
7
33
  sessionID: req.session?.sessionId,
@@ -25,12 +51,19 @@ export default async function getUserInfo(req) {
25
51
  p[k1][k2] = val;
26
52
  return p;
27
53
  }, {});
54
+ const access = req.pg?.pk?.["admin.role_access"] &&
55
+ req.pg?.pk?.["admin.user_roles"] &&
56
+ req.pg?.pk?.["admin.users"] &&
57
+ req.user?.uid
58
+ ? await req.pg.query(q, [req.user.uid]).then((el) => el.rows || [])
59
+ : [];
28
60
  Object.assign(payload, {
29
61
  user: userInfo,
30
62
  settings,
31
63
  session: !config.auth?.debug
32
64
  ? { ...req.session, passport: null }
33
65
  : req.session,
66
+ access,
34
67
  });
35
68
  const hookData = await applyHook("afterUser", { payload });
36
69
  return hookData || payload;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/fastify-table",
3
- "version": "2.0.51",
3
+ "version": "2.0.53",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [