@opengis/fastify-table 2.0.52 → 2.0.54

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 +1 @@
1
- {"version":3,"file":"access.group.post.d.ts","sourceRoot":"","sources":["../../../../../server/routes/access/controllers/access.group.post.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAKzD,wBAA8B,eAAe,CAC3C,EACE,EAAqB,EACrB,MAAM,EACN,IAAS,EACT,IAAS,EACT,QAAQ,GACT,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB,EACD,KAAK,EAAE,YAAY;;;GAiFpB"}
1
+ {"version":3,"file":"access.group.post.d.ts","sourceRoot":"","sources":["../../../../../server/routes/access/controllers/access.group.post.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5C,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAKzD,wBAA8B,eAAe,CAC3C,EACE,EAAqB,EACrB,MAAM,EACN,IAAS,EACT,IAAS,EACT,QAAQ,GACT,EAAE;IACD,EAAE,EAAE,UAAU,CAAC;IACf,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC1B,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB,EACD,KAAK,EAAE,YAAY;;;GA4FpB"}
@@ -21,12 +21,14 @@ export default async function accessGroupPost({ pg = pgClients.client, params, u
21
21
  if (routes?.length) {
22
22
  const routesDB = await pg
23
23
  .query('select array_agg(route_id) as "routesDB" from admin.routes where enabled')
24
- .then((res1) => res1.rows?.[0]?.routesDB || []);
24
+ .then((el) => el.rows?.[0]?.routesDB || []);
25
25
  await pg.query("delete from admin.role_access where role_id=$1;", [id]);
26
- const q = "insert into admin.role_access(role_id,route_id,actions) values ($1,$2,$3)";
27
26
  await Promise.all(routes
28
- .filter((el) => routesDB?.includes?.(el.path) && el.actions)
29
- .map((el) => pg.query(q, [id, el.path, el.actions])));
27
+ .filter((el) => !routesDB?.includes(el.path))
28
+ .map((el) => pg.query("insert into admin.routes(route_id) values($1)", [el.path])));
29
+ await Promise.all(routes
30
+ .filter((el) => /*routesDB?.includes?.(el.path) && */ el.actions)
31
+ .map((el) => pg.query("insert into admin.role_access(role_id,route_id,actions) values ($1,$2,$3)", [id, el.path, el.actions])));
30
32
  const { rows } = await pg.query(`select a.route_id as path, b.actions as actions from admin.routes a
31
33
  left join admin.role_access b on a.route_id=b.route_id
32
34
  where b.role_id=$1`, [id]);
@@ -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.52",
3
+ "version": "2.0.54",
4
4
  "type": "module",
5
5
  "description": "core-plugins",
6
6
  "keywords": [