@opengis/fastify-table 2.4.1 → 2.4.2

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.
Files changed (82) hide show
  1. package/README.md +86 -86
  2. package/dist/functions.js +20 -20
  3. package/dist/module/core/cls/constraint_action.json +9 -9
  4. package/dist/module/core/cls/constraint_matchtype.json +5 -5
  5. package/dist/module/core/cls/constraint_type_full.json +17 -17
  6. package/dist/module/core/cls/core.user_type.json +13 -13
  7. package/dist/module/core/pt/schemaItem.pt.hbs +17 -17
  8. package/dist/script/adduser +14 -14
  9. package/dist/script/dump.js +48 -48
  10. package/dist/script/dump.ts +216 -216
  11. package/dist/script/migrate.ts +41 -41
  12. package/dist/server/helpers/core/badge.js +1 -1
  13. package/dist/server/helpers/list/descriptionList.js +8 -8
  14. package/dist/server/helpers/list/tableList.js +4 -4
  15. package/dist/server/helpers/list/utils/button.js +1 -1
  16. package/dist/server/helpers/list/utils/buttonDel.js +3 -3
  17. package/dist/server/helpers/list/utils/buttonEdit.js +3 -3
  18. package/dist/server/helpers/utils/button.js +1 -1
  19. package/dist/server/helpers/utils/buttonAdd.js +15 -15
  20. package/dist/server/helpers/utils/buttonDel.js +11 -11
  21. package/dist/server/helpers/utils/buttonEdit.js +3 -3
  22. package/dist/server/migrations/0.sql +99 -99
  23. package/dist/server/migrations/cls.sql +105 -105
  24. package/dist/server/migrations/context.sql +136 -136
  25. package/dist/server/migrations/oauth.sql +79 -79
  26. package/dist/server/migrations/properties.sql +115 -115
  27. package/dist/server/migrations/roles.sql +195 -195
  28. package/dist/server/migrations/template.sql +43 -43
  29. package/dist/server/migrations/users.sql +151 -151
  30. package/dist/server/plugins/access/funcs/getUserPermissions.js +7 -7
  31. package/dist/server/plugins/auth/funcs/authorizeUser.js +4 -4
  32. package/dist/server/plugins/auth/funcs/getQuery.js +20 -20
  33. package/dist/server/plugins/crud/funcs/dataUpdate.js +7 -7
  34. package/dist/server/plugins/crud/funcs/getAccess.js +14 -14
  35. package/dist/server/plugins/crud/funcs/utils/getInsertQuery.js +6 -6
  36. package/dist/server/plugins/crud/funcs/utils/logChanges.js +18 -18
  37. package/dist/server/plugins/grpc/utils/convertp.proto +136 -136
  38. package/dist/server/plugins/grpc/utils/htmlTemplate.js +10 -10
  39. package/dist/server/plugins/grpc/utils/office2pdf.proto +13 -13
  40. package/dist/server/plugins/metric/loggerSystem.js +1 -1
  41. package/dist/server/plugins/pg/funcs/autoIndex.js +5 -5
  42. package/dist/server/plugins/pg/funcs/getMeta.js +10 -10
  43. package/dist/server/plugins/pg/funcs/init.js +36 -36
  44. package/dist/server/plugins/sqlite/funcs/init.js +22 -22
  45. package/dist/server/plugins/table/funcs/getFilterSQL/util/getCustomQuery.js +1 -1
  46. package/dist/server/plugins/table/funcs/getSelect.js +1 -1
  47. package/dist/server/plugins/table/funcs/gisIRColumn.js +3 -3
  48. package/dist/server/plugins/usercls/index.js +2 -2
  49. package/dist/server/routes/access/controllers/access.group.js +6 -6
  50. package/dist/server/routes/access/controllers/access.group.post.js +5 -5
  51. package/dist/server/routes/access/controllers/access.interface.js +14 -14
  52. package/dist/server/routes/access/controllers/access.user.js +6 -6
  53. package/dist/server/routes/auth/controllers/2factor/providers/totp.js +5 -5
  54. package/dist/server/routes/auth/controllers/2factor/qrcode.js +1 -1
  55. package/dist/server/routes/auth/controllers/2factor/recovery.js +1 -1
  56. package/dist/server/routes/auth/controllers/2factor/verify.js +1 -1
  57. package/dist/server/routes/auth/controllers/core/getUserInfo.js +33 -33
  58. package/dist/server/routes/auth/controllers/core/passwordRecovery.js +1 -1
  59. package/dist/server/routes/auth/controllers/core/registration.js +2 -2
  60. package/dist/server/routes/auth/controllers/page/login2faTemplate.js +1 -1
  61. package/dist/server/routes/file/controllers/resizeAll.js +6 -6
  62. package/dist/server/routes/grpc/controllers/file2geojson.js +13 -13
  63. package/dist/server/routes/menu/controllers/getMenu.js +9 -9
  64. package/dist/server/routes/notifications/controllers/readNotifications.js +4 -4
  65. package/dist/server/routes/notifications/controllers/userNotifications.js +3 -3
  66. package/dist/server/routes/table/controllers/card.js +1 -1
  67. package/dist/server/routes/table/controllers/filter.js +6 -6
  68. package/dist/server/routes/table/controllers/form.js +1 -1
  69. package/dist/server/routes/table/controllers/getFormByTable.js +6 -6
  70. package/dist/server/routes/table/controllers/suggest.js +3 -3
  71. package/dist/server/routes/table/controllers/tableData.js +2 -2
  72. package/dist/server/routes/table/controllers/tableInfo.js +10 -10
  73. package/dist/server/routes/table/functions/getData.js +13 -13
  74. package/dist/server/routes/widget/controllers/widget.get.js +33 -33
  75. package/dist/server/routes/widget/controllers/widget.set.js +3 -3
  76. package/dist/server/templates/page/2factor-recovery.html +101 -101
  77. package/dist/server/templates/page/2factor.html +140 -140
  78. package/dist/server/templates/page/login.html +90 -90
  79. package/dist/server/templates/page/loginEuSign.html +123 -123
  80. package/dist/server/templates/pt/recovery-codes-email-template.hbs +12 -12
  81. package/dist/server/templates/pt/recovery-password-email-template.html +20 -20
  82. package/package.json +98 -98
@@ -1,44 +1,44 @@
1
- create schema if not exists admin;
2
-
3
- -- DROP TABLE is exists admin.templates;
4
- CREATE TABLE if not exists admin.templates();
5
- ALTER TABLE admin.templates add column if not exists template_id text NOT NULL DEFAULT next_id();
6
- ALTER TABLE admin.templates DROP CONSTRAINT if exists admin_templates_template_id_pkey cascade;
7
- ALTER TABLE admin.templates DROP CONSTRAINT if exists admin_templates_name_type_unique;
8
-
9
- ALTER TABLE admin.templates add column if not exists name text;
10
- ALTER TABLE admin.templates add column if not exists title text;
11
- ALTER TABLE admin.templates add column if not exists type text;
12
- ALTER TABLE admin.templates add column if not exists category text;
13
- ALTER TABLE admin.templates add column if not exists route_id text;
14
- ALTER TABLE admin.templates add column if not exists is_active boolean;
15
- ALTER TABLE admin.templates alter column is_active set default true;
16
- ALTER TABLE admin.templates add column if not exists body text;
17
- ALTER TABLE admin.templates add column if not exists description text;
18
- ALTER TABLE admin.templates add column if not exists placeholders json;
19
- ALTER TABLE admin.templates add column if not exists version numeric;
20
-
21
- ALTER TABLE admin.templates add column if not exists created_by text;
22
- ALTER TABLE admin.templates add column if not exists created_at timestamp without time zone;
23
- ALTER TABLE admin.templates alter column created_at set DEFAULT date_trunc('seconds'::text, now());
24
- ALTER TABLE admin.templates add column if not exists updated_by text;
25
- ALTER TABLE admin.templates add column if not exists updated_at timestamp without time zone;
26
- ALTER TABLE admin.templates alter column updated_at set DEFAULT date_trunc('seconds'::text, now());
27
-
28
- ALTER TABLE admin.templates add CONSTRAINT admin_templates_template_id_pkey PRIMARY KEY (template_id);
29
- ALTER TABLE admin.templates add CONSTRAINT admin_templates_name_type_unique UNIQUE (name, type);
30
-
31
- COMMENT ON TABLE admin.templates IS 'Шаблони для друку';
32
-
33
- COMMENT ON COLUMN admin.templates.created_by IS 'ID користувача';
34
-
35
- COMMENT ON COLUMN admin.templates.name IS 'Систамна назва шаблону';
36
- COMMENT ON COLUMN admin.templates.title IS 'Назва шаблону українською';
37
- COMMENT ON COLUMN admin.templates.type IS 'Тип вихідних даних шаблону (demo/user)';
38
- COMMENT ON COLUMN admin.templates.category IS 'Категорія або тип документа';
39
- COMMENT ON COLUMN admin.templates.route_id IS 'ID інтерфейсу';
40
- COMMENT ON COLUMN admin.templates.is_active IS 'Чи доступний шаблон для використання';
41
- COMMENT ON COLUMN admin.templates.body IS 'Body HTML';
42
- COMMENT ON COLUMN admin.templates.description IS 'Короткий опис шаблону';
43
- COMMENT ON COLUMN admin.templates.placeholders IS 'Список змінних, які можна вставляти';
1
+ create schema if not exists admin;
2
+
3
+ -- DROP TABLE is exists admin.templates;
4
+ CREATE TABLE if not exists admin.templates();
5
+ ALTER TABLE admin.templates add column if not exists template_id text NOT NULL DEFAULT next_id();
6
+ ALTER TABLE admin.templates DROP CONSTRAINT if exists admin_templates_template_id_pkey cascade;
7
+ ALTER TABLE admin.templates DROP CONSTRAINT if exists admin_templates_name_type_unique;
8
+
9
+ ALTER TABLE admin.templates add column if not exists name text;
10
+ ALTER TABLE admin.templates add column if not exists title text;
11
+ ALTER TABLE admin.templates add column if not exists type text;
12
+ ALTER TABLE admin.templates add column if not exists category text;
13
+ ALTER TABLE admin.templates add column if not exists route_id text;
14
+ ALTER TABLE admin.templates add column if not exists is_active boolean;
15
+ ALTER TABLE admin.templates alter column is_active set default true;
16
+ ALTER TABLE admin.templates add column if not exists body text;
17
+ ALTER TABLE admin.templates add column if not exists description text;
18
+ ALTER TABLE admin.templates add column if not exists placeholders json;
19
+ ALTER TABLE admin.templates add column if not exists version numeric;
20
+
21
+ ALTER TABLE admin.templates add column if not exists created_by text;
22
+ ALTER TABLE admin.templates add column if not exists created_at timestamp without time zone;
23
+ ALTER TABLE admin.templates alter column created_at set DEFAULT date_trunc('seconds'::text, now());
24
+ ALTER TABLE admin.templates add column if not exists updated_by text;
25
+ ALTER TABLE admin.templates add column if not exists updated_at timestamp without time zone;
26
+ ALTER TABLE admin.templates alter column updated_at set DEFAULT date_trunc('seconds'::text, now());
27
+
28
+ ALTER TABLE admin.templates add CONSTRAINT admin_templates_template_id_pkey PRIMARY KEY (template_id);
29
+ ALTER TABLE admin.templates add CONSTRAINT admin_templates_name_type_unique UNIQUE (name, type);
30
+
31
+ COMMENT ON TABLE admin.templates IS 'Шаблони для друку';
32
+
33
+ COMMENT ON COLUMN admin.templates.created_by IS 'ID користувача';
34
+
35
+ COMMENT ON COLUMN admin.templates.name IS 'Систамна назва шаблону';
36
+ COMMENT ON COLUMN admin.templates.title IS 'Назва шаблону українською';
37
+ COMMENT ON COLUMN admin.templates.type IS 'Тип вихідних даних шаблону (demo/user)';
38
+ COMMENT ON COLUMN admin.templates.category IS 'Категорія або тип документа';
39
+ COMMENT ON COLUMN admin.templates.route_id IS 'ID інтерфейсу';
40
+ COMMENT ON COLUMN admin.templates.is_active IS 'Чи доступний шаблон для використання';
41
+ COMMENT ON COLUMN admin.templates.body IS 'Body HTML';
42
+ COMMENT ON COLUMN admin.templates.description IS 'Короткий опис шаблону';
43
+ COMMENT ON COLUMN admin.templates.placeholders IS 'Список змінних, які можна вставляти';
44
44
  COMMENT ON COLUMN admin.templates.version IS 'Версія шаблону';
@@ -1,152 +1,152 @@
1
- create schema if not exists admin;
2
-
3
- -- DROP TABLE is exists admin.users;
4
- CREATE TABLE if not exists admin.users();
5
- ALTER TABLE admin.users add column if not exists uid text NOT NULL DEFAULT next_id();
6
- ALTER TABLE admin.users DROP CONSTRAINT if exists admin_user_uid_pkey cascade;
7
- ALTER TABLE admin.users DROP CONSTRAINT if exists user_pk cascade;
8
- ALTER TABLE admin.users DROP CONSTRAINT if exists admin_user_user_rnokpp;
9
- ALTER TABLE admin.users DROP CONSTRAINT if exists admin_user_type_check;
10
-
11
- ALTER TABLE admin.users add column if not exists login text;
12
- ALTER TABLE admin.users add column if not exists password text NOT NULL DEFAULT ''::text;
13
- ALTER TABLE admin.users add column if not exists user_name text;
14
- ALTER TABLE admin.users add column if not exists sur_name text;
15
- ALTER TABLE admin.users add column if not exists father_name text;
16
- ALTER TABLE admin.users add column if not exists email text;
17
- ALTER TABLE admin.users add column if not exists phone text;
18
- ALTER TABLE admin.users add column if not exists avatar text;
19
- ALTER TABLE admin.users add column if not exists enabled boolean;
20
- ALTER TABLE admin.users add column if not exists user_personal_code text;
21
- ALTER TABLE admin.users add column if not exists last_activity_date timestamp without time zone;
22
- ALTER TABLE admin.users add column if not exists user_type text DEFAULT 'regular'::text;
23
- ALTER TABLE admin.users add column if not exists user_rnokpp text;
24
- ALTER TABLE admin.users alter column user_rnokpp drop not null;
25
- ALTER TABLE admin.users add column if not exists social_auth_id text;
26
- ALTER TABLE admin.users add column if not exists social_auth_type text;
27
- ALTER TABLE admin.users add column if not exists salt text;
28
- ALTER TABLE admin.users add column if not exists cdate timestamp without time zone DEFAULT date_trunc('seconds'::text, now());
29
- ALTER TABLE admin.users add column if not exists editor_id text;
30
- ALTER TABLE admin.users add column if not exists editor_date timestamp without time zone;
31
- ALTER TABLE admin.users add column if not exists twofa boolean not null DEFAULT true;
32
-
33
- ALTER TABLE admin.users add CONSTRAINT admin_user_uid_pkey PRIMARY KEY (uid);
34
- ALTER TABLE admin.users add CONSTRAINT admin_user_user_rnokpp UNIQUE (user_rnokpp);
35
-
36
- -- update admin.users set user_type='regular' where user_type not in ('viewer', 'regular','admin','superadmin');
37
- -- ALTER TABLE admin.users add constraint admin_user_type_check CHECK (user_type=any(array['viewer', 'regular','admin','superadmin']));
38
- insert into admin.users (uid,login,user_name,email,sur_name,password,user_type,enabled)values('viewer','viewer','viewer','viewer','viewer','viewer','viewer', false) on conflict (uid) do update set enabled=excluded.enabled, sur_name=excluded.sur_name;
39
- -- update admin.users set enabled=true where uid='viewer';
40
-
41
- COMMENT ON TABLE admin.users IS 'Користувачі';
42
-
43
- COMMENT ON COLUMN admin.users.uid IS 'ID користувача';
44
- COMMENT ON COLUMN admin.users.login IS 'Логін користувача';
45
- COMMENT ON COLUMN admin.users.password IS 'Пароль користувача';
46
- COMMENT ON COLUMN admin.users.user_name IS 'Ім''я користувача';
47
- COMMENT ON COLUMN admin.users.sur_name IS 'Прізвище користувача';
48
- COMMENT ON COLUMN admin.users.father_name IS 'По-батькові користувача';
49
- COMMENT ON COLUMN admin.users.email IS 'Ел. пошта користувача';
50
- COMMENT ON COLUMN admin.users.phone IS 'Номер телефону користувача';
51
- COMMENT ON COLUMN admin.users.avatar IS 'Аватар';
52
- COMMENT ON COLUMN admin.users.enabled IS 'On / Off';
53
- COMMENT ON COLUMN admin.users.last_activity_date IS 'Дата останньої активності';
54
- COMMENT ON COLUMN admin.users.user_type IS 'Тип користувача';
55
- COMMENT ON COLUMN admin.users.salt IS 'Сіль';
56
- COMMENT ON COLUMN admin.users.twofa IS 'Двофакторна авторизація';
57
-
58
- CREATE EXTENSION if not exists pgcrypto SCHEMA public VERSION "1.3";
59
- CREATE OR REPLACE FUNCTION admin.crypt(text, text) RETURNS text AS '$libdir/pgcrypto', 'pg_crypt' LANGUAGE c IMMUTABLE STRICT COST 1;
60
-
61
- -- DROP FUNCTION admin.insert_update_user_before();
62
- CREATE OR REPLACE FUNCTION admin.insert_update_user_before()
63
- RETURNS trigger AS
64
-
65
- $BODY$
66
- DECLARE
67
-
68
- iterations int;
69
- hash character varying;
70
-
71
- BEGIN
72
-
73
- if(TG_OP='INSERT' or (TG_OP='UPDATE' and new.password<>old.password)) then
74
- if(char_length(new.password) <> 0 and char_length(new.password) < 8) then
75
- --raise exception 'password must be longer than 8 characters';
76
- end if;
77
- new.salt=md5(now()::text);
78
- --raise exception '%','change pass';
79
- if(new.salt ='') then
80
- new.salt=gen_salt('md5');
81
- end if;
82
- iterations = 10;
83
- hash='';
84
-
85
- loop
86
- if iterations=0 then
87
- exit;
88
- end if;
89
- hash = md5(new.password||hash||new.salt);
90
- iterations=iterations-1;
91
- end loop;
92
- new.password=admin.crypt(hash,new.salt);
93
-
94
- end if;
95
- RETURN new;
96
- END
97
- $BODY$
98
-
99
- LANGUAGE plpgsql VOLATILE COST 100;
100
-
101
- DROP TRIGGER if exists insert_update_user_before on admin.users;
102
- CREATE TRIGGER insert_update_user_before BEFORE INSERT OR UPDATE ON admin.users FOR EACH ROW
103
- EXECUTE PROCEDURE admin.insert_update_user_before();
104
-
105
- -- DROP TABLE is exists admin.users_social_auth;
106
- CREATE TABLE if not exists admin.users_social_auth();
107
- ALTER TABLE admin.users_social_auth add column if not exists users_social_auth_id text NOT NULL DEFAULT next_id();
108
- ALTER TABLE admin.users_social_auth alter column users_social_auth_id set DEFAULT next_id();
109
- ALTER TABLE admin.users_social_auth DROP CONSTRAINT if exists users_social_auth_pk cascade;
110
- ALTER TABLE admin.users_social_auth DROP CONSTRAINT if exists users_social_auth_users_fk cascade;
111
- ALTER TABLE admin.users_social_auth DROP CONSTRAINT if exists users_social_auth_social_id_email_unique;
112
-
113
- ALTER TABLE admin.users_social_auth add column if not exists uid text not null;
114
- ALTER TABLE admin.users_social_auth add column if not exists user_name text;
115
- ALTER TABLE admin.users_social_auth add column if not exists sur_name text;
116
- ALTER TABLE admin.users_social_auth add column if not exists email text;
117
- ALTER TABLE admin.users_social_auth add column if not exists city text;
118
- ALTER TABLE admin.users_social_auth add column if not exists phone text;
119
- ALTER TABLE admin.users_social_auth add column if not exists social_auth_id text;
120
- ALTER TABLE admin.users_social_auth add column if not exists social_auth_type text;
121
- ALTER TABLE admin.users_social_auth add column if not exists social_auth_code text;
122
- ALTER TABLE admin.users_social_auth add column if not exists social_auth_obj json;
123
- ALTER TABLE admin.users_social_auth add column if not exists social_auth_date timestamp without time zone;
124
- ALTER TABLE admin.users_social_auth add column if not exists social_auth_softpro_code text;
125
- ALTER TABLE admin.users_social_auth add column if not exists enabled boolean;
126
- ALTER TABLE admin.users_social_auth add column if not exists cdate timestamp without time zone;
127
- ALTER TABLE admin.users_social_auth alter column cdate SET DEFAULT date_trunc('seconds'::text, now());
128
-
129
- ALTER TABLE admin.users_social_auth add column if not exists editor_id text;
130
- ALTER TABLE admin.users_social_auth add column if not exists lang text;
131
- ALTER TABLE admin.users_social_auth add column if not exists editor_date timestamp without time zone;
132
- ALTER TABLE admin.users_social_auth add column if not exists social_auth_url text;
133
- ALTER TABLE admin.users_social_auth add CONSTRAINT users_social_auth_pk PRIMARY KEY (users_social_auth_id);
134
- ALTER TABLE admin.users_social_auth add CONSTRAINT users_social_auth_users_fk FOREIGN KEY (uid) REFERENCES admin.users (uid) MATCH SIMPLE on delete cascade;
135
- ALTER TABLE admin.users_social_auth add CONSTRAINT users_social_auth_social_id_email_unique UNIQUE (social_auth_id,email);
136
-
137
- COMMENT ON COLUMN admin.users_social_auth.uid IS 'id пользователя';
138
- COMMENT ON COLUMN admin.users_social_auth.user_name IS 'Имя пользователя';
139
- COMMENT ON COLUMN admin.users_social_auth.sur_name IS 'Фамилия';
140
- COMMENT ON COLUMN admin.users_social_auth.email IS 'email пользователя';
141
- COMMENT ON COLUMN admin.users_social_auth.city IS 'Місто';
142
- COMMENT ON COLUMN admin.users_social_auth.phone IS 'Телефон';
143
- COMMENT ON COLUMN admin.users_social_auth.social_auth_id IS 'ID в соцсети';
144
- COMMENT ON COLUMN admin.users_social_auth.social_auth_type IS 'тип соцсети';
145
- COMMENT ON COLUMN admin.users_social_auth.social_auth_code IS 'код обьекта соцсети, используеться соцсетью';
146
- COMMENT ON COLUMN admin.users_social_auth.social_auth_obj IS 'обьект соцсети';
147
- COMMENT ON COLUMN admin.users_social_auth.social_auth_date IS 'время получение последнего обьекта соцсети';
148
- COMMENT ON COLUMN admin.users_social_auth.social_auth_softpro_code IS 'код обьекта соцсети, создаваемый и используемый сервером авторизации';
149
- COMMENT ON COLUMN admin.users_social_auth.enabled IS 'Выключатель';
150
- COMMENT ON COLUMN admin.users_social_auth.social_auth_url IS 'URL для QR code';
151
-
1
+ create schema if not exists admin;
2
+
3
+ -- DROP TABLE is exists admin.users;
4
+ CREATE TABLE if not exists admin.users();
5
+ ALTER TABLE admin.users add column if not exists uid text NOT NULL DEFAULT next_id();
6
+ ALTER TABLE admin.users DROP CONSTRAINT if exists admin_user_uid_pkey cascade;
7
+ ALTER TABLE admin.users DROP CONSTRAINT if exists user_pk cascade;
8
+ ALTER TABLE admin.users DROP CONSTRAINT if exists admin_user_user_rnokpp;
9
+ ALTER TABLE admin.users DROP CONSTRAINT if exists admin_user_type_check;
10
+
11
+ ALTER TABLE admin.users add column if not exists login text;
12
+ ALTER TABLE admin.users add column if not exists password text NOT NULL DEFAULT ''::text;
13
+ ALTER TABLE admin.users add column if not exists user_name text;
14
+ ALTER TABLE admin.users add column if not exists sur_name text;
15
+ ALTER TABLE admin.users add column if not exists father_name text;
16
+ ALTER TABLE admin.users add column if not exists email text;
17
+ ALTER TABLE admin.users add column if not exists phone text;
18
+ ALTER TABLE admin.users add column if not exists avatar text;
19
+ ALTER TABLE admin.users add column if not exists enabled boolean;
20
+ ALTER TABLE admin.users add column if not exists user_personal_code text;
21
+ ALTER TABLE admin.users add column if not exists last_activity_date timestamp without time zone;
22
+ ALTER TABLE admin.users add column if not exists user_type text DEFAULT 'regular'::text;
23
+ ALTER TABLE admin.users add column if not exists user_rnokpp text;
24
+ ALTER TABLE admin.users alter column user_rnokpp drop not null;
25
+ ALTER TABLE admin.users add column if not exists social_auth_id text;
26
+ ALTER TABLE admin.users add column if not exists social_auth_type text;
27
+ ALTER TABLE admin.users add column if not exists salt text;
28
+ ALTER TABLE admin.users add column if not exists cdate timestamp without time zone DEFAULT date_trunc('seconds'::text, now());
29
+ ALTER TABLE admin.users add column if not exists editor_id text;
30
+ ALTER TABLE admin.users add column if not exists editor_date timestamp without time zone;
31
+ ALTER TABLE admin.users add column if not exists twofa boolean not null DEFAULT true;
32
+
33
+ ALTER TABLE admin.users add CONSTRAINT admin_user_uid_pkey PRIMARY KEY (uid);
34
+ ALTER TABLE admin.users add CONSTRAINT admin_user_user_rnokpp UNIQUE (user_rnokpp);
35
+
36
+ -- update admin.users set user_type='regular' where user_type not in ('viewer', 'regular','admin','superadmin');
37
+ -- ALTER TABLE admin.users add constraint admin_user_type_check CHECK (user_type=any(array['viewer', 'regular','admin','superadmin']));
38
+ insert into admin.users (uid,login,user_name,email,sur_name,password,user_type,enabled)values('viewer','viewer','viewer','viewer','viewer','viewer','viewer', false) on conflict (uid) do update set enabled=excluded.enabled, sur_name=excluded.sur_name;
39
+ -- update admin.users set enabled=true where uid='viewer';
40
+
41
+ COMMENT ON TABLE admin.users IS 'Користувачі';
42
+
43
+ COMMENT ON COLUMN admin.users.uid IS 'ID користувача';
44
+ COMMENT ON COLUMN admin.users.login IS 'Логін користувача';
45
+ COMMENT ON COLUMN admin.users.password IS 'Пароль користувача';
46
+ COMMENT ON COLUMN admin.users.user_name IS 'Ім''я користувача';
47
+ COMMENT ON COLUMN admin.users.sur_name IS 'Прізвище користувача';
48
+ COMMENT ON COLUMN admin.users.father_name IS 'По-батькові користувача';
49
+ COMMENT ON COLUMN admin.users.email IS 'Ел. пошта користувача';
50
+ COMMENT ON COLUMN admin.users.phone IS 'Номер телефону користувача';
51
+ COMMENT ON COLUMN admin.users.avatar IS 'Аватар';
52
+ COMMENT ON COLUMN admin.users.enabled IS 'On / Off';
53
+ COMMENT ON COLUMN admin.users.last_activity_date IS 'Дата останньої активності';
54
+ COMMENT ON COLUMN admin.users.user_type IS 'Тип користувача';
55
+ COMMENT ON COLUMN admin.users.salt IS 'Сіль';
56
+ COMMENT ON COLUMN admin.users.twofa IS 'Двофакторна авторизація';
57
+
58
+ CREATE EXTENSION if not exists pgcrypto SCHEMA public VERSION "1.3";
59
+ CREATE OR REPLACE FUNCTION admin.crypt(text, text) RETURNS text AS '$libdir/pgcrypto', 'pg_crypt' LANGUAGE c IMMUTABLE STRICT COST 1;
60
+
61
+ -- DROP FUNCTION admin.insert_update_user_before();
62
+ CREATE OR REPLACE FUNCTION admin.insert_update_user_before()
63
+ RETURNS trigger AS
64
+
65
+ $BODY$
66
+ DECLARE
67
+
68
+ iterations int;
69
+ hash character varying;
70
+
71
+ BEGIN
72
+
73
+ if(TG_OP='INSERT' or (TG_OP='UPDATE' and new.password<>old.password)) then
74
+ if(char_length(new.password) <> 0 and char_length(new.password) < 8) then
75
+ --raise exception 'password must be longer than 8 characters';
76
+ end if;
77
+ new.salt=md5(now()::text);
78
+ --raise exception '%','change pass';
79
+ if(new.salt ='') then
80
+ new.salt=gen_salt('md5');
81
+ end if;
82
+ iterations = 10;
83
+ hash='';
84
+
85
+ loop
86
+ if iterations=0 then
87
+ exit;
88
+ end if;
89
+ hash = md5(new.password||hash||new.salt);
90
+ iterations=iterations-1;
91
+ end loop;
92
+ new.password=admin.crypt(hash,new.salt);
93
+
94
+ end if;
95
+ RETURN new;
96
+ END
97
+ $BODY$
98
+
99
+ LANGUAGE plpgsql VOLATILE COST 100;
100
+
101
+ DROP TRIGGER if exists insert_update_user_before on admin.users;
102
+ CREATE TRIGGER insert_update_user_before BEFORE INSERT OR UPDATE ON admin.users FOR EACH ROW
103
+ EXECUTE PROCEDURE admin.insert_update_user_before();
104
+
105
+ -- DROP TABLE is exists admin.users_social_auth;
106
+ CREATE TABLE if not exists admin.users_social_auth();
107
+ ALTER TABLE admin.users_social_auth add column if not exists users_social_auth_id text NOT NULL DEFAULT next_id();
108
+ ALTER TABLE admin.users_social_auth alter column users_social_auth_id set DEFAULT next_id();
109
+ ALTER TABLE admin.users_social_auth DROP CONSTRAINT if exists users_social_auth_pk cascade;
110
+ ALTER TABLE admin.users_social_auth DROP CONSTRAINT if exists users_social_auth_users_fk cascade;
111
+ ALTER TABLE admin.users_social_auth DROP CONSTRAINT if exists users_social_auth_social_id_email_unique;
112
+
113
+ ALTER TABLE admin.users_social_auth add column if not exists uid text not null;
114
+ ALTER TABLE admin.users_social_auth add column if not exists user_name text;
115
+ ALTER TABLE admin.users_social_auth add column if not exists sur_name text;
116
+ ALTER TABLE admin.users_social_auth add column if not exists email text;
117
+ ALTER TABLE admin.users_social_auth add column if not exists city text;
118
+ ALTER TABLE admin.users_social_auth add column if not exists phone text;
119
+ ALTER TABLE admin.users_social_auth add column if not exists social_auth_id text;
120
+ ALTER TABLE admin.users_social_auth add column if not exists social_auth_type text;
121
+ ALTER TABLE admin.users_social_auth add column if not exists social_auth_code text;
122
+ ALTER TABLE admin.users_social_auth add column if not exists social_auth_obj json;
123
+ ALTER TABLE admin.users_social_auth add column if not exists social_auth_date timestamp without time zone;
124
+ ALTER TABLE admin.users_social_auth add column if not exists social_auth_softpro_code text;
125
+ ALTER TABLE admin.users_social_auth add column if not exists enabled boolean;
126
+ ALTER TABLE admin.users_social_auth add column if not exists cdate timestamp without time zone;
127
+ ALTER TABLE admin.users_social_auth alter column cdate SET DEFAULT date_trunc('seconds'::text, now());
128
+
129
+ ALTER TABLE admin.users_social_auth add column if not exists editor_id text;
130
+ ALTER TABLE admin.users_social_auth add column if not exists lang text;
131
+ ALTER TABLE admin.users_social_auth add column if not exists editor_date timestamp without time zone;
132
+ ALTER TABLE admin.users_social_auth add column if not exists social_auth_url text;
133
+ ALTER TABLE admin.users_social_auth add CONSTRAINT users_social_auth_pk PRIMARY KEY (users_social_auth_id);
134
+ ALTER TABLE admin.users_social_auth add CONSTRAINT users_social_auth_users_fk FOREIGN KEY (uid) REFERENCES admin.users (uid) MATCH SIMPLE on delete cascade;
135
+ ALTER TABLE admin.users_social_auth add CONSTRAINT users_social_auth_social_id_email_unique UNIQUE (social_auth_id,email);
136
+
137
+ COMMENT ON COLUMN admin.users_social_auth.uid IS 'id пользователя';
138
+ COMMENT ON COLUMN admin.users_social_auth.user_name IS 'Имя пользователя';
139
+ COMMENT ON COLUMN admin.users_social_auth.sur_name IS 'Фамилия';
140
+ COMMENT ON COLUMN admin.users_social_auth.email IS 'email пользователя';
141
+ COMMENT ON COLUMN admin.users_social_auth.city IS 'Місто';
142
+ COMMENT ON COLUMN admin.users_social_auth.phone IS 'Телефон';
143
+ COMMENT ON COLUMN admin.users_social_auth.social_auth_id IS 'ID в соцсети';
144
+ COMMENT ON COLUMN admin.users_social_auth.social_auth_type IS 'тип соцсети';
145
+ COMMENT ON COLUMN admin.users_social_auth.social_auth_code IS 'код обьекта соцсети, используеться соцсетью';
146
+ COMMENT ON COLUMN admin.users_social_auth.social_auth_obj IS 'обьект соцсети';
147
+ COMMENT ON COLUMN admin.users_social_auth.social_auth_date IS 'время получение последнего обьекта соцсети';
148
+ COMMENT ON COLUMN admin.users_social_auth.social_auth_softpro_code IS 'код обьекта соцсети, создаваемый и используемый сервером авторизации';
149
+ COMMENT ON COLUMN admin.users_social_auth.enabled IS 'Выключатель';
150
+ COMMENT ON COLUMN admin.users_social_auth.social_auth_url IS 'URL для QR code';
151
+
152
152
  update admin.users set twofa=false where uid='1';
@@ -1,11 +1,11 @@
1
1
  import pgClients from "../../pg/pgClients.js";
2
2
  import { resourcesList } from "./getResources.js";
3
- const q = `select resource_id as name,
4
- array_intersect(coalesce(a.actions, array['read']), coalesce(c.actions, array['create', 'read', 'update', 'delete'])) as actions,
5
- b.name as role
6
- from admin.role_access a
7
- left join admin.roles b on a.role_id=b.role_id and b.enabled
8
- left join admin.user_roles c on a.role_id=c.role_id
3
+ const q = `select resource_id as name,
4
+ array_intersect(coalesce(a.actions, array['read']), coalesce(c.actions, array['create', 'read', 'update', 'delete'])) as actions,
5
+ b.name as role
6
+ from admin.role_access a
7
+ left join admin.roles b on a.role_id=b.role_id and b.enabled
8
+ left join admin.user_roles c on a.role_id=c.role_id
9
9
  where resource_id is not null and $1 in (a.user_uid, c.user_uid)`;
10
10
  export default async function getUserPermissions({ uid, resource, table, userType, }, pg = pgClients.client) {
11
11
  if (!uid)
@@ -15,7 +15,7 @@ export default async function getUserPermissions({ uid, resource, table, userTyp
15
15
  }
16
16
  // ? in case pg.pk not set yet
17
17
  const pks = await pg
18
- .query(`SELECT json_object_agg(conrelid::regclass, (SELECT attname FROM pg_attribute WHERE attrelid = c.conrelid AND attnum = c.conkey[1]) )
18
+ .query(`SELECT json_object_agg(conrelid::regclass, (SELECT attname FROM pg_attribute WHERE attrelid = c.conrelid AND attnum = c.conkey[1]) )
19
19
  FROM pg_constraint c WHERE contype = 'p' AND connamespace::regnamespace::text = 'admin'`)
20
20
  .then((el) => el.rows?.[0]?.json_object_agg || {});
21
21
  const permissions = pks["admin.role_access"] &&
@@ -83,10 +83,10 @@ export default async function authorizeUser(user, req, authType = "creds-user",
83
83
  twofaEnabled &&
84
84
  !req.session?.secondFactorPassed) {
85
85
  const verified = await pg
86
- .query(`select
87
- enabled and social_auth_url is not null as verified
88
- from admin.users_social_auth
89
- where uid = $1
86
+ .query(`select
87
+ enabled and social_auth_url is not null as verified
88
+ from admin.users_social_auth
89
+ where uid = $1
90
90
  and social_auth_type = $2`, [user.uid, "TOTP"])
91
91
  .then((el) => el.rows?.[0]?.verified || false);
92
92
  const redirect2fa = `${config.auth?.link?.["2fa"]?.login || "/2factor"}?redirect=${redirectUrl.startsWith("/") ? redirectUrl : "/"}`;
@@ -1,24 +1,24 @@
1
- const insertSocialSQL = `insert into admin.users_social_auth(uid, phone, user_name, sur_name, email, social_auth_id,
2
- social_auth_type, social_auth_date, social_auth_obj, city, enabled)
3
- select $9, $1, $2, $3, $4, $5,
4
- $6, now(), $7, $8, true
5
- on conflict(social_auth_id,email) do update set
6
- phone=excluded.phone, user_name=excluded.user_name,
7
- sur_name=excluded.sur_name, email=excluded.email, social_auth_id=excluded.social_auth_id,
8
- social_auth_type=excluded.social_auth_type, social_auth_date=excluded.social_auth_date,
1
+ const insertSocialSQL = `insert into admin.users_social_auth(uid, phone, user_name, sur_name, email, social_auth_id,
2
+ social_auth_type, social_auth_date, social_auth_obj, city, enabled)
3
+ select $9, $1, $2, $3, $4, $5,
4
+ $6, now(), $7, $8, true
5
+ on conflict(social_auth_id,email) do update set
6
+ phone=excluded.phone, user_name=excluded.user_name,
7
+ sur_name=excluded.sur_name, email=excluded.email, social_auth_id=excluded.social_auth_id,
8
+ social_auth_type=excluded.social_auth_type, social_auth_date=excluded.social_auth_date,
9
9
  social_auth_obj=excluded.social_auth_obj, city=excluded.city, enabled=excluded.enabled`;
10
- const insertUserSQL = `insert into admin.users (enabled, phone, user_name, sur_name, father_name, email, user_rnokpp)
11
- values(true, $1, $2, $3, $4, $5, $6)
12
- on conflict (user_rnokpp) do update set
13
- phone=excluded.phone,
14
- user_name=excluded.user_name,
15
- sur_name=excluded.sur_name,
16
- father_name=excluded.father_name,
17
- email=excluded.email
10
+ const insertUserSQL = `insert into admin.users (enabled, phone, user_name, sur_name, father_name, email, user_rnokpp)
11
+ values(true, $1, $2, $3, $4, $5, $6)
12
+ on conflict (user_rnokpp) do update set
13
+ phone=excluded.phone,
14
+ user_name=excluded.user_name,
15
+ sur_name=excluded.sur_name,
16
+ father_name=excluded.father_name,
17
+ email=excluded.email
18
18
  returning uid`;
19
- const updateUserSQL = `update admin.users set
20
- phone=$1, user_name=$2, sur_name=$3,
21
- father_name=coalesce($4, father_name), email=$5, social_auth_id=$6,
19
+ const updateUserSQL = `update admin.users set
20
+ phone=$1, user_name=$2, sur_name=$3,
21
+ father_name=coalesce($4, father_name), email=$5, social_auth_id=$6,
22
22
  social_auth_type=$7 where uid=$8 returning uid`;
23
23
  const deleteSocialIdSQL = `delete from admin.users_social_auth where social_auth_id=$1 or email=$2`;
24
24
  import config from "../../../../config.js";
@@ -121,7 +121,7 @@ export default async function getQuery({ pg, data, }) {
121
121
  client.release();
122
122
  }
123
123
  const result = await pg
124
- .query(`select * from admin.users where uid =(select uid from admin.users_social_auth
124
+ .query(`select * from admin.users where uid =(select uid from admin.users_social_auth
125
125
  where ${id ? "social_auth_id=$1" : "email=$1"} limit 1)`, [id || email])
126
126
  .then((el) => el.rows?.[0] || {});
127
127
  return result;
@@ -72,19 +72,19 @@ export default async function dataUpdate({ table: table1, tokenData, referer, id
72
72
  // update geometry with srid
73
73
  if (!srids[table] && pg.tlist?.includes("public.geometry_columns")) {
74
74
  const { srids1 } = await pg
75
- .query(`select json_object_agg(_table,rel) as srids1 from (
76
- select f_table_schema||'.'||f_table_name as _table,
77
- json_object_agg(f_geometry_column, case when srid = 0 then 4326 else srid end) as rel
78
- from public.geometry_columns group by f_table_schema||'.'||f_table_name
75
+ .query(`select json_object_agg(_table,rel) as srids1 from (
76
+ select f_table_schema||'.'||f_table_name as _table,
77
+ json_object_agg(f_geometry_column, case when srid = 0 then 4326 else srid end) as rel
78
+ from public.geometry_columns group by f_table_schema||'.'||f_table_name
79
79
  )q`)
80
80
  .then((el) => el.rows?.[0] || {});
81
81
  Object.assign(srids, srids1);
82
82
  }
83
- const updateQuery = `UPDATE ${table} SET ${systemColumns ? `${systemColumns}${filterData?.length ? "," : ""}` : ""}
84
-
83
+ const updateQuery = `UPDATE ${table} SET ${systemColumns ? `${systemColumns}${filterData?.length ? "," : ""}` : ""}
84
+
85
85
  ${filterData
86
86
  ?.map((key, i) => assignValue(key, i, srids[table]?.[key] || 4326, pg.pgType?.[columns.find((col) => col.name === key)?.dataTypeID || ""]))
87
- ?.join(",")}
87
+ ?.join(",")}
88
88
  WHERE ${pk}::text = $1::text returning *`;
89
89
  // console.log(updateQuery, filterValue);
90
90
  // for transactions
@@ -10,20 +10,20 @@ const matches = {
10
10
  update: "edit",
11
11
  delete: "del",
12
12
  };
13
- const q = `select a.route_id as id, d.actions as user_roles, d.actions as role_actions, coalesce(b.actions, array['view']) as interface_actions, b.scope, c.role_id
14
- from admin.routes a
15
- left join admin.role_access b on
16
- a.route_id=b.route_id
17
- left join admin.roles c on
18
- b.role_id=c.role_id
19
- and c.enabled
20
- left join admin.user_roles d on
21
- c.role_id=d.role_id
22
- and ( case when
23
- d.expiration is not null
24
- then d.expiration > CURRENT_DATE
25
- else 1=1
26
- end )
13
+ const q = `select a.route_id as id, d.actions as user_roles, d.actions as role_actions, coalesce(b.actions, array['view']) as interface_actions, b.scope, c.role_id
14
+ from admin.routes a
15
+ left join admin.role_access b on
16
+ a.route_id=b.route_id
17
+ left join admin.roles c on
18
+ b.role_id=c.role_id
19
+ and c.enabled
20
+ left join admin.user_roles d on
21
+ c.role_id=d.role_id
22
+ and ( case when
23
+ d.expiration is not null
24
+ then d.expiration > CURRENT_DATE
25
+ else 1=1
26
+ end )
27
27
  where $1 in (a.route_id, a.alias, a.table_name) and $2 in (b.user_uid, d.user_uid)`;
28
28
  /**
29
29
  * @param {Array} user_roles.actions Actions - user actions <> group actions
@@ -33,20 +33,20 @@ export default async function getInsertQuery({ pg, table, data, id, uid, }) {
33
33
  (["boolean", "number"].includes(typeof data[el]) ? true : data[el]) &&
34
34
  names.includes(el))
35
35
  .map((el) => [el, data[el]]);
36
- const insertQuery = `insert into ${table}
37
-
36
+ const insertQuery = `insert into ${table}
37
+
38
38
  ( ${filterData
39
39
  ?.map((key) => `"${key[0]}"`)
40
40
  .concat(systemColumnNames)
41
- .join(",")})
42
-
41
+ .join(",")})
42
+
43
43
  values (${filterData
44
44
  ?.map((key, i) => key[0] === "geom"
45
45
  ? `st_setsrid(st_geomfromgeojson($${i + 1}::json),4326)`
46
46
  : `$${i + 1}`)
47
47
  .concat(systemColumns.map((el) => el[1]))
48
- .join(",")})
49
-
48
+ .join(",")})
49
+
50
50
  returning *`;
51
51
  const args = [
52
52
  ...filterData.map((el) => typeof el[1] === "object" &&
@@ -62,25 +62,25 @@ export default async function logChanges({ pg, table: table1, tokenData, referer
62
62
  }
63
63
  try {
64
64
  const { change_id: changeId } = await pg
65
- .query(`insert into log.table_changes(change_date,change_type,change_user_id,entity_type,entity_id)
65
+ .query(`insert into log.table_changes(change_date,change_type,change_user_id,entity_type,entity_id)
66
66
  values(CURRENT_DATE, $1, $2, $3, $4) returning change_id`, [type, uid, table, id])
67
67
  .then((el) => el.rows?.[0] || {});
68
- const q = `select json_object_agg(entity_key, json_build_object('hash',value_hash,'value',value_new)) from (
69
- select
70
- entity_key,
71
- value_hash,
72
- value_new,
73
- ( rank() over (partition by entity_key order by cdate desc) = 1 ) as is_latest
74
- from log.table_changes_data
75
-
76
- where change_id in (
77
- select
78
- change_id
79
- from log.table_changes
80
- where entity_id=$1
81
- and entity_type=$2
82
- )
83
-
68
+ const q = `select json_object_agg(entity_key, json_build_object('hash',value_hash,'value',value_new)) from (
69
+ select
70
+ entity_key,
71
+ value_hash,
72
+ value_new,
73
+ ( rank() over (partition by entity_key order by cdate desc) = 1 ) as is_latest
74
+ from log.table_changes_data
75
+
76
+ where change_id in (
77
+ select
78
+ change_id
79
+ from log.table_changes
80
+ where entity_id=$1
81
+ and entity_type=$2
82
+ )
83
+
84
84
  )q where is_latest`;
85
85
  // console.log(q, type, id);
86
86
  const old = type !== "INSERT"
@@ -160,7 +160,7 @@ export default async function logChanges({ pg, table: table1, tokenData, referer
160
160
  const res = await Promise.all(changesData.map(async (el) => {
161
161
  const insertQuery = `insert into log.table_changes_data (${Object.entries(el)
162
162
  ?.map((key) => `"${key[0]}"`)
163
- .join(",")})
163
+ .join(",")})
164
164
  values (${Object.entries(el)
165
165
  ?.map((key, i) => `$${i + 1}`)
166
166
  .join(",")}) returning *`;