@opengis/fastify-table 1.4.70 → 1.4.71
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.
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
config, applyHook, getTemplate, pgClients, getAccess, setToken, getSelectMeta,
|
|
2
|
+
config, applyHook, getTemplate, pgClients, getAccess, setToken, getSelectMeta, getToken,
|
|
3
3
|
} from '../../../../utils.js';
|
|
4
4
|
|
|
5
5
|
import getEditData from '../../crud/controllers/table.js';
|
|
@@ -29,13 +29,17 @@ export default async function getForm({
|
|
|
29
29
|
return reply.status(hookData?.status).send(hookData?.message);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const
|
|
32
|
+
const tokenData = await getToken({ token: params.name, uid: user?.uid, json: 1 }) || {};
|
|
33
|
+
|
|
34
|
+
const table = tokenData?.table || hookData?.table || params.name;
|
|
35
|
+
|
|
36
|
+
const { form } = await getTemplate('table', table) || {};
|
|
33
37
|
|
|
34
38
|
if (!form) {
|
|
35
39
|
return reply.status(404).send('form not found');
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
const { actions = [] } = await getAccess({ table
|
|
42
|
+
const { actions = [] } = await getAccess({ table, form, user }, pg) || {};
|
|
39
43
|
|
|
40
44
|
const loadTemplate = form ? await getTemplate('form', form) : null;
|
|
41
45
|
|
|
@@ -56,13 +60,13 @@ export default async function getForm({
|
|
|
56
60
|
const res = { mode: 'form', time: 0, schema };
|
|
57
61
|
|
|
58
62
|
if (user.uid) {
|
|
59
|
-
if (!actions.includes('add') && !config.local) {
|
|
63
|
+
if (!actions.includes('add') && !config.local && config.env !== 'test') {
|
|
60
64
|
return reply.status(403).send('access restricted: actions');
|
|
61
65
|
}
|
|
62
66
|
const addTokens = setToken({
|
|
63
67
|
ids: [
|
|
64
68
|
JSON.stringify({
|
|
65
|
-
table
|
|
69
|
+
table,
|
|
66
70
|
form,
|
|
67
71
|
})],
|
|
68
72
|
uid: user.uid,
|
|
@@ -71,17 +75,17 @@ export default async function getForm({
|
|
|
71
75
|
Object.assign(res, { token: addTokens[0], mode: 'add' });
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
if (edit && user.uid) {
|
|
75
|
-
if (!actions.includes('edit') && !config.local) {
|
|
78
|
+
if ((edit || tokenData?.id) && user.uid) {
|
|
79
|
+
if (!actions.includes('edit') && !config.local && config.env !== 'test') {
|
|
76
80
|
return reply.status(403).send('access restricted: actions');
|
|
77
81
|
}
|
|
78
82
|
const editTokens = setToken({
|
|
79
|
-
ids: [JSON.stringify({ id: edit
|
|
83
|
+
ids: [JSON.stringify({ id: edit || tokenData?.id, table, form })],
|
|
80
84
|
uid: user.uid,
|
|
81
85
|
array: 1,
|
|
82
86
|
});
|
|
83
87
|
const data = await getEditData({
|
|
84
|
-
pg, params: { table:
|
|
88
|
+
pg, params: { table, id: edit || tokenData?.id }, user,
|
|
85
89
|
}, reply, true);
|
|
86
90
|
Object.assign(res, { token: editTokens[0], data, mode: 'edit' });
|
|
87
91
|
}
|