@opengis/admin 0.2.6 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengis/admin",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "This project Softpro Admin",
5
5
  "main": "dist/admin.js",
6
6
  "type": "module",
@@ -24,5 +24,6 @@ export default async function route() {
24
24
  handlebars.registerHelper('badge', badge);
25
25
  handlebars.registerHelper('contentList', contentList);
26
26
  handlebarsSync.registerHelper('ifCond', ifCond);
27
+ handlebarsSync.registerHelper('button', buttonHelper);
27
28
  handlebars.registerHelper('ifCond', ifCond);
28
29
  }
@@ -13,6 +13,12 @@ export default async function plugin(fastify) {
13
13
  const user1 = config?.auth?.disable || process.env.NODE_ENV !== 'admin' ? { uid: '1' } : null;
14
14
  await initPG(client);
15
15
 
16
+ addHook('preForm', async ({ form, user }) => {
17
+ if (!user?.uid) return null;
18
+ const opt = await getToken({ mode: 'w', token: form, uid: user.uid, json: 1 });
19
+ return opt;
20
+ });
21
+
16
22
  fastify.addHook('onListen', async () => {
17
23
  const json = await getMenu({ user: { uid: 1 } });
18
24
  // insert interface list to db (user access management)
@@ -1,4 +1,4 @@
1
- import { config, applyHook, getTemplate, getToken } from "@opengis/fastify-table/utils.js";
1
+ import { config, applyHook, getTemplate, getToken, setToken } from "@opengis/fastify-table/utils.js";
2
2
  // import { getToken } from "../../../../../fastify-table/utils.js";
3
3
 
4
4
  export default async function getTemplateApi(req) {
@@ -22,6 +22,19 @@ export default async function getTemplateApi(req) {
22
22
  ) {
23
23
  return `access restricted ${name}`;
24
24
  }
25
+ if (type === 'form' && user?.uid) {
26
+ const schema = data.schema || data;
27
+ Object.keys(schema || {}).filter((key) => schema?.[key]?.add).map((key) => {
28
+ const { add } = schema[key];
29
+ Object.assign(add, { table: add.table || add.model }); // support old forms w/ model key
30
+ const [token] = setToken({
31
+ ids: [JSON.stringify(add)],
32
+ uid: user.uid,
33
+ array: 1,
34
+ });
35
+ Object.assign(schema[key].add, { token, api: `${config.prefix || '/api'}/table/${token}` });
36
+ });
37
+ }
25
38
  await applyHook('afterTemplate', { name, type, data, user });
26
39
  if (tokenData.obj) {
27
40
  const obj = tokenData.obj.split('#').reduce((p, el) => ({ ...p, [el.split('=')[0]]: el.split('=')[1] }), {})