@opengis/fastify-table 2.5.16 → 2.5.17
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.
|
@@ -13,7 +13,7 @@ export default function checkPolicy(req, jwt) {
|
|
|
13
13
|
const { role, referer, policy = [], } = (routeOptions?.config || {});
|
|
14
14
|
// role=admin|regular
|
|
15
15
|
const isRole = (role && (!user?.user_type || !role?.includes?.(user?.user_type))) ||
|
|
16
|
-
(policy.includes("admin") && user?.user_type
|
|
16
|
+
(policy.includes("admin") && !user?.user_type?.includes?.("admin"));
|
|
17
17
|
const allowExtPublic = [".png", ".jpg", ".svg"];
|
|
18
18
|
const ext = path.toLowerCase().substr(-4);
|
|
19
19
|
const isPublic = Array.isArray(policy)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/controllers/table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAqB5C,wBAA8B,QAAQ,CACpC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../../../server/routes/crud/controllers/table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAqB5C,wBAA8B,QAAQ,CACpC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,YAAY,EACnB,MAAM,EAAE,GAAG,gBAoQZ"}
|
|
@@ -47,11 +47,11 @@ export default async function tableAPI(req, reply, called) {
|
|
|
47
47
|
const table = loadTable?.table || table1;
|
|
48
48
|
const form = loadTable?.form || form1;
|
|
49
49
|
const id = hookData?.id || tokenData?.id || params.id;
|
|
50
|
-
if (tokenData && !
|
|
50
|
+
if (tokenData && !table) {
|
|
51
51
|
throw ForbiddenError("invalid token");
|
|
52
52
|
}
|
|
53
|
-
if (!table
|
|
54
|
-
throw BadRequestError("not enough params: table
|
|
53
|
+
if (!table) {
|
|
54
|
+
throw BadRequestError("not enough params: table");
|
|
55
55
|
}
|
|
56
56
|
const { actions = [], query: accessQuery, message: accessMessage, } = (await getAccess({
|
|
57
57
|
resource,
|
|
@@ -135,10 +135,12 @@ export default async function tableAPI(req, reply, called) {
|
|
|
135
135
|
.join(";");
|
|
136
136
|
return `${q};${extraQ || ""}`.replace(/\$1/g, `'${id}'`);
|
|
137
137
|
}
|
|
138
|
-
const data =
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
138
|
+
const data = id
|
|
139
|
+
? await pg
|
|
140
|
+
.query(q.replace(/{{uid}}/, user?.uid), [id])
|
|
141
|
+
.then((el) => el.rows[0])
|
|
142
|
+
: null;
|
|
143
|
+
if (id && !data) {
|
|
142
144
|
throw NotFoundError(`object not found: ${id}`);
|
|
143
145
|
}
|
|
144
146
|
Object.keys(schema)
|
|
@@ -148,7 +150,7 @@ export default async function tableAPI(req, reply, called) {
|
|
|
148
150
|
data[key] = null;
|
|
149
151
|
}
|
|
150
152
|
});
|
|
151
|
-
if (extraKeys?.length) {
|
|
153
|
+
if (id && extraKeys?.length) {
|
|
152
154
|
await Promise.all(extraKeys?.map(async (key) => {
|
|
153
155
|
const { colModel, table: extraTable, parent_id: parentId, } = schema[key];
|
|
154
156
|
const colModel1 = Array.isArray(colModel)
|
|
@@ -167,7 +169,8 @@ export default async function tableAPI(req, reply, called) {
|
|
|
167
169
|
if (user?.uid &&
|
|
168
170
|
!config.security?.disableToken &&
|
|
169
171
|
actions.includes("edit") &&
|
|
170
|
-
!called
|
|
172
|
+
!called &&
|
|
173
|
+
id) {
|
|
171
174
|
data.token = tokenData?.table
|
|
172
175
|
? params.table
|
|
173
176
|
: setToken({
|
|
@@ -176,7 +179,9 @@ export default async function tableAPI(req, reply, called) {
|
|
|
176
179
|
array: 1,
|
|
177
180
|
})?.[0];
|
|
178
181
|
}
|
|
179
|
-
|
|
182
|
+
if (id) {
|
|
183
|
+
await extraDataGet({ rows: [data], table, form }, pg);
|
|
184
|
+
}
|
|
180
185
|
const res = await applyHook("afterTable", {
|
|
181
186
|
pg,
|
|
182
187
|
table,
|