@opengis/admin 0.3.7 → 0.3.9

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.
@@ -1,10 +1,12 @@
1
- import { config, applyHook, getTemplate, getToken, setToken } from "@opengis/fastify-table/utils.js";
1
+ import { config, applyHook, getTemplate, getToken, setToken, handlebarsSync } from "@opengis/fastify-table/utils.js";
2
2
 
3
- function formatSchema(schema, user) {
3
+ function formatSchema(schema, user, opt) {
4
4
  function parseDataTables(obj) {
5
5
  if (obj?.add) {
6
+ const obj1 = obj.add?.obj?.includes('{{') && opt ? handlebarsSync.compile(obj.add.obj)(opt) : obj.add?.obj;
7
+ if (obj.add?.obj) obj.add.obj = obj1;
6
8
  const [token] = setToken({
7
- ids: [JSON.stringify({ ... obj.add, table: obj.add?.table || obj.add?.model })],
9
+ ids: [JSON.stringify({ ...obj.add, table: obj.add?.table || obj.add?.model })],
8
10
  uid: user.uid,
9
11
  array: 1,
10
12
  });
@@ -18,33 +20,26 @@ function formatSchema(schema, user) {
18
20
 
19
21
  export default async function getTemplateApi(req) {
20
22
  const { user } = req?.session?.passport || {};
21
- const { params = {}, session = {} } = req;
23
+ const { params = {} } = req;
22
24
  const { type, name } = params;
23
25
 
24
26
  const tokenData = await getToken({ token: name, uid: user?.uid, json: 1 }) || {};
25
27
 
26
28
  const hookData = await applyHook('preTemplate', { name: tokenData.name || name, type, user });
27
- if (hookData?.message && hookData?.status) {
28
- return hookData;
29
- }
29
+ if (hookData?.message && hookData?.status) return hookData;
30
30
 
31
31
  const data = await getTemplate(type, hookData?.name || tokenData.form || name);
32
- if (!['interface', 'table'].includes(type)
33
- && (!data?.public || !data?.ispublic)
34
- && !config?.auth?.disable
35
- && !session.passport?.user?.uid
36
- && false
37
- ) {
38
- return `access restricted ${name}`;
32
+
33
+ if (tokenData.obj) {
34
+ const obj = tokenData.obj.split('#').reduce((p, el) => ({ ...p, [el.split('=')[0]]: el.split('=')[1] }), {})
35
+ Object.assign(data, { obj });
39
36
  }
37
+
40
38
  if (type === 'form' && user?.uid) {
41
39
  const schema = data.schema || data;
42
- formatSchema(schema, user);
40
+ formatSchema(schema, user, data.obj);
43
41
  }
42
+
44
43
  await applyHook('afterTemplate', { name, type, data, user });
45
- if (tokenData.obj) {
46
- const obj = tokenData.obj.split('#').reduce((p, el) => ({ ...p, [el.split('=')[0]]: el.split('=')[1] }), {})
47
- Object.assign(data, { obj });
48
- }
49
44
  return data?.html || data || `template not found "${name}"`;
50
45
  }