@opengis/gis 0.2.89 → 0.2.91
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/index.js +5311 -4981
- package/dist/index.umd.cjs +47 -47
- package/module/permissions/form/permissions.users.form.json +152 -0
- package/module/permissions/table/gis.permissions.table.json +99 -0
- package/package.json +2 -2
- package/plugin.js +1 -0
- package/server/migrations/array_intersect.sql +14 -0
- package/server/migrations/group_list.sql +75 -0
- package/server/migrations/services_users_rel.sql +23 -0
- package/server/routes/map/controllers/layerList.js +34 -8
- package/server/routes/map/controllers/mapFormat.js +2 -1
- package/server/routes/permissions/controllers/catalog.permissions.edit.js +22 -0
- package/server/routes/permissions/controllers/catalog.permissions.js +8 -0
- package/server/routes/permissions/controllers/gis.catalog.js +80 -0
- package/server/routes/permissions/controllers/utils/get.permissions.js +43 -0
- package/server/routes/permissions/index.mjs +18 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schema": {
|
|
3
|
+
"d1": {
|
|
4
|
+
"type": "HTML",
|
|
5
|
+
"title": false,
|
|
6
|
+
"text": "<h4 class='text-center'>Акаунт</h4><br>",
|
|
7
|
+
"col": 12
|
|
8
|
+
},
|
|
9
|
+
"user_name": {
|
|
10
|
+
"type": "Text",
|
|
11
|
+
"validators": [
|
|
12
|
+
"required"
|
|
13
|
+
],
|
|
14
|
+
"ua": "Ім'я",
|
|
15
|
+
"i": "Вноситься ім'я користувача, що буде відображатися у системі",
|
|
16
|
+
"ru": "Имя"
|
|
17
|
+
},
|
|
18
|
+
"sur_name": {
|
|
19
|
+
"type": "Text",
|
|
20
|
+
"validators": [
|
|
21
|
+
"required"
|
|
22
|
+
],
|
|
23
|
+
"ua": "Прізвище",
|
|
24
|
+
"i": "Вноситься прізвище користувача, що буде відображатися у системі",
|
|
25
|
+
"ru": "Фамилия"
|
|
26
|
+
},
|
|
27
|
+
"father_name": {
|
|
28
|
+
"ua": "По-батькові",
|
|
29
|
+
"type": "text"
|
|
30
|
+
},
|
|
31
|
+
"phone": {
|
|
32
|
+
"type": "MarkedText",
|
|
33
|
+
"mask": "+389999999999",
|
|
34
|
+
"id": "1",
|
|
35
|
+
"ua": "Телефон",
|
|
36
|
+
"i": "Вноситься телефон користувача",
|
|
37
|
+
"ru": "Телефон"
|
|
38
|
+
},
|
|
39
|
+
"email": {
|
|
40
|
+
"type": "Email",
|
|
41
|
+
"ua": "E-mail",
|
|
42
|
+
"i": "Вноситься електронна адреса користувача",
|
|
43
|
+
"ru": "E-mail",
|
|
44
|
+
"validators": [
|
|
45
|
+
"email"
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
"d2": {
|
|
49
|
+
"type": "HTML",
|
|
50
|
+
"title": false,
|
|
51
|
+
"text": "<h4 class='text-center'>Логін / Пароль</h4><br>",
|
|
52
|
+
"hidden": true,
|
|
53
|
+
"col": 12
|
|
54
|
+
},
|
|
55
|
+
"login": {
|
|
56
|
+
"type": "Text",
|
|
57
|
+
"ua": "Логін",
|
|
58
|
+
"i": "Вноситься довільний логін користувача латинськими літерами, що буде використовуватися для входу в систему",
|
|
59
|
+
"ru": "Логин",
|
|
60
|
+
"validators": [
|
|
61
|
+
"required"
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"password": {
|
|
65
|
+
"type": "Password",
|
|
66
|
+
"validators": [
|
|
67
|
+
"required",
|
|
68
|
+
{
|
|
69
|
+
"type": "regexp",
|
|
70
|
+
"regexp": "^.{8,}$",
|
|
71
|
+
"flags": "gm",
|
|
72
|
+
"message": "Пароль повинен бути більше 8 символів"
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
"ua": "Пароль",
|
|
76
|
+
"i": "Вноситься пароль, що буде використовуватися для входу в систему (рекомендоване використання складних паролів)",
|
|
77
|
+
"ru": "Пароль"
|
|
78
|
+
},
|
|
79
|
+
"d3": {
|
|
80
|
+
"type": "HTML",
|
|
81
|
+
"title": false,
|
|
82
|
+
"text": "<h4 class='text-center'>Доступ</h4><br>",
|
|
83
|
+
"col": 12
|
|
84
|
+
},
|
|
85
|
+
"user_type": {
|
|
86
|
+
"type": "Autocomplete",
|
|
87
|
+
"data": "users.user_type",
|
|
88
|
+
"default": "regular",
|
|
89
|
+
"ua": "Тип користувача"
|
|
90
|
+
},
|
|
91
|
+
"enabled": {
|
|
92
|
+
"type": "Switcher",
|
|
93
|
+
"ua": "Off/On",
|
|
94
|
+
"help": "Off - користувач вимкнутий; On - Користувач увімкнутий"
|
|
95
|
+
},
|
|
96
|
+
"readonly": {
|
|
97
|
+
"type": "Switcher",
|
|
98
|
+
"ua": "Read Only",
|
|
99
|
+
"help": "On - У користувача усі інтерфейси в режимі перегляду, без редагування"
|
|
100
|
+
},
|
|
101
|
+
"d4": {
|
|
102
|
+
"type": "HTML",
|
|
103
|
+
"title": false,
|
|
104
|
+
"text": "<h4 class='text-center'>Профіль</h4><br>",
|
|
105
|
+
"col": 12
|
|
106
|
+
},
|
|
107
|
+
"user_rnokpp": {
|
|
108
|
+
"type": "MarkedText",
|
|
109
|
+
"mask": "9999999999",
|
|
110
|
+
"ua": "РНОКПП",
|
|
111
|
+
"col": 6,
|
|
112
|
+
"validators": [
|
|
113
|
+
{
|
|
114
|
+
"type": "regexp",
|
|
115
|
+
"regexp": "^([0-9]{10,10})$",
|
|
116
|
+
"flags": "g",
|
|
117
|
+
"message": "Лише цифри, 10 символів"
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
},
|
|
121
|
+
"organ_edrpou": {
|
|
122
|
+
"type": "MarkedText",
|
|
123
|
+
"mask": "99999999",
|
|
124
|
+
"ua": "Код ЄДРПОУ",
|
|
125
|
+
"col": 6,
|
|
126
|
+
"validators": [
|
|
127
|
+
{
|
|
128
|
+
"type": "regexp",
|
|
129
|
+
"regexp": "^([0-9]{8,8})$",
|
|
130
|
+
"flags": "g",
|
|
131
|
+
"message": "Лише цифри, 8 символів"
|
|
132
|
+
}
|
|
133
|
+
]
|
|
134
|
+
},
|
|
135
|
+
"unzr": {
|
|
136
|
+
"type": "MarkedText",
|
|
137
|
+
"mask": "99999999-9999",
|
|
138
|
+
"ua": "УНЗР",
|
|
139
|
+
"col": 6,
|
|
140
|
+
"i": "Унікальний номер запису в Єдиному державному демографічному реєстрі"
|
|
141
|
+
},
|
|
142
|
+
"avatar": {
|
|
143
|
+
"type": "File",
|
|
144
|
+
"ua": "Аватар",
|
|
145
|
+
"i": "Додається зображення, що буде відображено в системі у якості аватара цього користувача",
|
|
146
|
+
"ru": "Аватар",
|
|
147
|
+
"dir": "avatar"
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
"label_style": "vertical",
|
|
151
|
+
"width": 900
|
|
152
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{
|
|
2
|
+
"key": "uid",
|
|
3
|
+
"table": "admin.users",
|
|
4
|
+
"actions": [
|
|
5
|
+
"add",
|
|
6
|
+
"edit"
|
|
7
|
+
],
|
|
8
|
+
"controls": [
|
|
9
|
+
"search",
|
|
10
|
+
"list",
|
|
11
|
+
"add"
|
|
12
|
+
],
|
|
13
|
+
"access": "user",
|
|
14
|
+
"order": "cdate desc",
|
|
15
|
+
"form": "admin.users.form",
|
|
16
|
+
"meta": {
|
|
17
|
+
"title": "full_name",
|
|
18
|
+
"search": "user_name,sur_name,father_name,login,email,phone"
|
|
19
|
+
},
|
|
20
|
+
"title": "Доступи до шарів",
|
|
21
|
+
"sql": [
|
|
22
|
+
{
|
|
23
|
+
"sql": "select count(*) as count_layers from gis.services_users_rel where user_id=t.uid",
|
|
24
|
+
"name": "count_layers_sql"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"sql": "select concat(user_name, ' ', sur_name, ' ', father_name, ' ') as full_name",
|
|
28
|
+
"name": "full_name_sql"
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"columns": [
|
|
32
|
+
{
|
|
33
|
+
"ua": "ПІБ",
|
|
34
|
+
"name": "full_name",
|
|
35
|
+
"format": "text",
|
|
36
|
+
"link": "gis.permissions/{id}"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"ua": "Логін",
|
|
40
|
+
"name": "login",
|
|
41
|
+
"hidden": true,
|
|
42
|
+
"format": "text"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"ua": "Email",
|
|
46
|
+
"name": "email",
|
|
47
|
+
"format": "text"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"ua": "РНОКПП",
|
|
51
|
+
"name": "user_rnokpp",
|
|
52
|
+
"format": "text"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"ua": "Кількість шарів в доступі",
|
|
56
|
+
"name": "count_layers",
|
|
57
|
+
"format": "text"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
"name": "cdate",
|
|
61
|
+
"ua": "Створено",
|
|
62
|
+
"format": "date"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"name": "enabled",
|
|
66
|
+
"ua": "On / Off",
|
|
67
|
+
"data": "yes_no",
|
|
68
|
+
"format": "date"
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
"filters": [
|
|
72
|
+
{
|
|
73
|
+
"ua": "РНОКПП",
|
|
74
|
+
"name": "user_rnokpp",
|
|
75
|
+
"type": "Text"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"ua": "Email",
|
|
79
|
+
"name": "email",
|
|
80
|
+
"type": "Text"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
"ua": "Кількість шарів в доступі",
|
|
84
|
+
"name": "count_layers",
|
|
85
|
+
"type": "Range"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"name": "enabled",
|
|
89
|
+
"type": "Check",
|
|
90
|
+
"data": "yes_no",
|
|
91
|
+
"ua": "On / Off"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"ua": "Дата створення",
|
|
95
|
+
"name": "cdate",
|
|
96
|
+
"type": "Date"
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengis/gis",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.91",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "Softpro",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@opengis/core": "^0.0.23",
|
|
56
|
-
"@opengis/fastify-table": "^2.0.
|
|
56
|
+
"@opengis/fastify-table": "^2.0.142",
|
|
57
57
|
"@opengis/filter": "0.1.31",
|
|
58
58
|
"@opengis/form": "^0.0.103",
|
|
59
59
|
"@opengis/table": "^0.0.27",
|
package/plugin.js
CHANGED
|
@@ -29,6 +29,7 @@ async function plugin(app, opts = config) {
|
|
|
29
29
|
app.register(import('./server/routes/map/index.mjs'), opts);
|
|
30
30
|
app.register(import('./server/plugins/crons.js'), opts);
|
|
31
31
|
app.register(import('./server/routes/gis/index.mjs'), opts);
|
|
32
|
+
app.register(import('./server/routes/permissions/index.mjs'), opts);
|
|
32
33
|
app.register(import('./server/routes/mapnik/index.js'), opts);
|
|
33
34
|
app.get('/logger-gis/stat', adminParams, mapnikStat);
|
|
34
35
|
app.get('/logger-gis/*', adminParams, mapnikLogger);
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
-- Table: gis.group_list
|
|
2
|
+
|
|
3
|
+
-- DROP TABLE gis.group_list;
|
|
4
|
+
|
|
5
|
+
CREATE TABLE if not exists gis.group_list
|
|
6
|
+
(
|
|
7
|
+
group_id text NOT NULL DEFAULT admin.next_id(), -- ідентифікатор групи
|
|
8
|
+
group_name text NOT NULL, -- Назва групи
|
|
9
|
+
enabled boolean DEFAULT true, -- ознака чи включена група
|
|
10
|
+
created_at timestamp without time zone DEFAULT date_trunc('minutes'::text, (now())::timestamp without time zone),
|
|
11
|
+
updated_at timestamp without time zone,
|
|
12
|
+
updated_by text,
|
|
13
|
+
created_by text,
|
|
14
|
+
cdate timestamp without time zone DEFAULT date_trunc('minutes'::text, (now())::timestamp without time zone), -- дата створення запису в БД
|
|
15
|
+
editor_date timestamp without time zone, -- Дата редагування
|
|
16
|
+
editor_id text, -- ідентифікатор користувача котрий останій вносив зміни в запис
|
|
17
|
+
uid text, -- ідентифікатор користувача який створив запис
|
|
18
|
+
icon text, -- Зображення
|
|
19
|
+
CONSTRAINT gis_group_id_pkey PRIMARY KEY (group_id)
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
COMMENT ON COLUMN gis.group_list.group_id IS 'ідентифікатор групи';
|
|
23
|
+
COMMENT ON COLUMN gis.group_list.group_name IS 'Назва групи';
|
|
24
|
+
COMMENT ON COLUMN gis.group_list.enabled IS 'ознака чи включена група';
|
|
25
|
+
COMMENT ON COLUMN gis.group_list.cdate IS 'дата створення запису в БД';
|
|
26
|
+
COMMENT ON COLUMN gis.group_list.editor_date IS 'Дата редагування';
|
|
27
|
+
COMMENT ON COLUMN gis.group_list.editor_id IS 'ідентифікатор користувача котрий останій вносив зміни в запис';
|
|
28
|
+
COMMENT ON COLUMN gis.group_list.uid IS 'ідентифікатор користувача який створив запис';
|
|
29
|
+
COMMENT ON COLUMN gis.group_list.icon IS 'Зображення';
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
-- Index: gis.gis_group_list_enabled_btree_idx
|
|
33
|
+
|
|
34
|
+
-- DROP INDEX gis.gis_group_list_enabled_btree_idx;
|
|
35
|
+
|
|
36
|
+
CREATE INDEX if not exists gis_group_list_enabled_btree_idx
|
|
37
|
+
ON gis.group_list
|
|
38
|
+
USING btree
|
|
39
|
+
(enabled);
|
|
40
|
+
|
|
41
|
+
-- Index: gis.gis_group_list_group_cdate_btree_idx
|
|
42
|
+
|
|
43
|
+
-- DROP INDEX gis.gis_group_list_group_cdate_btree_idx;
|
|
44
|
+
|
|
45
|
+
CREATE INDEX if not exists gis_group_list_group_cdate_btree_idx
|
|
46
|
+
ON gis.group_list
|
|
47
|
+
USING btree
|
|
48
|
+
(cdate);
|
|
49
|
+
|
|
50
|
+
-- Index: gis.gis_group_list_group_enabled_btree_idx
|
|
51
|
+
|
|
52
|
+
-- DROP INDEX gis.gis_group_list_group_enabled_btree_idx;
|
|
53
|
+
|
|
54
|
+
CREATE INDEX if not exists gis_group_list_group_enabled_btree_idx
|
|
55
|
+
ON gis.group_list
|
|
56
|
+
USING btree
|
|
57
|
+
(enabled);
|
|
58
|
+
|
|
59
|
+
-- Index: gis.gis_group_list_group_name_gin_idx
|
|
60
|
+
|
|
61
|
+
-- DROP INDEX gis.gis_group_list_group_name_gin_idx;
|
|
62
|
+
|
|
63
|
+
CREATE INDEX if not exists gis_group_list_group_name_gin_idx
|
|
64
|
+
ON gis.group_list
|
|
65
|
+
USING gin
|
|
66
|
+
(group_name COLLATE pg_catalog."default" gin_trgm_ops);
|
|
67
|
+
|
|
68
|
+
-- Index: gis.gis_group_list_group_name_gin_idx_lower
|
|
69
|
+
|
|
70
|
+
-- DROP INDEX gis.gis_group_list_group_name_gin_idx_lower;
|
|
71
|
+
|
|
72
|
+
CREATE INDEX if not exists gis_group_list_group_name_gin_idx_lower
|
|
73
|
+
ON gis.group_list
|
|
74
|
+
USING gin
|
|
75
|
+
(lower(group_name) COLLATE pg_catalog."default" gin_trgm_ops);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
CREATE TABLE if not exists gis.services_users_rel
|
|
2
|
+
(
|
|
3
|
+
services_rel_id text NOT NULL DEFAULT admin.next_id(),
|
|
4
|
+
service_id text NOT NULL,
|
|
5
|
+
user_id text NOT NULL,
|
|
6
|
+
actions text[],
|
|
7
|
+
created_at timestamp without time zone DEFAULT date_trunc('minutes'::text, (now())::timestamp without time zone),
|
|
8
|
+
updated_at timestamp without time zone,
|
|
9
|
+
updated_by text,
|
|
10
|
+
created_by text,
|
|
11
|
+
CONSTRAINT services_rel_pkey PRIMARY KEY (services_rel_id),
|
|
12
|
+
CONSTRAINT user_id_fkey FOREIGN KEY (user_id)
|
|
13
|
+
REFERENCES admin.users (uid) MATCH SIMPLE
|
|
14
|
+
ON UPDATE NO ACTION ON DELETE NO ACTION,
|
|
15
|
+
CONSTRAINT services_user_id_unique UNIQUE (service_id, user_id)
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
CREATE INDEX if not exists services_users_rel_service_id_btree_idx
|
|
19
|
+
ON gis.services_users_rel
|
|
20
|
+
USING btree
|
|
21
|
+
(service_id);
|
|
22
|
+
|
|
23
|
+
ALTER TABLE admin.users ADD COLUMN IF NOT EXISTS all_layers boolean NOT NULL DEFAULT false;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
config, pgClients, yml2json, getTemplates, getTemplate,
|
|
3
3
|
} from '@opengis/fastify-table/utils.js';
|
|
4
|
+
import getPermissions from '../../permissions/controllers/utils/get.permissions.js';
|
|
4
5
|
|
|
5
6
|
export default async function layerList({
|
|
6
7
|
pg = pgClients.client, query = {}, user = {},
|
|
@@ -12,19 +13,41 @@ export default async function layerList({
|
|
|
12
13
|
return layer;
|
|
13
14
|
}));
|
|
14
15
|
|
|
15
|
-
if (!pg.pk?.['gis.services']) {
|
|
16
|
+
if (!pg.pk?.['gis.services'] && !pg.pk?.['gis.ogc_service'] && !pg.pk?.['gis.rasters'] && !pg.pk?.['gis.cartocss']) {
|
|
16
17
|
return files;
|
|
17
18
|
// return reply.status(404).send('services table not found');
|
|
18
19
|
}
|
|
19
20
|
|
|
21
|
+
const { all_layers, layer_list } = (user.uid) ? await getPermissions({ pg, uid: user.uid }) : { all_layers: false, layer_list: [] };
|
|
22
|
+
|
|
23
|
+
const whereServices = (all_layers === true) ? '1=1'
|
|
24
|
+
: (user.uid && !all_layers) ? '( s.is_public or ( not s.is_public and ( s.service_id = any($1) or not exists ( select 1 from gis.services_users_rel r where r.service_id = s.service_id and r.actions is not null ) ) ) )'
|
|
25
|
+
: 'is_public';
|
|
26
|
+
|
|
27
|
+
const whereOgcServices = (all_layers === true) ? '1=1'
|
|
28
|
+
: (user.uid && !all_layers) ? '( s.ispublic or ( not s.ispublic and ( s.ogc_service_id = any($1) or not exists ( select 1 from gis.services_users_rel r where r.service_id = s.ogc_service_id and r.actions is not null ) ) ) )'
|
|
29
|
+
: 'ispublic';
|
|
30
|
+
|
|
31
|
+
const whereRasters = (all_layers === true) ? '1=1'
|
|
32
|
+
: (user.uid && !all_layers) ? '(s.is_public or (s.raster_id = any($1) and not s.is_public and s.raster_id not in (select service_id from gis.services_users_rel where actions is not null)))'
|
|
33
|
+
: 'is_public';
|
|
34
|
+
|
|
35
|
+
const whereCartocss = (all_layers === true) ? '1=1'
|
|
36
|
+
: (user.uid && !all_layers) ? '(s.is_public or (s.cartocss_id = any($1) and not s.is_public and s.cartocss_id not in (select service_id from gis.services_users_rel where actions is not null)))'
|
|
37
|
+
: 'is_public';
|
|
38
|
+
|
|
20
39
|
const q = `
|
|
40
|
+
select * from
|
|
41
|
+
(
|
|
21
42
|
select service_id as id, name, category, style, bbox::box2d as extent, st_asgeojson(bbox)::json as geom, coalesce('/api/vtile/'||service_id||'/ua/{z}/{x}/{y}.vmt',null) as url, coalesce(service_type, 'vtile') as service, group_id,
|
|
22
43
|
popup, card, filters, source_path
|
|
23
|
-
from gis.services where is_active and
|
|
44
|
+
from gis.services s where is_active and
|
|
45
|
+
${whereServices}
|
|
24
46
|
union all
|
|
25
47
|
select ogc_service_id as id, name, category, null as style, geom::box2d as extent, st_asgeojson(geom)::json as geom, url, 'ogc' as service, group_id,
|
|
26
48
|
null as popup, null as card, null as filters, table_name as source_path
|
|
27
|
-
from gis.ogc_service where enabled and
|
|
49
|
+
from gis.ogc_service s where enabled and
|
|
50
|
+
${whereOgcServices}
|
|
28
51
|
union all
|
|
29
52
|
select raster_id as id, name, null as category, null as style, geom::box2d as extent, st_asgeojson(geom)::json as geom,
|
|
30
53
|
coalesce('/api/gis-rtile/'||rtrim(
|
|
@@ -38,17 +61,20 @@ export default async function layerList({
|
|
|
38
61
|
'='
|
|
39
62
|
)||'/{z}/{x}/{y}.png',null) as url, 'raster' as service, group_id,
|
|
40
63
|
null as popup, null as card, null as filters, source_path
|
|
41
|
-
from gis.rasters s where is_active and
|
|
64
|
+
from gis.rasters s where is_active and
|
|
65
|
+
${whereRasters}
|
|
42
66
|
union all
|
|
43
67
|
select cartocss_id as id, name, null as category, style, geom::box2d as bbox, st_asgeojson(geom)::json as geom,
|
|
44
|
-
|
|
45
|
-
null as popup, null as card, null as filters, source_path
|
|
46
|
-
from gis.cartocss where enabled and
|
|
68
|
+
coalesce('/api/gis-rtile/'||cartocss_id||'/{z}/{x}/{y}.png',null) as url, 'cartocss' as service, group_id,
|
|
69
|
+
null as popup, null as card, null as filters, null as source_path
|
|
70
|
+
from gis.cartocss s where enabled and
|
|
71
|
+
${whereCartocss}
|
|
72
|
+
)q order by q.name
|
|
47
73
|
`;
|
|
48
74
|
|
|
49
75
|
if (user.uid && sql) return q;
|
|
50
76
|
|
|
51
|
-
const rows = await pg.query(q).then(el => el.rows || []);
|
|
77
|
+
const rows = await pg.query(q, (user.uid && !all_layers) ? [layer_list] : []).then(el => el.rows || []);
|
|
52
78
|
|
|
53
79
|
const totals = pg.queryCache ? await pg.queryCache('select json_object_agg(oid::regclass, reltuples) from pg_class')
|
|
54
80
|
.then(el => el.rows?.[0]?.json_object_agg || {}) : {};
|
|
@@ -12,7 +12,7 @@ function getLayerTableQuery({
|
|
|
12
12
|
gcol: geom = 'geom', table, pk = pg.pk[el.table], query: tableQuery, srid, columns,
|
|
13
13
|
} = el;
|
|
14
14
|
const step = srids.length && srids.includes(srid - 0) && srid !== 4326 ? 10 : 0.001;
|
|
15
|
-
|
|
15
|
+
const q = `SELECT
|
|
16
16
|
${pk} as "id"
|
|
17
17
|
,'${el.key}' as "key"
|
|
18
18
|
${nogeom ? '' : `,st_asgeojson(${srid !== 4326 ? `st_transform(${geom}, 4326)` : geom})::json as geom`}, ${srid !== 4326 ? `st_transform(${geom}, 4326)` : geom}::box2d as box2d, ${columns ? `row_to_json(t)` : 'null'} as "data"
|
|
@@ -26,6 +26,7 @@ and ${point ? `case
|
|
|
26
26
|
then st_distance(${srid !== 4326 ? `st_transform(${geom}, 4326)` : geom},'${point}') < ${step}
|
|
27
27
|
else false end` : `${id ? `${pk}='${id.replace(/'/g, "")}'` : '2=2'}`
|
|
28
28
|
} ${point ? 'order by distance' : ''} limit 1`;
|
|
29
|
+
return q;
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
async function getLayersData({
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export default async function catalogPermissionsEdit(req, reply) {
|
|
2
|
+
const { pg, params, body } = req;
|
|
3
|
+
const { uid } = params;
|
|
4
|
+
if (!uid) return reply.status(403).send({ status: 403, message: 'access restricted' });
|
|
5
|
+
if (!body?.length) return reply.status(400).send({ status: 400, message: 'body is empty' });
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
await pg.one(`delete from gis.services_users_rel where user_id = $1`, [uid]);
|
|
9
|
+
|
|
10
|
+
const sql = [];
|
|
11
|
+
body.map(el => {
|
|
12
|
+
const insertSql = `('${el?.service_id}','${uid}','${uid}',${(el?.actions?.length) ? `'{${el?.actions?.map(action => `"${action}"`)}}'::text[]` : 'null'})`;
|
|
13
|
+
sql.push(insertSql);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
await pg.query(`insert into gis.services_users_rel (service_id,user_id,created_by,actions) values ${sql?.join(',')}`);
|
|
17
|
+
return reply.status(201).send({ status: 201, message: `Inserted ${body?.length} permissions` });
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
return reply.status(500).send({ status: 500, message: err.toString() });
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export default async function catalogPermissions(req, reply) {
|
|
2
|
+
const { pg, params } = req;
|
|
3
|
+
const { uid } = params;
|
|
4
|
+
if (!uid) return reply.status(403).send({ status: 403, message: 'access restricted' });
|
|
5
|
+
const { total, layer_list } = await pg.one(
|
|
6
|
+
`select count(*)::int as total,array_agg(json_build_object('service_id',service_id,'actions',actions)) as layer_list from gis.services_users_rel where user_id=$1`, [uid]);
|
|
7
|
+
return reply.status(200).send({ status: 200, total, layer_list })
|
|
8
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import getPermissions from './utils/get.permissions.js';
|
|
2
|
+
|
|
3
|
+
export default async function gisCatalog(req, reply) {
|
|
4
|
+
const { pg, user } = req;
|
|
5
|
+
|
|
6
|
+
if (!user?.uid) return reply.status(403).send({ status: 403, message: 'access restricted' });
|
|
7
|
+
|
|
8
|
+
// permissions
|
|
9
|
+
const { all_layers, group_list, layer_list } = await getPermissions({ pg, uid: user.uid });
|
|
10
|
+
if (!all_layers && !group_list?.length && !layer_list?.length) {
|
|
11
|
+
return reply.status(200).send({
|
|
12
|
+
status: 204, categoriesCount: 0, layersCount: 0, servicesCount: 0, rastersCount: 0, categories: [], layers: [],
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// groups
|
|
17
|
+
const selectCategories = `select group_id as category_id, group_name as name, icon from gis.group_list where enabled and ${all_layers ? '$1' : 'group_id = any($1)'}`;
|
|
18
|
+
const { rows: categories } = await pg.query(selectCategories, [all_layers ? true : group_list]);
|
|
19
|
+
const categoriesCount = categories?.length || 0;
|
|
20
|
+
|
|
21
|
+
// services
|
|
22
|
+
const selectLayers = `
|
|
23
|
+
select
|
|
24
|
+
service_id as layer_id,
|
|
25
|
+
group_id as category_id,
|
|
26
|
+
name,
|
|
27
|
+
service_type,
|
|
28
|
+
source_path,
|
|
29
|
+
geom_type /*,
|
|
30
|
+
style,
|
|
31
|
+
popup,
|
|
32
|
+
card,
|
|
33
|
+
bi,
|
|
34
|
+
legend,
|
|
35
|
+
attributes,
|
|
36
|
+
popup*/
|
|
37
|
+
from gis.services
|
|
38
|
+
where is_active and
|
|
39
|
+
${all_layers ? '$1' : 'service_id = any($1)'}`;
|
|
40
|
+
const { rows: services } = await pg.query(selectLayers, [all_layers ? true : layer_list]);
|
|
41
|
+
const servicesCount = services?.length || 0;
|
|
42
|
+
|
|
43
|
+
// ogc services
|
|
44
|
+
const selectOgcServices = `select ogc_service_id as layer_id,group_id as category_id,name,service as service_type,url,html from gis.ogc_service where enabled and ${all_layers ? '$1' : 'ogc_service_id = any($1)'}`;
|
|
45
|
+
const { rows: ogcServices } = await pg.query(selectOgcServices, [all_layers ? true : layer_list]);
|
|
46
|
+
const ogcServicesCount = ogcServices?.length || 0;
|
|
47
|
+
|
|
48
|
+
// rasters
|
|
49
|
+
const selectRasters = `select raster_id as layer_id, group_id as category_id,name,'raster' as service_type,source_path from gis.rasters where enabled and ${all_layers ? '$1' : 'raster_id = any($1)'}`;
|
|
50
|
+
const { rows: rasters } = await pg.query(selectRasters, [all_layers ? true : layer_list]);
|
|
51
|
+
const rastersCount = rasters?.length || 0;
|
|
52
|
+
|
|
53
|
+
// cartocss
|
|
54
|
+
const selectCartocss = `select cartocss_id as layer_id, group_id as category_id,name,'cartocss' as service_type,config from gis.cartocss where enabled and ${all_layers ? '$1' : 'cartocss_id = any($1)'}`;
|
|
55
|
+
const { rows: cartocss } = await pg.query(selectCartocss, [all_layers ? true : layer_list]);
|
|
56
|
+
const cartocssCount = cartocss?.length || 0;
|
|
57
|
+
|
|
58
|
+
const layers = [
|
|
59
|
+
...services,
|
|
60
|
+
...ogcServices,
|
|
61
|
+
...rasters,
|
|
62
|
+
...cartocss,
|
|
63
|
+
];
|
|
64
|
+
const layersCount = layers?.length || 0;
|
|
65
|
+
|
|
66
|
+
const res = {
|
|
67
|
+
categoriesCount,
|
|
68
|
+
layersCount,
|
|
69
|
+
servicesCount,
|
|
70
|
+
ogcServicesCount,
|
|
71
|
+
rastersCount,
|
|
72
|
+
cartocssCount,
|
|
73
|
+
categories,
|
|
74
|
+
layers,
|
|
75
|
+
|
|
76
|
+
};
|
|
77
|
+
const statusCode = (!layersCount && !categoriesCount) ? 204 : 200;
|
|
78
|
+
|
|
79
|
+
return reply.status(statusCode).send(res);
|
|
80
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export default async function getPermissions({ pg, uid }) {
|
|
2
|
+
if (!uid) return { all_layers: false, group_list: [] };
|
|
3
|
+
const selectPermissions = `
|
|
4
|
+
select
|
|
5
|
+
case when a.user_type='admin' then true else a.all_layers end as all_layers,
|
|
6
|
+
b.layer_list,
|
|
7
|
+
c.group_list
|
|
8
|
+
from admin.users a
|
|
9
|
+
left join lateral (
|
|
10
|
+
select array_agg(service_id) as layer_list
|
|
11
|
+
from gis.services_users_rel
|
|
12
|
+
where user_id = a.uid
|
|
13
|
+
) b on true
|
|
14
|
+
left join lateral (
|
|
15
|
+
select
|
|
16
|
+
array_agg(distinct group_id) as group_list
|
|
17
|
+
from
|
|
18
|
+
(
|
|
19
|
+
select
|
|
20
|
+
group_id
|
|
21
|
+
from gis.services
|
|
22
|
+
where is_public and is_active
|
|
23
|
+
and service_id = any(b.layer_list)
|
|
24
|
+
union all
|
|
25
|
+
select
|
|
26
|
+
group_id
|
|
27
|
+
from gis.ogc_service
|
|
28
|
+
where enabled and
|
|
29
|
+
ogc_service_id = any(b.layer_list)
|
|
30
|
+
)q
|
|
31
|
+
where group_id in (
|
|
32
|
+
select group_id
|
|
33
|
+
from gis.group_list
|
|
34
|
+
where enabled
|
|
35
|
+
)
|
|
36
|
+
) c on true
|
|
37
|
+
where a.uid = $1
|
|
38
|
+
limit 1
|
|
39
|
+
`;
|
|
40
|
+
const { all_layers, group_list, layer_list } = await pg.query(selectPermissions, [uid]).then(el => el?.rows?.[0] || {});
|
|
41
|
+
|
|
42
|
+
return { all_layers, group_list, layer_list };
|
|
43
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import catalogPermissions from './controllers/catalog.permissions.js';
|
|
2
|
+
import catalogPermissionsEdit from './controllers/catalog.permissions.edit.js';
|
|
3
|
+
import gisCatalog from './controllers/gis.catalog.js';
|
|
4
|
+
|
|
5
|
+
export default async function route(fastify) {
|
|
6
|
+
if (!fastify.hasRoute({ method: 'GET', url: '/api/catalog' })) {
|
|
7
|
+
console.log('\x1b[34m%s\x1b[0m', 'add catalog from gis');
|
|
8
|
+
fastify.get('/catalog', { policy: 'L2' }, gisCatalog);
|
|
9
|
+
}
|
|
10
|
+
if (!fastify.hasRoute({ method: 'GET', url: '/api/catalog-permissions/:uid' })) {
|
|
11
|
+
console.log('\x1b[34m%s\x1b[0m', 'add catalog-permissions from gis');
|
|
12
|
+
fastify.get('/catalog-permissions/:uid', { policy: 'L2' }, catalogPermissions);
|
|
13
|
+
}
|
|
14
|
+
if (!fastify.hasRoute({ method: 'POST', url: '/api/catalog-permissions/:uid' })) {
|
|
15
|
+
console.log('\x1b[34m%s\x1b[0m', 'add catalog-permissions-edit from gis');
|
|
16
|
+
fastify.post('/catalog-permissions/:uid', { policy: 'L2' }, catalogPermissionsEdit);
|
|
17
|
+
}
|
|
18
|
+
}
|