@opengis/admin 0.3.21 → 0.3.23
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/dist/{add-page-DsqxZzEq.js → add-page-2cPkdIAC.js} +29 -26
- package/dist/{admin-interface-C8SGlC1N.js → admin-interface-D9Dx7QqK.js} +234 -232
- package/dist/{admin-view-DtdqTUPa.js → admin-view-C_Ecdip-.js} +29 -29
- package/dist/admin.js +1 -1
- package/dist/admin.umd.cjs +88 -88
- package/dist/{card-view-juhvChuX.js → card-view-MuS2Gqq6.js} +3 -3
- package/dist/{edit-page-DB1hlRzp.js → edit-page-Dr397YuE.js} +33 -31
- package/dist/{import-file-BSdaeh6s.js → import-file-CcRnsq1s.js} +23212 -23090
- package/dist/{profile-page-B-RhB5JP.js → profile-page-BrKTAsqO.js} +2 -2
- package/dist/style.css +1 -1
- package/module/settings/card/admin.roles.table/access.hbs +11 -11
- package/module/settings/card/admin.roles.table/general_info.hbs +9 -9
- package/module/settings/card/admin.roles.table/index.yml +22 -22
- package/module/settings/card/admin.roles.table/users.hbs +12 -12
- package/module/settings/card/admin.routes.table/general_info.hbs +13 -13
- package/module/settings/card/admin.routes.table/index.yml +15 -15
- package/module/settings/card/admin.table_properties.table/custom_columns.hbs +22 -22
- package/module/settings/card/admin.table_properties.table/index.yml +12 -12
- package/module/settings/card/admin.table_properties.table/info.hbs +17 -17
- package/module/settings/card/admin.users.table/general_info.hbs +18 -18
- package/module/settings/card/admin.users.table/index.yml +20 -20
- package/module/settings/card/admin.users.table/last_login.hbs +17 -17
- package/module/settings/card/admin.users.table/logs.hbs +16 -16
- package/module/settings/card/admin.users.table/routes.hbs +13 -13
- package/module/settings/card/admin.users.table/user_roles.hbs +35 -35
- package/module/settings/cls/change_type.json +13 -13
- package/module/settings/cls/core.column_type.json +14 -14
- package/module/settings/form/admin.custom_column.form.json +55 -55
- package/module/settings/form/admin.routes.form.json +25 -25
- package/module/settings/form/admin.rules.form.json +30 -30
- package/module/settings/form/admin.table_properties.form.json +19 -19
- package/module/settings/form/admin.user_roles.form.json +24 -24
- package/module/settings/form/admin.users.form.json +177 -177
- package/module/settings/form/admin.users_edit.form.json +145 -145
- package/module/settings/form/context.account_grants.form.json +24 -24
- package/module/settings/form/context.account_users.form.json +12 -12
- package/module/settings/form/user.user_roles.form.json +13 -13
- package/module/settings/menu.json +72 -72
- package/module/settings/table/admin.accounts.table.json +49 -49
- package/module/settings/table/admin.custom_column.table.json +100 -100
- package/module/settings/table/admin.roles.table.json +77 -77
- package/module/settings/table/admin.routes.table.json +73 -73
- package/module/settings/table/admin.rules.table.json +77 -77
- package/module/settings/table/admin.table_properties.table.json +37 -37
- package/module/settings/table/admin.user_roles.table.json +74 -74
- package/module/settings/table/admin.users.table.json +135 -135
- package/module/settings/table/context.account_grants.table.json +88 -88
- package/module/settings/table/context.account_users.table.json +53 -53
- package/module/settings/table/log.table_changes.table.json +100 -100
- package/package.json +102 -102
- package/plugin.js +30 -30
- package/server/helpers/index.js +40 -40
- package/server/helpers/list/descriptionList.js +45 -45
- package/server/helpers/list/tableList.js +82 -82
- package/server/helpers/list/utils/buttonDel.js +12 -12
- package/server/helpers/list/utils/buttonEdit.js +14 -14
- package/server/helpers/utils/buttonAdd.js +6 -6
- package/server/helpers/utils/buttonDel.js +6 -6
- package/server/helpers/utils/buttonEdit.js +5 -5
- package/server/helpers/utils/paddingNumber.js +3 -3
- package/server/plugins/access/funcs/getAdminAccess.js +12 -12
- package/server/plugins/hook.js +276 -275
- package/server/plugins/vite.js +77 -77
- package/server/routes/access/controllers/access.interface.js +33 -33
- package/server/routes/data/controllers/cardData.js +127 -127
- package/server/routes/data/controllers/tableFilter.js +9 -9
- package/server/routes/data/controllers/tableInfo.js +112 -112
- package/server/routes/dblist/controllers/readItems.js +20 -20
- package/server/routes/dblist/controllers/setItem.js +22 -22
- package/server/routes/dblist/index.mjs +18 -18
- package/server/routes/dblist/utils/formatData.js +7 -7
- package/server/routes/menu/controllers/getMenu.js +77 -77
- package/server/routes/menu/controllers/interfaces.js +20 -20
- package/server/routes/menu/index.mjs +7 -7
- package/server/routes/print/controllers/printTemplate.add.js +37 -37
- package/server/routes/print/controllers/printTemplate.delete.js +29 -29
- package/server/routes/print/controllers/printTemplate.edit.js +42 -42
- package/server/routes/print/controllers/printTemplate.js +67 -67
- package/server/routes/print/controllers/printTemplateList.js +19 -19
- package/server/routes/print/controllers/printTemplatePreview.js +87 -87
- package/server/routes/print/index.mjs +19 -19
- package/server/routes/properties/controllers/admin.properties.get.js +31 -31
- package/server/routes/properties/controllers/table.properties.get.js +120 -120
- package/server/routes/properties/controllers/table.properties.post.js +115 -115
- package/server/routes/properties/controllers/user.properties.get.js +19 -19
- package/server/routes/properties/controllers/user.properties.post.js +10 -10
- package/server/routes/properties/index.mjs +21 -21
- package/server/routes/properties/utils/dataInsert.js +26 -26
- package/server/routes/properties/utils/getColumnMetaData.js +17 -17
- package/server/routes/properties/utils/refreshData.js +128 -128
- package/server/routes/report/utils/getFilterQuery.js +67 -67
- package/server/routes/templates/index.mjs +16 -16
- package/server/routes/user/controllers/user.cls.post.js +54 -54
- package/server/routes/util/index.mjs +5 -5
- package/server/routes/widget/controllers/widget.get.js +125 -125
- package/server/templates/form/admin.profile.form.json +31 -31
- package/server/templates/form/cp_building.form.json +32 -32
- package/server/templates/pt/card-print.pt.hbs +245 -245
- package/utils.js +26 -26
@@ -1,112 +1,112 @@
|
|
1
|
-
import {
|
2
|
-
getTemplate, getMeta, metaFormat, applyHook, handlebars, pgClients,
|
3
|
-
} from '@opengis/fastify-table/utils.js';
|
4
|
-
|
5
|
-
export default async function tableInfo(req) {
|
6
|
-
const {
|
7
|
-
pg = pgClients.client, params = {}, query = {}, user = {},
|
8
|
-
} = req;
|
9
|
-
|
10
|
-
const time = Date.now();
|
11
|
-
|
12
|
-
const { uid } = user;
|
13
|
-
|
14
|
-
if (!uid) {
|
15
|
-
return { message: 'access restricted: uid', status: 403 };
|
16
|
-
}
|
17
|
-
|
18
|
-
if (!params?.id || !params?.table) {
|
19
|
-
return { message: 'not enougn params', status: 400 };
|
20
|
-
}
|
21
|
-
|
22
|
-
const loadTable = await getTemplate('table', params.table);
|
23
|
-
|
24
|
-
if (!loadTable) {
|
25
|
-
return { message: 'template not found', status: 404 };
|
26
|
-
}
|
27
|
-
|
28
|
-
const {
|
29
|
-
table, columns = [], sql, cardSql, filters, form, meta, public: ispublic,
|
30
|
-
} = loadTable;
|
31
|
-
|
32
|
-
if (!meta?.info) {
|
33
|
-
return { message: 'empty meta info', status: 400 };
|
34
|
-
}
|
35
|
-
|
36
|
-
const tableMeta = await getMeta(table);
|
37
|
-
|
38
|
-
if (tableMeta?.view) {
|
39
|
-
if (!loadTable?.key) {
|
40
|
-
return { message: `key not found: ${table}`, status: 404 };
|
41
|
-
}
|
42
|
-
Object.assign(tableMeta, { pk: loadTable?.key });
|
43
|
-
}
|
44
|
-
|
45
|
-
const { pk } = tableMeta || {};
|
46
|
-
|
47
|
-
if (!pk) {
|
48
|
-
return { message: `table not found: ${table}`, status: 404 };
|
49
|
-
}
|
50
|
-
|
51
|
-
const sqlTable = sql
|
52
|
-
?.filter?.((el) => !el?.disabled && el?.sql?.replace)
|
53
|
-
?.map((el, i) => ` left join lateral (${el.sql.replace('{{uid}}', uid)}) ${el.name || `t${i}`} on 1=1 `)
|
54
|
-
?.join('') || '';
|
55
|
-
|
56
|
-
const cardSqlFiltered = params.id ? (cardSql?.filter?.((el) => !el?.disabled && el?.name && el?.sql?.replace) || []) : [];
|
57
|
-
const cardSqlTable = cardSqlFiltered.length ? cardSqlFiltered.map((el, i) => ` left join lateral (${el.sql.replace('{{uid}}', uid)}) ct${i} on 1=1 `).join('\n') || '' : '';
|
58
|
-
|
59
|
-
const interfaceQuery = params?.query ? await handlebars.compile(params?.query)({ user, uid }) : undefined;
|
60
|
-
const where = [params.id ? `"${pk}" = $1` : null, loadTable.query, interfaceQuery].filter((el) => el).filter((el) => (user?.user_type === 'superadmin' ? !el.includes('{{uid}}') : true));
|
61
|
-
|
62
|
-
const { fields = [] } = await pg.query(`select * from ${table} where ${sqlTable ? 'true' : (where.join(' and ') || 'true')} limit 0`, ([sqlTable ? null : params.id].filter(el => el)) );
|
63
|
-
const columnList = fields.map(el => el.name);
|
64
|
-
|
65
|
-
const metaInfoCols = meta.info.split(',').filter(el => columnList.includes(el)).map((el) => `"${el}"`);
|
66
|
-
|
67
|
-
if (!metaInfoCols.length) {
|
68
|
-
return { message: 'invalid meta info: columns not found', status: 400 };
|
69
|
-
}
|
70
|
-
|
71
|
-
const q = `select ${pk ? `"${pk}" as id,` : ''}
|
72
|
-
${metaInfoCols.join(',')}
|
73
|
-
from (select * from ${table} where ${sqlTable ? 'true' : (where.join(' and ') || 'true')}) t
|
74
|
-
${sqlTable}
|
75
|
-
${cardSqlTable}
|
76
|
-
where ${where.join(' and ') || 'true'}
|
77
|
-
limit 1`
|
78
|
-
.replace(/{{uid}}/g, uid);
|
79
|
-
|
80
|
-
// if (user?.user_type === 'superadmin') console.log(q);
|
81
|
-
|
82
|
-
if (query.sql === '1') { return q; }
|
83
|
-
|
84
|
-
const { rows } = await pg.query(q, [params.id]);
|
85
|
-
|
86
|
-
const qCount = `select
|
87
|
-
count(*)::int as total,
|
88
|
-
count(*) FILTER(WHERE ${[interfaceQuery].filter(el => el).join(' and ') || 'true'})::int as filtered
|
89
|
-
from ${table} t ${sqlTable}
|
90
|
-
where ${[loadTable.query].filter(el => el).join(' and ') || 'true'} `
|
91
|
-
.replace(/{{uid}}/g, uid);
|
92
|
-
|
93
|
-
const { total, filtered } = params.id ? rows.length
|
94
|
-
: await pg.queryCache(qCount, { table: loadTable.table, time: 5 }).then((el) => el?.rows[0]);
|
95
|
-
|
96
|
-
const cls = meta.info.split(',').filter(el => columnList.includes(el))
|
97
|
-
.map(el => ({ name: el, data: columns.find(col => col.name === el)?.data }))
|
98
|
-
.filter(el => el.data)
|
99
|
-
.reduce((acc, curr) => Object.assign(acc, { [curr.name]: curr.data }), {});
|
100
|
-
|
101
|
-
await metaFormat({ rows, cls /* , sufix: false */ });
|
102
|
-
|
103
|
-
const res = {
|
104
|
-
time: Date.now() - time, public: ispublic, card: loadTable.card, total, filtered, count: rows.length, pk, form, rows, meta, columns, filters,
|
105
|
-
};
|
106
|
-
|
107
|
-
const result = await applyHook('afterData', {
|
108
|
-
table: loadTable.table, payload: res, user,
|
109
|
-
});
|
110
|
-
|
111
|
-
return result || res;
|
112
|
-
}
|
1
|
+
import {
|
2
|
+
getTemplate, getMeta, metaFormat, applyHook, handlebars, pgClients,
|
3
|
+
} from '@opengis/fastify-table/utils.js';
|
4
|
+
|
5
|
+
export default async function tableInfo(req) {
|
6
|
+
const {
|
7
|
+
pg = pgClients.client, params = {}, query = {}, user = {},
|
8
|
+
} = req;
|
9
|
+
|
10
|
+
const time = Date.now();
|
11
|
+
|
12
|
+
const { uid } = user;
|
13
|
+
|
14
|
+
if (!uid) {
|
15
|
+
return { message: 'access restricted: uid', status: 403 };
|
16
|
+
}
|
17
|
+
|
18
|
+
if (!params?.id || !params?.table) {
|
19
|
+
return { message: 'not enougn params', status: 400 };
|
20
|
+
}
|
21
|
+
|
22
|
+
const loadTable = await getTemplate('table', params.table);
|
23
|
+
|
24
|
+
if (!loadTable) {
|
25
|
+
return { message: 'template not found', status: 404 };
|
26
|
+
}
|
27
|
+
|
28
|
+
const {
|
29
|
+
table, columns = [], sql, cardSql, filters, form, meta, public: ispublic,
|
30
|
+
} = loadTable;
|
31
|
+
|
32
|
+
if (!meta?.info) {
|
33
|
+
return { message: 'empty meta info', status: 400 };
|
34
|
+
}
|
35
|
+
|
36
|
+
const tableMeta = await getMeta(table);
|
37
|
+
|
38
|
+
if (tableMeta?.view) {
|
39
|
+
if (!loadTable?.key) {
|
40
|
+
return { message: `key not found: ${table}`, status: 404 };
|
41
|
+
}
|
42
|
+
Object.assign(tableMeta, { pk: loadTable?.key });
|
43
|
+
}
|
44
|
+
|
45
|
+
const { pk } = tableMeta || {};
|
46
|
+
|
47
|
+
if (!pk) {
|
48
|
+
return { message: `table not found: ${table}`, status: 404 };
|
49
|
+
}
|
50
|
+
|
51
|
+
const sqlTable = sql
|
52
|
+
?.filter?.((el) => !el?.disabled && el?.sql?.replace)
|
53
|
+
?.map((el, i) => ` left join lateral (${el.sql.replace('{{uid}}', uid)}) ${el.name || `t${i}`} on 1=1 `)
|
54
|
+
?.join('') || '';
|
55
|
+
|
56
|
+
const cardSqlFiltered = params.id ? (cardSql?.filter?.((el) => !el?.disabled && el?.name && el?.sql?.replace) || []) : [];
|
57
|
+
const cardSqlTable = cardSqlFiltered.length ? cardSqlFiltered.map((el, i) => ` left join lateral (${el.sql.replace('{{uid}}', uid)}) ct${i} on 1=1 `).join('\n') || '' : '';
|
58
|
+
|
59
|
+
const interfaceQuery = params?.query ? await handlebars.compile(params?.query)({ user, uid }) : undefined;
|
60
|
+
const where = [params.id ? `"${pk}" = $1` : null, loadTable.query, interfaceQuery].filter((el) => el).filter((el) => (user?.user_type === 'superadmin' ? !el.includes('{{uid}}') : true));
|
61
|
+
|
62
|
+
const { fields = [] } = await pg.query(`select * from ${table} where ${sqlTable ? 'true' : (where.join(' and ') || 'true')} limit 0`, ([sqlTable ? null : params.id].filter(el => el)) );
|
63
|
+
const columnList = fields.map(el => el.name);
|
64
|
+
|
65
|
+
const metaInfoCols = meta.info.split(',').filter(el => columnList.includes(el)).map((el) => `"${el}"`);
|
66
|
+
|
67
|
+
if (!metaInfoCols.length) {
|
68
|
+
return { message: 'invalid meta info: columns not found', status: 400 };
|
69
|
+
}
|
70
|
+
|
71
|
+
const q = `select ${pk ? `"${pk}" as id,` : ''}
|
72
|
+
${metaInfoCols.join(',')}
|
73
|
+
from (select * from ${table} where ${sqlTable ? 'true' : (where.join(' and ') || 'true')}) t
|
74
|
+
${sqlTable}
|
75
|
+
${cardSqlTable}
|
76
|
+
where ${where.join(' and ') || 'true'}
|
77
|
+
limit 1`
|
78
|
+
.replace(/{{uid}}/g, uid);
|
79
|
+
|
80
|
+
// if (user?.user_type === 'superadmin') console.log(q);
|
81
|
+
|
82
|
+
if (query.sql === '1') { return q; }
|
83
|
+
|
84
|
+
const { rows } = await pg.query(q, [params.id]);
|
85
|
+
|
86
|
+
const qCount = `select
|
87
|
+
count(*)::int as total,
|
88
|
+
count(*) FILTER(WHERE ${[interfaceQuery].filter(el => el).join(' and ') || 'true'})::int as filtered
|
89
|
+
from ${table} t ${sqlTable}
|
90
|
+
where ${[loadTable.query].filter(el => el).join(' and ') || 'true'} `
|
91
|
+
.replace(/{{uid}}/g, uid);
|
92
|
+
|
93
|
+
const { total, filtered } = params.id ? rows.length
|
94
|
+
: await pg.queryCache(qCount, { table: loadTable.table, time: 5 }).then((el) => el?.rows[0]);
|
95
|
+
|
96
|
+
const cls = meta.info.split(',').filter(el => columnList.includes(el))
|
97
|
+
.map(el => ({ name: el, data: columns.find(col => col.name === el)?.data }))
|
98
|
+
.filter(el => el.data)
|
99
|
+
.reduce((acc, curr) => Object.assign(acc, { [curr.name]: curr.data }), {});
|
100
|
+
|
101
|
+
await metaFormat({ rows, cls /* , sufix: false */ });
|
102
|
+
|
103
|
+
const res = {
|
104
|
+
time: Date.now() - time, public: ispublic, card: loadTable.card, total, filtered, count: rows.length, pk, form, rows, meta, columns, filters,
|
105
|
+
};
|
106
|
+
|
107
|
+
const result = await applyHook('afterData', {
|
108
|
+
table: loadTable.table, payload: res, user,
|
109
|
+
});
|
110
|
+
|
111
|
+
return result || res;
|
112
|
+
}
|
@@ -1,20 +1,20 @@
|
|
1
|
-
import { dblist, getRedis } from '@opengis/fastify-table/utils.js';
|
2
|
-
|
3
|
-
import formatData from '../utils/formatData.js';
|
4
|
-
|
5
|
-
const rclient = getRedis();
|
6
|
-
|
7
|
-
export default async function readItemList(req) {
|
8
|
-
const rows = formatData(dblist);
|
9
|
-
const uid = req.session.passport?.user?.uid // login db
|
10
|
-
|| req.session.passport?.user?.username // login passwd
|
11
|
-
|| '2';
|
12
|
-
|
13
|
-
const key = `current-db:${uid}`;
|
14
|
-
const ttl = await rclient.ttl(key);
|
15
|
-
const currentId = await rclient.get(key);
|
16
|
-
rclient.setex(key, 60 * 60 * 10000, currentId);
|
17
|
-
|
18
|
-
const { originalMaxAge, expires } = req.session?.cookie || {};
|
19
|
-
return { ttl, current: currentId || rows[0]?.id, rows, user: { ...req.user, originalMaxAge, expires, uid }, };
|
20
|
-
}
|
1
|
+
import { dblist, getRedis } from '@opengis/fastify-table/utils.js';
|
2
|
+
|
3
|
+
import formatData from '../utils/formatData.js';
|
4
|
+
|
5
|
+
const rclient = getRedis();
|
6
|
+
|
7
|
+
export default async function readItemList(req) {
|
8
|
+
const rows = formatData(dblist);
|
9
|
+
const uid = req.session.passport?.user?.uid // login db
|
10
|
+
|| req.session.passport?.user?.username // login passwd
|
11
|
+
|| '2';
|
12
|
+
|
13
|
+
const key = `current-db:${uid}`;
|
14
|
+
const ttl = await rclient.ttl(key);
|
15
|
+
const currentId = await rclient.get(key);
|
16
|
+
rclient.setex(key, 60 * 60 * 10000, currentId);
|
17
|
+
|
18
|
+
const { originalMaxAge, expires } = req.session?.cookie || {};
|
19
|
+
return { ttl, current: currentId || rows[0]?.id, rows, user: { ...req.user, originalMaxAge, expires, uid }, };
|
20
|
+
}
|
@@ -1,22 +1,22 @@
|
|
1
|
-
import { dblist, getRedis } from '@opengis/fastify-table/utils.js';
|
2
|
-
|
3
|
-
export default async function setItem(req) {
|
4
|
-
const { params = {} } = req;
|
5
|
-
const { id } = params;
|
6
|
-
|
7
|
-
if (!id) return { error: 'not enough params', status: 400 };
|
8
|
-
|
9
|
-
const current = dblist.find((el) => [el.id, el.key].includes(id));
|
10
|
-
if (!current?.database) {
|
11
|
-
return { error: 'invalid param id', status: 400 };
|
12
|
-
}
|
13
|
-
|
14
|
-
const rclient = getRedis();
|
15
|
-
const uid = req.session.passport?.user?.uid // login db
|
16
|
-
|| req.session.passport?.user?.username // login passwd
|
17
|
-
|| '2';
|
18
|
-
|
19
|
-
await rclient.setex(`current-db:${uid}`, 60 * 60 * 10000, id);
|
20
|
-
|
21
|
-
return { current: id };
|
22
|
-
}
|
1
|
+
import { dblist, getRedis } from '@opengis/fastify-table/utils.js';
|
2
|
+
|
3
|
+
export default async function setItem(req) {
|
4
|
+
const { params = {} } = req;
|
5
|
+
const { id } = params;
|
6
|
+
|
7
|
+
if (!id) return { error: 'not enough params', status: 400 };
|
8
|
+
|
9
|
+
const current = dblist.find((el) => [el.id, el.key].includes(id));
|
10
|
+
if (!current?.database) {
|
11
|
+
return { error: 'invalid param id', status: 400 };
|
12
|
+
}
|
13
|
+
|
14
|
+
const rclient = getRedis();
|
15
|
+
const uid = req.session.passport?.user?.uid // login db
|
16
|
+
|| req.session.passport?.user?.username // login passwd
|
17
|
+
|| '2';
|
18
|
+
|
19
|
+
await rclient.setex(`current-db:${uid}`, 60 * 60 * 10000, id);
|
20
|
+
|
21
|
+
return { current: id };
|
22
|
+
}
|
@@ -1,18 +1,18 @@
|
|
1
|
-
import readItemList from './controllers/readItems.js';
|
2
|
-
import setItem from './controllers/setItem.js';
|
3
|
-
|
4
|
-
export default async function plugin(fastify) {
|
5
|
-
|
6
|
-
fastify.route({
|
7
|
-
method: 'GET',
|
8
|
-
url: '/db-list',
|
9
|
-
config: { policy: ['site'] },
|
10
|
-
handler: readItemList,
|
11
|
-
});
|
12
|
-
fastify.route({
|
13
|
-
method: 'GET',
|
14
|
-
url: '/db-list/:id',
|
15
|
-
config: { policy: ['site'] },
|
16
|
-
handler: setItem,
|
17
|
-
});
|
18
|
-
}
|
1
|
+
import readItemList from './controllers/readItems.js';
|
2
|
+
import setItem from './controllers/setItem.js';
|
3
|
+
|
4
|
+
export default async function plugin(fastify) {
|
5
|
+
|
6
|
+
fastify.route({
|
7
|
+
method: 'GET',
|
8
|
+
url: '/db-list',
|
9
|
+
config: { policy: ['site'] },
|
10
|
+
handler: readItemList,
|
11
|
+
});
|
12
|
+
fastify.route({
|
13
|
+
method: 'GET',
|
14
|
+
url: '/db-list/:id',
|
15
|
+
config: { policy: ['site'] },
|
16
|
+
handler: setItem,
|
17
|
+
});
|
18
|
+
}
|
@@ -1,7 +1,7 @@
|
|
1
|
-
const showKeys = ['id', 'key', 'title'];
|
2
|
-
|
3
|
-
export default function formatData(data = []) {
|
4
|
-
return data?.length
|
5
|
-
? data.map((el) => Object.keys(el).filter((key) => showKeys.includes(key)).reduce((acc, curr) => Object.assign(acc, { [curr]: el[curr] }), {}))
|
6
|
-
: [];
|
7
|
-
}
|
1
|
+
const showKeys = ['id', 'key', 'title'];
|
2
|
+
|
3
|
+
export default function formatData(data = []) {
|
4
|
+
return data?.length
|
5
|
+
? data.map((el) => Object.keys(el).filter((key) => showKeys.includes(key)).reduce((acc, curr) => Object.assign(acc, { [curr]: el[curr] }), {}))
|
6
|
+
: [];
|
7
|
+
}
|
@@ -1,78 +1,78 @@
|
|
1
|
-
|
2
|
-
import { join } from 'path';
|
3
|
-
import { userTemplateDir, pgClients, applyHook, config } from '@opengis/fastify-table/utils.js';
|
4
|
-
|
5
|
-
import { existsSync, readdirSync, readFileSync } from 'fs';
|
6
|
-
const menuCache = [];
|
7
|
-
// check module dir
|
8
|
-
const moduleDir = join(process.cwd(), 'module');
|
9
|
-
const dirs = existsSync(moduleDir) ?
|
10
|
-
readdirSync(moduleDir).map(el => join(moduleDir, el)) : [];
|
11
|
-
|
12
|
-
// all menu files module + user
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
const isProduction = process.env.NODE_ENV === 'production';
|
17
|
-
// readMenu();
|
18
|
-
|
19
|
-
async function readMenu() {
|
20
|
-
const menuList = dirs.concat(userTemplateDir)
|
21
|
-
.map(el => join(el, 'menu.json'))
|
22
|
-
.filter(el => existsSync(el))
|
23
|
-
// const list = menuList.map(el => readFileSync(el, 'utf-8')); // sync
|
24
|
-
const list = menuList.filter((el, idx, arr) => el && arr.indexOf(el) === idx).map(el => readFileSync(el, 'utf-8')); // sync
|
25
|
-
const menus = list.reduce((p, el) => p.concat(JSON.parse(el)), [])
|
26
|
-
.map(el => ({ order: 0, ...el }))
|
27
|
-
.sort((a, b) => (a.order > b.order) ? 1 : ((b.order > a.order) ? -1 : 0))
|
28
|
-
|
29
|
-
if (!menuCache.length) menus.forEach(el => menuCache.push(el))
|
30
|
-
return menus;
|
31
|
-
}
|
32
|
-
export default async function adminMenu({ user = {}, session, pg = pgClients.client }) {
|
33
|
-
const time = Date.now();
|
34
|
-
if (!user.uid) return { status: 403, message: 'access restricted' }
|
35
|
-
|
36
|
-
const menus = isProduction && menuCache.length ? menuCache : await readMenu();
|
37
|
-
|
38
|
-
const { rows } = await pgClients.client.query(`select property_key as key,property_text as val from admin.properties where property_key~'^(${config.settingKeys || 'site|map|admin'})'`);
|
39
|
-
const settings = rows.reduce((p, { key, val }) => { const [k1, k2] = key.split('.'); p[k1] = p[k1] || {}; p[k1][k2] = val; return p }, {});
|
40
|
-
// update user access
|
41
|
-
const { user_name, sur_name, father_name, email, phone, uid } = user;
|
42
|
-
const result = { settings, user: { uid, user_name, sur_name, father_name, email, phone } };
|
43
|
-
await applyHook('userMenu', result);
|
44
|
-
|
45
|
-
if (session && user?.uid && !user.user_type?.includes?.('admin') && !user.type?.includes?.('admin') && pg.pk['admin.role_access']) {
|
46
|
-
const { type, gl = [], routes = [] } = await pg.query(`select user_type as type, b.gl,routes from admin.users a
|
47
|
-
left join lateral (
|
48
|
-
select array_agg(role_id) as gl from admin.user_roles
|
49
|
-
where user_uid=a.uid
|
50
|
-
and role_id in ( select role_id from admin.roles where enabled)
|
51
|
-
)b on 1=1
|
52
|
-
left join lateral (
|
53
|
-
select array_agg(route_id) as routes from admin.role_access where role_id=any(b.gl)
|
54
|
-
)r on 1=1
|
55
|
-
where uid=$1`, [user.uid]).then(el => el.rows[0] || {});
|
56
|
-
/* const { interfaces = [] } = await pg.query(`select array_agg(route_id) as interfaces from admin.role_access
|
57
|
-
where user_uid=$1 or role_id=any($2::text[])`, [user.uid, gl]).then((res) => res.rows?.[0] || {}); */
|
58
|
-
|
59
|
-
Object.assign(user, { type, group_list: gl, routes });
|
60
|
-
session?.set?.('passport', { user });
|
61
|
-
|
62
|
-
if (type?.includes?.('admin')) {
|
63
|
-
return { time: Date.now() - time, menus, ...result };
|
64
|
-
}
|
65
|
-
|
66
|
-
const userMenus = menus.map(el => (el.menu ? { ...el, menu: el.menu.filter(item => routes?.includes(item.path)) } : el))
|
67
|
-
const filtered = userMenus.filter(el => el.menu?.length || routes?.includes(el.path));
|
68
|
-
return { time: Date.now() - time, menus: filtered, ...result }
|
69
|
-
// .filter((el, idx, arr) => arr.map((el) => el?.ua || el?.en || el?.name).indexOf(el?.ua || el?.en || el?.name) === idx)
|
70
|
-
}
|
71
|
-
|
72
|
-
// skip dupes?
|
73
|
-
// .filter((el, idx, arr) => arr.map((el) => el?.ua || el?.en || el?.name).indexOf(el?.ua || el?.en || el?.name) === idx)
|
74
|
-
|
75
|
-
return { time: Date.now() - time, menus, ...result };
|
76
|
-
|
77
|
-
|
1
|
+
|
2
|
+
import { join } from 'path';
|
3
|
+
import { userTemplateDir, pgClients, applyHook, config } from '@opengis/fastify-table/utils.js';
|
4
|
+
|
5
|
+
import { existsSync, readdirSync, readFileSync } from 'fs';
|
6
|
+
const menuCache = [];
|
7
|
+
// check module dir
|
8
|
+
const moduleDir = join(process.cwd(), 'module');
|
9
|
+
const dirs = existsSync(moduleDir) ?
|
10
|
+
readdirSync(moduleDir).map(el => join(moduleDir, el)) : [];
|
11
|
+
|
12
|
+
// all menu files module + user
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
17
|
+
// readMenu();
|
18
|
+
|
19
|
+
async function readMenu() {
|
20
|
+
const menuList = dirs.concat(userTemplateDir)
|
21
|
+
.map(el => join(el, 'menu.json'))
|
22
|
+
.filter(el => existsSync(el))
|
23
|
+
// const list = menuList.map(el => readFileSync(el, 'utf-8')); // sync
|
24
|
+
const list = menuList.filter((el, idx, arr) => el && arr.indexOf(el) === idx).map(el => readFileSync(el, 'utf-8')); // sync
|
25
|
+
const menus = list.reduce((p, el) => p.concat(JSON.parse(el)), [])
|
26
|
+
.map(el => ({ order: 0, ...el }))
|
27
|
+
.sort((a, b) => (a.order > b.order) ? 1 : ((b.order > a.order) ? -1 : 0))
|
28
|
+
|
29
|
+
if (!menuCache.length) menus.forEach(el => menuCache.push(el))
|
30
|
+
return menus;
|
31
|
+
}
|
32
|
+
export default async function adminMenu({ user = {}, session, pg = pgClients.client }) {
|
33
|
+
const time = Date.now();
|
34
|
+
if (!user.uid) return { status: 403, message: 'access restricted' }
|
35
|
+
|
36
|
+
const menus = isProduction && menuCache.length ? menuCache : await readMenu();
|
37
|
+
|
38
|
+
const { rows } = await pgClients.client.query(`select property_key as key,property_text as val from admin.properties where property_key~'^(${config.settingKeys || 'site|map|admin'})'`);
|
39
|
+
const settings = rows.reduce((p, { key, val }) => { const [k1, k2] = key.split('.'); p[k1] = p[k1] || {}; p[k1][k2] = val; return p }, {});
|
40
|
+
// update user access
|
41
|
+
const { user_name, sur_name, father_name, email, phone, uid } = user;
|
42
|
+
const result = { settings, user: { uid, user_name, sur_name, father_name, email, phone } };
|
43
|
+
await applyHook('userMenu', result);
|
44
|
+
|
45
|
+
if (session && user?.uid && !user.user_type?.includes?.('admin') && !user.type?.includes?.('admin') && pg.pk['admin.role_access']) {
|
46
|
+
const { type, gl = [], routes = [] } = await pg.query(`select user_type as type, b.gl,routes from admin.users a
|
47
|
+
left join lateral (
|
48
|
+
select array_agg(role_id) as gl from admin.user_roles
|
49
|
+
where user_uid=a.uid
|
50
|
+
and role_id in ( select role_id from admin.roles where enabled)
|
51
|
+
)b on 1=1
|
52
|
+
left join lateral (
|
53
|
+
select array_agg(route_id) as routes from admin.role_access where role_id=any(b.gl)
|
54
|
+
)r on 1=1
|
55
|
+
where uid=$1`, [user.uid]).then(el => el.rows[0] || {});
|
56
|
+
/* const { interfaces = [] } = await pg.query(`select array_agg(route_id) as interfaces from admin.role_access
|
57
|
+
where user_uid=$1 or role_id=any($2::text[])`, [user.uid, gl]).then((res) => res.rows?.[0] || {}); */
|
58
|
+
|
59
|
+
Object.assign(user, { type, group_list: gl, routes });
|
60
|
+
session?.set?.('passport', { user });
|
61
|
+
|
62
|
+
if (type?.includes?.('admin')) {
|
63
|
+
return { time: Date.now() - time, menus, ...result };
|
64
|
+
}
|
65
|
+
|
66
|
+
const userMenus = menus.map(el => (el.menu ? { ...el, menu: el.menu.filter(item => routes?.includes(item.path)) } : el))
|
67
|
+
const filtered = userMenus.filter(el => el.menu?.length || routes?.includes(el.path));
|
68
|
+
return { time: Date.now() - time, menus: filtered, ...result }
|
69
|
+
// .filter((el, idx, arr) => arr.map((el) => el?.ua || el?.en || el?.name).indexOf(el?.ua || el?.en || el?.name) === idx)
|
70
|
+
}
|
71
|
+
|
72
|
+
// skip dupes?
|
73
|
+
// .filter((el, idx, arr) => arr.map((el) => el?.ua || el?.en || el?.name).indexOf(el?.ua || el?.en || el?.name) === idx)
|
74
|
+
|
75
|
+
return { time: Date.now() - time, menus, ...result };
|
76
|
+
|
77
|
+
|
78
78
|
}
|
@@ -1,21 +1,21 @@
|
|
1
|
-
import { pgClients, getTemplatePath } from '@opengis/fastify-table/utils.js';
|
2
|
-
|
3
|
-
export default async function adminMenu({ pg = pgClients.client }) {
|
4
|
-
const { rows = [] } = await pg.query(`select route_id, alias, table_name, title, enabled from admin.routes`);
|
5
|
-
|
6
|
-
const interfaces = rows
|
7
|
-
.filter((el, idx, arr) => el.table_name && arr.findIndex(item => item.route_id === el.route_id) === idx)
|
8
|
-
.filter(el => pg.pk?.[el.table_name || ''])
|
9
|
-
.filter(el => !['log.', 'admin.', 'setting.'].find(item => el.table_name.startsWith(item)))
|
10
|
-
.map(el => ({
|
11
|
-
title: el.title,
|
12
|
-
alias: el.alias,
|
13
|
-
table: el.table_name,
|
14
|
-
route: el.route_id,
|
15
|
-
enabled: el.enabled,
|
16
|
-
}));
|
17
|
-
|
18
|
-
const all = getTemplatePath('table').map(el => el[0]);
|
19
|
-
|
20
|
-
return interfaces.filter(el => el.alias && all.includes(el.alias));
|
1
|
+
import { pgClients, getTemplatePath } from '@opengis/fastify-table/utils.js';
|
2
|
+
|
3
|
+
export default async function adminMenu({ pg = pgClients.client }) {
|
4
|
+
const { rows = [] } = await pg.query(`select route_id, alias, table_name, title, enabled from admin.routes`);
|
5
|
+
|
6
|
+
const interfaces = rows
|
7
|
+
.filter((el, idx, arr) => el.table_name && arr.findIndex(item => item.route_id === el.route_id) === idx)
|
8
|
+
.filter(el => pg.pk?.[el.table_name || ''])
|
9
|
+
.filter(el => !['log.', 'admin.', 'setting.'].find(item => el.table_name.startsWith(item)))
|
10
|
+
.map(el => ({
|
11
|
+
title: el.title,
|
12
|
+
alias: el.alias,
|
13
|
+
table: el.table_name,
|
14
|
+
route: el.route_id,
|
15
|
+
enabled: el.enabled,
|
16
|
+
}));
|
17
|
+
|
18
|
+
const all = getTemplatePath('table').map(el => el[0]);
|
19
|
+
|
20
|
+
return interfaces.filter(el => el.alias && all.includes(el.alias));
|
21
21
|
}
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import getMenu from './controllers/getMenu.js';
|
2
|
-
import interfaces from './controllers/interfaces.js';
|
3
|
-
|
4
|
-
export default async function (fastify, opts) {
|
5
|
-
fastify.get(`/user-menu`, getMenu);
|
6
|
-
fastify.get(`/interfaces`, { config: { policy: ['admin'] } }, interfaces);
|
7
|
-
}
|
1
|
+
import getMenu from './controllers/getMenu.js';
|
2
|
+
import interfaces from './controllers/interfaces.js';
|
3
|
+
|
4
|
+
export default async function (fastify, opts) {
|
5
|
+
fastify.get(`/user-menu`, getMenu);
|
6
|
+
fastify.get(`/interfaces`, { config: { policy: ['admin'] } }, interfaces);
|
7
|
+
}
|
@@ -1,37 +1,37 @@
|
|
1
|
-
import { pgClients, dataInsert } from '@opengis/fastify-table/utils.js';
|
2
|
-
|
3
|
-
export default async function printTemplateAdd({
|
4
|
-
pg = pgClients.client, body = {}, user = {},
|
5
|
-
}) {
|
6
|
-
if (!user?.uid) {
|
7
|
-
return { message: 'access restricted', status: 403 };
|
8
|
-
}
|
9
|
-
|
10
|
-
const { name, title, route, html } = body;
|
11
|
-
|
12
|
-
if (!name) {
|
13
|
-
return { message: 'not enough body params: name', status: 400 };
|
14
|
-
}
|
15
|
-
|
16
|
-
if (!html) {
|
17
|
-
return { message: 'not enough body params: html', status: 400 };
|
18
|
-
}
|
19
|
-
|
20
|
-
const id = await pg.query(`select template_id as id from admin.templates where $1 in (template_id, name)`, [name])
|
21
|
-
.then(el => el.rows?.[0]?.id);
|
22
|
-
|
23
|
-
if (id) {
|
24
|
-
return { message: 'access restricted: template exists', status: 403 };
|
25
|
-
}
|
26
|
-
|
27
|
-
const res = await dataInsert({
|
28
|
-
pg,
|
29
|
-
table: 'admin.templates',
|
30
|
-
data: { name, title, route_id: route, body: html, type: 'user' },
|
31
|
-
uid: user?.uid,
|
32
|
-
})
|
33
|
-
|
34
|
-
const data = res.rows?.[0];
|
35
|
-
|
36
|
-
return { id: data?.template_id, data };
|
37
|
-
}
|
1
|
+
import { pgClients, dataInsert } from '@opengis/fastify-table/utils.js';
|
2
|
+
|
3
|
+
export default async function printTemplateAdd({
|
4
|
+
pg = pgClients.client, body = {}, user = {},
|
5
|
+
}) {
|
6
|
+
if (!user?.uid) {
|
7
|
+
return { message: 'access restricted', status: 403 };
|
8
|
+
}
|
9
|
+
|
10
|
+
const { name, title, route, html } = body;
|
11
|
+
|
12
|
+
if (!name) {
|
13
|
+
return { message: 'not enough body params: name', status: 400 };
|
14
|
+
}
|
15
|
+
|
16
|
+
if (!html) {
|
17
|
+
return { message: 'not enough body params: html', status: 400 };
|
18
|
+
}
|
19
|
+
|
20
|
+
const id = await pg.query(`select template_id as id from admin.templates where $1 in (template_id, name)`, [name])
|
21
|
+
.then(el => el.rows?.[0]?.id);
|
22
|
+
|
23
|
+
if (id) {
|
24
|
+
return { message: 'access restricted: template exists', status: 403 };
|
25
|
+
}
|
26
|
+
|
27
|
+
const res = await dataInsert({
|
28
|
+
pg,
|
29
|
+
table: 'admin.templates',
|
30
|
+
data: { name, title, route_id: route, body: html, type: 'user' },
|
31
|
+
uid: user?.uid,
|
32
|
+
})
|
33
|
+
|
34
|
+
const data = res.rows?.[0];
|
35
|
+
|
36
|
+
return { id: data?.template_id, data };
|
37
|
+
}
|