emilsoftware-utilities 1.8.0-dev.1 → 2.0.0-dev.1
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/README.MD +4 -0
- package/dist/Utilities.d.ts +18 -0
- package/dist/Utilities.js +90 -1
- package/dist/Utilities.js.map +1 -1
- package/dist/accessi-module/AccessiModule.d.ts +15 -0
- package/dist/accessi-module/AccessiModule.js.map +1 -1
- package/dist/accessi-module/Controllers/AuthController.d.ts +4 -4
- package/dist/accessi-module/Controllers/AuthController.js +36 -21
- package/dist/accessi-module/Controllers/AuthController.js.map +1 -1
- package/dist/accessi-module/Controllers/EmailController.d.ts +3 -3
- package/dist/accessi-module/Controllers/EmailController.js +15 -15
- package/dist/accessi-module/Controllers/EmailController.js.map +1 -1
- package/dist/accessi-module/Controllers/FiltriController.d.ts +3 -3
- package/dist/accessi-module/Controllers/FiltriController.js +32 -15
- package/dist/accessi-module/Controllers/FiltriController.js.map +1 -1
- package/dist/accessi-module/Controllers/PermissionController.d.ts +12 -17
- package/dist/accessi-module/Controllers/PermissionController.js +140 -124
- package/dist/accessi-module/Controllers/PermissionController.js.map +1 -1
- package/dist/accessi-module/Controllers/UserController.d.ts +12 -11
- package/dist/accessi-module/Controllers/UserController.js +112 -79
- package/dist/accessi-module/Controllers/UserController.js.map +1 -1
- package/dist/accessi-module/Dtos/AssignPermissionsToUserRequest.js +6 -0
- package/dist/accessi-module/Dtos/AssignPermissionsToUserRequest.js.map +1 -1
- package/dist/accessi-module/Dtos/AssignRolesToUserRequest.js +6 -0
- package/dist/accessi-module/Dtos/AssignRolesToUserRequest.js.map +1 -1
- package/dist/accessi-module/Dtos/Permission.js +5 -0
- package/dist/accessi-module/Dtos/Permission.js.map +1 -1
- package/dist/accessi-module/Dtos/RegisterRequest.d.ts +1 -0
- package/dist/accessi-module/Dtos/RegisterRequest.js +44 -1
- package/dist/accessi-module/Dtos/RegisterRequest.js.map +1 -1
- package/dist/accessi-module/Dtos/Role.js +13 -2
- package/dist/accessi-module/Dtos/Role.js.map +1 -1
- package/dist/accessi-module/Dtos/SetStatoRegistrazione.js +6 -0
- package/dist/accessi-module/Dtos/SetStatoRegistrazione.js.map +1 -1
- package/dist/accessi-module/Dtos/UserDto.d.ts +1 -0
- package/dist/accessi-module/Dtos/UserDto.js +66 -1
- package/dist/accessi-module/Dtos/UserDto.js.map +1 -1
- package/dist/accessi-module/Services/AuthService/AuthService.d.ts +7 -3
- package/dist/accessi-module/Services/AuthService/AuthService.js +147 -25
- package/dist/accessi-module/Services/AuthService/AuthService.js.map +1 -1
- package/dist/accessi-module/Services/EmailService/EmailService.js +33 -10
- package/dist/accessi-module/Services/EmailService/EmailService.js.map +1 -1
- package/dist/accessi-module/Services/UserService/UserService.d.ts +15 -6
- package/dist/accessi-module/Services/UserService/UserService.js +117 -84
- package/dist/accessi-module/Services/UserService/UserService.js.map +1 -1
- package/dist/accessi-module/Views/reset-password.html +39 -21
- package/dist/accessi-module/index.js +17 -3
- package/dist/accessi-module/index.js.map +1 -1
- package/dist/accessi-module/jwt/jwt.strategy.d.ts +4 -2
- package/dist/accessi-module/jwt/jwt.strategy.js +47 -19
- package/dist/accessi-module/jwt/jwt.strategy.js.map +1 -1
- package/dist/accessi-module/middleware/authenticateGen.d.ts +3 -1
- package/dist/accessi-module/middleware/authenticateGen.js +17 -11
- package/dist/accessi-module/middleware/authenticateGen.js.map +1 -1
- package/dist/accessi-module/security/accessControl.d.ts +17 -0
- package/dist/accessi-module/security/accessControl.js +44 -0
- package/dist/accessi-module/security/accessControl.js.map +1 -0
- package/dist/accessi-module/security/authenticatedToken.d.ts +11 -0
- package/dist/accessi-module/security/authenticatedToken.js +39 -0
- package/dist/accessi-module/security/authenticatedToken.js.map +1 -0
- package/dist/accessi-module/security/passwordResetToken.d.ts +8 -0
- package/dist/accessi-module/security/passwordResetToken.js +73 -0
- package/dist/accessi-module/security/passwordResetToken.js.map +1 -0
- package/dist/accessi-module/security/publicAuthRateLimit.d.ts +10 -0
- package/dist/accessi-module/security/publicAuthRateLimit.js +105 -0
- package/dist/accessi-module/security/publicAuthRateLimit.js.map +1 -0
- package/dist/emilsoftware-utilities-2.0.0-dev.1.tgz +0 -0
- package/package.json +1 -1
- package/dist/emilsoftware-utilities-1.8.0-dev.1.tgz +0 -0
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { AccessiOptions } from '../../AccessiModule';
|
|
2
|
-
import { StatoRegistrazione } from '../../Dtos/StatoRegistrazione';
|
|
3
|
-
import { EmailService } from '../EmailService/EmailService';
|
|
4
2
|
import { GetUsersResult } from '../../Dtos/GetUsersResponse';
|
|
5
|
-
import { PermissionService } from '../PermissionService/PermissionService';
|
|
6
|
-
import { UserDto } from '../../Dtos';
|
|
7
3
|
import { RegisterRequest } from '../../Dtos/RegisterRequest';
|
|
4
|
+
import { StatoRegistrazione } from '../../Dtos/StatoRegistrazione';
|
|
5
|
+
import { UserDto } from '../../Dtos/UserDto';
|
|
6
|
+
import { AccessiAuthenticatedUserSnapshot } from '../../security/authenticatedToken';
|
|
7
|
+
import { EmailService } from '../EmailService/EmailService';
|
|
8
8
|
import { FiltriService } from '../FiltriService/FiltriService';
|
|
9
|
+
import { PermissionService } from '../PermissionService/PermissionService';
|
|
9
10
|
export declare class UserService {
|
|
10
11
|
private readonly accessiOptions;
|
|
11
12
|
private readonly emailService;
|
|
12
13
|
private readonly permissionService;
|
|
13
14
|
private readonly filtriService;
|
|
14
15
|
constructor(accessiOptions: AccessiOptions, emailService: EmailService, permissionService: PermissionService, filtriService: FiltriService);
|
|
16
|
+
private normalizeDatabaseBoolean;
|
|
17
|
+
private normalizeEmail;
|
|
18
|
+
private ensureEmailIsAvailable;
|
|
15
19
|
isAdminConfigurator(codiceUtente: number): Promise<boolean>;
|
|
20
|
+
getAuthenticatedUserSnapshot(codiceUtente: number): Promise<AccessiAuthenticatedUserSnapshot | null>;
|
|
16
21
|
getUsers(filters?: {
|
|
17
22
|
email?: string;
|
|
18
23
|
codiceUtente?: number;
|
|
@@ -26,8 +31,12 @@ export declare class UserService {
|
|
|
26
31
|
getUserByEmail(email: string): Promise<UserDto | null>;
|
|
27
32
|
insertUserFilters(codiceUtente: number, filterData: RegisterRequest): Promise<void>;
|
|
28
33
|
private executeInTransaction;
|
|
29
|
-
register(registrationData: RegisterRequest
|
|
30
|
-
|
|
34
|
+
register(registrationData: RegisterRequest, options?: {
|
|
35
|
+
allowPrivilegedFields?: boolean;
|
|
36
|
+
}): Promise<number>;
|
|
37
|
+
updateUser(codiceUtente: number, user: UserDto, options?: {
|
|
38
|
+
allowPrivilegedChanges?: boolean;
|
|
39
|
+
}): Promise<void>;
|
|
31
40
|
updateUserFilters(codiceUtente: number, user: UserDto): Promise<void>;
|
|
32
41
|
deleteUser(codiceCliente: number): Promise<void>;
|
|
33
42
|
setStato(codiceCliente: number, statoRegistrazione: StatoRegistrazione): Promise<void>;
|
|
@@ -26,11 +26,11 @@ const common_1 = require("@nestjs/common");
|
|
|
26
26
|
const autobind_1 = require("../../../autobind");
|
|
27
27
|
const Orm_1 = require("../../../Orm");
|
|
28
28
|
const Utilities_1 = require("../../../Utilities");
|
|
29
|
+
const FiltriUtente_1 = require("../../Dtos/FiltriUtente");
|
|
29
30
|
const StatoRegistrazione_1 = require("../../Dtos/StatoRegistrazione");
|
|
30
31
|
const EmailService_1 = require("../EmailService/EmailService");
|
|
31
|
-
const FiltriUtente_1 = require("../../Dtos/FiltriUtente");
|
|
32
|
-
const PermissionService_1 = require("../PermissionService/PermissionService");
|
|
33
32
|
const FiltriService_1 = require("../FiltriService/FiltriService");
|
|
33
|
+
const PermissionService_1 = require("../PermissionService/PermissionService");
|
|
34
34
|
let UserService = class UserService {
|
|
35
35
|
constructor(accessiOptions, emailService, permissionService, filtriService) {
|
|
36
36
|
this.accessiOptions = accessiOptions;
|
|
@@ -38,6 +38,25 @@ let UserService = class UserService {
|
|
|
38
38
|
this.permissionService = permissionService;
|
|
39
39
|
this.filtriService = filtriService;
|
|
40
40
|
}
|
|
41
|
+
normalizeDatabaseBoolean(value) {
|
|
42
|
+
return value === true || value === 1 || value === '1';
|
|
43
|
+
}
|
|
44
|
+
normalizeEmail(email) {
|
|
45
|
+
if (typeof email !== 'string' || email.trim() === '') {
|
|
46
|
+
throw new Error("L'email e' obbligatoria.");
|
|
47
|
+
}
|
|
48
|
+
return email.trim().toLowerCase();
|
|
49
|
+
}
|
|
50
|
+
ensureEmailIsAvailable(email, currentUserCode) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, 'SELECT FIRST 1 CODUTE as codice_utente FROM UTENTI WHERE LOWER(USRNAME) = ?', [email]);
|
|
53
|
+
const existingUser = result.map(Utilities_1.RestUtilities.convertKeysToCamelCase)[0];
|
|
54
|
+
if ((existingUser === null || existingUser === void 0 ? void 0 : existingUser.codiceUtente) &&
|
|
55
|
+
(!currentUserCode || existingUser.codiceUtente !== currentUserCode)) {
|
|
56
|
+
throw new Error("Questa e-mail e' gia stata utilizzata!");
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
41
60
|
isAdminConfigurator(codiceUtente) {
|
|
42
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
43
62
|
var _a;
|
|
@@ -57,6 +76,35 @@ let UserService = class UserService {
|
|
|
57
76
|
return flagValue === 1;
|
|
58
77
|
});
|
|
59
78
|
}
|
|
79
|
+
getAuthenticatedUserSnapshot(codiceUtente) {
|
|
80
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
+
if (!codiceUtente || codiceUtente <= 0) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
const result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, `
|
|
85
|
+
SELECT
|
|
86
|
+
U.CODUTE AS codice_utente,
|
|
87
|
+
U.USRNAME AS email,
|
|
88
|
+
U.STAREG AS stato_registrazione,
|
|
89
|
+
C.FLGSUPER AS flag_super,
|
|
90
|
+
C.FLGADMINCONFIG AS flag_admin_configurator
|
|
91
|
+
FROM UTENTI U
|
|
92
|
+
LEFT JOIN UTENTI_CONFIG C ON C.CODUTE = U.CODUTE
|
|
93
|
+
WHERE U.CODUTE = ?
|
|
94
|
+
`, [codiceUtente]);
|
|
95
|
+
const user = result.map(Utilities_1.RestUtilities.convertKeysToCamelCase)[0];
|
|
96
|
+
if (!(user === null || user === void 0 ? void 0 : user.codiceUtente)) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
codiceUtente: Number(user.codiceUtente),
|
|
101
|
+
email: typeof user.email === 'string' ? user.email : undefined,
|
|
102
|
+
statoRegistrazione: Number(user.statoRegistrazione),
|
|
103
|
+
flagSuper: this.normalizeDatabaseBoolean(user.flagSuper),
|
|
104
|
+
flagAdminConfigurator: this.normalizeDatabaseBoolean(user.flagAdminConfigurator),
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
}
|
|
60
108
|
getUsers(filters, options) {
|
|
61
109
|
return __awaiter(this, void 0, void 0, function* () {
|
|
62
110
|
try {
|
|
@@ -81,6 +129,7 @@ let UserService = class UserService {
|
|
|
81
129
|
G.PAGDEF as pagina_default,
|
|
82
130
|
G.JSON_METADATA as json_metadata,
|
|
83
131
|
G.RAGSOCCLI as rag_soc_cli,
|
|
132
|
+
G.NUMMAC as nummac,
|
|
84
133
|
F.NUMREP AS num_rep,
|
|
85
134
|
F.IDXPERS AS idx_pers,
|
|
86
135
|
F.CODCLISUPER AS cod_cli_super,
|
|
@@ -94,40 +143,37 @@ let UserService = class UserService {
|
|
|
94
143
|
LEFT JOIN FILTRI F ON F.CODUTE = U.CODUTE
|
|
95
144
|
WHERE 1=1
|
|
96
145
|
`;
|
|
97
|
-
|
|
98
|
-
if (filters.email) {
|
|
146
|
+
const queryParams = [];
|
|
147
|
+
if (filters === null || filters === void 0 ? void 0 : filters.email) {
|
|
99
148
|
query += ` AND LOWER(U.USRNAME) = ? `;
|
|
100
149
|
queryParams.push(filters.email.trim().toLowerCase());
|
|
101
150
|
}
|
|
102
|
-
if (filters.codiceUtente) {
|
|
151
|
+
if (filters === null || filters === void 0 ? void 0 : filters.codiceUtente) {
|
|
103
152
|
query += ` AND U.CODUTE = ? `;
|
|
104
153
|
queryParams.push(filters.codiceUtente);
|
|
105
154
|
}
|
|
106
155
|
query += ` ORDER BY U.CODUTE DESC `;
|
|
107
156
|
let users = (yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, queryParams));
|
|
108
157
|
users = users.map(Utilities_1.RestUtilities.convertKeysToCamelCase);
|
|
109
|
-
|
|
110
|
-
console.log('OPTIONS: ', options);
|
|
158
|
+
const usersResponse = [];
|
|
111
159
|
for (const user of users) {
|
|
112
160
|
let userGrants = null;
|
|
113
|
-
if (options.includeGrants)
|
|
161
|
+
if (options === null || options === void 0 ? void 0 : options.includeGrants) {
|
|
114
162
|
userGrants = yield this.permissionService.getUserRolesAndGrants(user.codiceUtente);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (options.includeExtensionFields) {
|
|
163
|
+
}
|
|
164
|
+
let extensionFields = (options === null || options === void 0 ? void 0 : options.includeExtensionFields) ? {} : null;
|
|
165
|
+
if ((options === null || options === void 0 ? void 0 : options.includeExtensionFields) && this.accessiOptions.extensionFieldsOptions) {
|
|
118
166
|
for (const ext of this.accessiOptions.extensionFieldsOptions) {
|
|
119
167
|
const values = (yield Orm_1.Orm.query(ext.databaseOptions, `SELECT ${ext.tableFields.join(',')} FROM ${ext.tableName} WHERE ${ext.tableJoinFieldName} = ?`, [user.codiceUtente])).map(Utilities_1.RestUtilities.convertKeysToCamelCase);
|
|
120
168
|
extensionFields[ext.objectKey] = values;
|
|
121
169
|
}
|
|
122
170
|
}
|
|
123
|
-
|
|
171
|
+
usersResponse.push({
|
|
124
172
|
utente: user,
|
|
125
|
-
userGrants
|
|
126
|
-
extensionFields
|
|
127
|
-
};
|
|
128
|
-
usersResponse.push(userResult);
|
|
173
|
+
userGrants,
|
|
174
|
+
extensionFields,
|
|
175
|
+
});
|
|
129
176
|
}
|
|
130
|
-
console.log('OPTIONS: ', options);
|
|
131
177
|
return usersResponse;
|
|
132
178
|
}
|
|
133
179
|
catch (error) {
|
|
@@ -168,6 +214,7 @@ let UserService = class UserService {
|
|
|
168
214
|
C.FLGSUPER AS flag_super,
|
|
169
215
|
C.FLGADMINCONFIG AS flag_admin_configurator,
|
|
170
216
|
C.PAGDEF AS pagina_default,
|
|
217
|
+
C.NUMMAC AS nummac,
|
|
171
218
|
C.RAGSOCCLI AS rag_soc_cli
|
|
172
219
|
FROM UTENTI U
|
|
173
220
|
INNER JOIN UTENTI_CONFIG C ON C.CODUTE = U.CODUTE
|
|
@@ -181,7 +228,6 @@ let UserService = class UserService {
|
|
|
181
228
|
if (utenti.length > 0 && filtriUtente.length > 0) {
|
|
182
229
|
const user = utenti[0];
|
|
183
230
|
const filtro = filtriUtente[0];
|
|
184
|
-
// Type-safe mapping using type assertion
|
|
185
231
|
Object.entries(FiltriUtente_1.FILTRI_UTENTE_DB_MAPPING).forEach(([key]) => {
|
|
186
232
|
if (key in filtro) {
|
|
187
233
|
user[key] = filtro[key];
|
|
@@ -191,25 +237,6 @@ let UserService = class UserService {
|
|
|
191
237
|
return utenti.length > 0 ? utenti[0] : null;
|
|
192
238
|
});
|
|
193
239
|
}
|
|
194
|
-
// async getUserFilters(codiceUtente: number): Promise<FiltriUtente[]> {
|
|
195
|
-
// const query = `
|
|
196
|
-
// SELECT
|
|
197
|
-
// F.PROG AS progressivo,
|
|
198
|
-
// F.NUMREP AS numero_report,
|
|
199
|
-
// F.IDXPERS AS indice_personale,
|
|
200
|
-
// F.CODCLISUPER AS codice_cliente_super,
|
|
201
|
-
// F.CODAGE AS cod_age,
|
|
202
|
-
// F.CODCLICOL AS codice_cliente_collegato,
|
|
203
|
-
// F.CODCLIENTI AS codice_clienti,
|
|
204
|
-
// F.TIPFIL AS tipo_filtro,
|
|
205
|
-
// F.IDXPOS AS idx_postazione
|
|
206
|
-
// FROM FILTRI F
|
|
207
|
-
// WHERE F.CODUTE = ?
|
|
208
|
-
// `;
|
|
209
|
-
// return (await Orm.query(this.accessiOptions.databaseOptions, query, [codiceUtente]).then(
|
|
210
|
-
// (results) => results.map(RestUtilities.convertKeysToCamelCase),
|
|
211
|
-
// )) as FiltriUtente[];
|
|
212
|
-
// }
|
|
213
240
|
insertUserFilters(codiceUtente, filterData) {
|
|
214
241
|
return __awaiter(this, void 0, void 0, function* () {
|
|
215
242
|
try {
|
|
@@ -263,18 +290,24 @@ let UserService = class UserService {
|
|
|
263
290
|
yield operation();
|
|
264
291
|
});
|
|
265
292
|
}
|
|
266
|
-
register(registrationData) {
|
|
293
|
+
register(registrationData, options) {
|
|
267
294
|
return __awaiter(this, void 0, void 0, function* () {
|
|
268
295
|
var _a, _b, _c;
|
|
269
296
|
try {
|
|
270
|
-
const
|
|
271
|
-
|
|
272
|
-
|
|
297
|
+
const allowPrivilegedFields = (options === null || options === void 0 ? void 0 : options.allowPrivilegedFields) === true;
|
|
298
|
+
const normalizedEmail = this.normalizeEmail(registrationData.email);
|
|
299
|
+
if (!allowPrivilegedFields &&
|
|
300
|
+
(registrationData.flagSuper !== undefined ||
|
|
301
|
+
registrationData.flagAdminConfigurator !== undefined ||
|
|
302
|
+
registrationData.roles !== undefined ||
|
|
303
|
+
registrationData.permissions !== undefined)) {
|
|
304
|
+
throw new Error('I campi privilegiati non sono consentiti nella registrazione pubblica.');
|
|
273
305
|
}
|
|
306
|
+
yield this.ensureEmailIsAvailable(normalizedEmail);
|
|
274
307
|
const queryUtenti = `INSERT INTO UTENTI (USRNAME, STAREG) VALUES (?,?)`;
|
|
275
|
-
const paramsUtenti = [
|
|
308
|
+
const paramsUtenti = [normalizedEmail, StatoRegistrazione_1.StatoRegistrazione.INVIO];
|
|
276
309
|
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, queryUtenti, paramsUtenti);
|
|
277
|
-
const codiceUtenteResult = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, 'SELECT FIRST 1 CODUTE FROM UTENTI WHERE USRNAME = ? ORDER BY CODUTE DESC', [
|
|
310
|
+
const codiceUtenteResult = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, 'SELECT FIRST 1 CODUTE FROM UTENTI WHERE USRNAME = ? ORDER BY CODUTE DESC', [normalizedEmail]);
|
|
278
311
|
const codiceUtente = Number((_b = (_a = codiceUtenteResult === null || codiceUtenteResult === void 0 ? void 0 : codiceUtenteResult[0]) === null || _a === void 0 ? void 0 : _a.CODUTE) !== null && _b !== void 0 ? _b : (_c = codiceUtenteResult === null || codiceUtenteResult === void 0 ? void 0 : codiceUtenteResult[0]) === null || _c === void 0 ? void 0 : _c.codute);
|
|
279
312
|
if (!codiceUtente) {
|
|
280
313
|
throw new Error('Creazione utente non riuscita: impossibile recuperare CODUTE.');
|
|
@@ -282,32 +315,12 @@ let UserService = class UserService {
|
|
|
282
315
|
const utentiConfigFields = ['CODUTE', 'COGNOME', 'NOME'];
|
|
283
316
|
const utentiConfigPlaceholders = ['?', '?', '?'];
|
|
284
317
|
const utentiConfigParams = [codiceUtente, registrationData.cognome, registrationData.nome];
|
|
285
|
-
// Mapping dei campi opzionali
|
|
286
|
-
// const optionalFields: [keyof typeof registrationData, string][] = [
|
|
287
|
-
// ['cellulare', 'CELLULARE'],
|
|
288
|
-
// ['flagSuper', 'FLGSUPER'],
|
|
289
|
-
// ['flagAdminConfigurator', 'FLGADMINCONFIG'],
|
|
290
|
-
// ['avatar', 'AVATAR'],
|
|
291
|
-
// ['flagDueFattori', 'FLG2FATT'],
|
|
292
|
-
// ['paginaDefault', 'PAGDEF'],
|
|
293
|
-
// ['ragSocCli', 'RAGSOCCLI'],
|
|
294
|
-
// ];
|
|
295
318
|
const optionalFields = [
|
|
296
319
|
{
|
|
297
320
|
key: 'cellulare',
|
|
298
321
|
dbField: 'CELLULARE',
|
|
299
322
|
transform: (v) => String(v),
|
|
300
323
|
},
|
|
301
|
-
{
|
|
302
|
-
key: 'flagSuper',
|
|
303
|
-
dbField: 'FLGSUPER',
|
|
304
|
-
transform: (v) => (v ? 1 : 0),
|
|
305
|
-
},
|
|
306
|
-
{
|
|
307
|
-
key: 'flagAdminConfigurator',
|
|
308
|
-
dbField: 'FLGADMINCONFIG',
|
|
309
|
-
transform: (v) => (v ? 1 : 0),
|
|
310
|
-
},
|
|
311
324
|
{
|
|
312
325
|
key: 'avatar',
|
|
313
326
|
dbField: 'AVATAR',
|
|
@@ -323,12 +336,28 @@ let UserService = class UserService {
|
|
|
323
336
|
dbField: 'PAGDEF',
|
|
324
337
|
transform: (v) => String(v),
|
|
325
338
|
},
|
|
339
|
+
{
|
|
340
|
+
key: 'nummac',
|
|
341
|
+
dbField: 'NUMMAC',
|
|
342
|
+
transform: (v) => Number(v),
|
|
343
|
+
},
|
|
326
344
|
{
|
|
327
345
|
key: 'ragSocCli',
|
|
328
346
|
dbField: 'RAGSOCCLI',
|
|
329
347
|
transform: (v) => String(v),
|
|
330
348
|
},
|
|
331
349
|
];
|
|
350
|
+
if (allowPrivilegedFields) {
|
|
351
|
+
optionalFields.push({
|
|
352
|
+
key: 'flagSuper',
|
|
353
|
+
dbField: 'FLGSUPER',
|
|
354
|
+
transform: (v) => (v ? 1 : 0),
|
|
355
|
+
}, {
|
|
356
|
+
key: 'flagAdminConfigurator',
|
|
357
|
+
dbField: 'FLGADMINCONFIG',
|
|
358
|
+
transform: (v) => (v ? 1 : 0),
|
|
359
|
+
});
|
|
360
|
+
}
|
|
332
361
|
for (const field of optionalFields) {
|
|
333
362
|
const value = registrationData[field.key];
|
|
334
363
|
if (value !== undefined && value !== null) {
|
|
@@ -339,12 +368,13 @@ let UserService = class UserService {
|
|
|
339
368
|
}
|
|
340
369
|
const queryUtentiConfig = `INSERT INTO UTENTI_CONFIG (${utentiConfigFields.join(', ')}) VALUES (${utentiConfigPlaceholders.join(', ')})`;
|
|
341
370
|
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, queryUtentiConfig, utentiConfigParams);
|
|
342
|
-
//await this.insertUserFilters(codiceUtente, registrationData);
|
|
343
371
|
yield this.filtriService.upsertFiltriUtente(codiceUtente, registrationData);
|
|
344
|
-
if (!!registrationData.roles && registrationData.roles.length > 0) {
|
|
372
|
+
if (allowPrivilegedFields && !!registrationData.roles && registrationData.roles.length > 0) {
|
|
345
373
|
yield this.permissionService.assignRolesToUser(codiceUtente, registrationData.roles);
|
|
346
374
|
}
|
|
347
|
-
if (
|
|
375
|
+
if (allowPrivilegedFields &&
|
|
376
|
+
!!registrationData.permissions &&
|
|
377
|
+
registrationData.permissions.length > 0) {
|
|
348
378
|
yield this.permissionService.assignPermissionsToUser(codiceUtente, registrationData.permissions);
|
|
349
379
|
}
|
|
350
380
|
return codiceUtente;
|
|
@@ -354,23 +384,33 @@ let UserService = class UserService {
|
|
|
354
384
|
}
|
|
355
385
|
});
|
|
356
386
|
}
|
|
357
|
-
updateUser(codiceUtente, user) {
|
|
387
|
+
updateUser(codiceUtente, user, options) {
|
|
358
388
|
return __awaiter(this, void 0, void 0, function* () {
|
|
359
389
|
try {
|
|
360
390
|
if (!codiceUtente)
|
|
361
391
|
throw new Error('Impossibile aggiornare senza codice utente.');
|
|
362
|
-
|
|
392
|
+
const allowPrivilegedChanges = (options === null || options === void 0 ? void 0 : options.allowPrivilegedChanges) === true;
|
|
393
|
+
if (!allowPrivilegedChanges &&
|
|
394
|
+
(user.statoRegistrazione !== undefined ||
|
|
395
|
+
user.flagSuper !== undefined ||
|
|
396
|
+
user.flagAdminConfigurator !== undefined ||
|
|
397
|
+
user.roles !== undefined ||
|
|
398
|
+
user.permissions !== undefined)) {
|
|
399
|
+
throw new Error('Non e consentito modificare campi privilegiati.');
|
|
400
|
+
}
|
|
363
401
|
const utentiUpdates = [];
|
|
364
402
|
const utentiParams = [];
|
|
365
403
|
if (user.email !== undefined) {
|
|
404
|
+
const normalizedEmail = this.normalizeEmail(user.email);
|
|
405
|
+
yield this.ensureEmailIsAvailable(normalizedEmail, codiceUtente);
|
|
366
406
|
utentiUpdates.push('usrname = ?');
|
|
367
|
-
utentiParams.push(
|
|
407
|
+
utentiParams.push(normalizedEmail);
|
|
368
408
|
}
|
|
369
409
|
if (user.flagGdpr !== undefined) {
|
|
370
410
|
utentiUpdates.push('flggdpr = ?');
|
|
371
411
|
utentiParams.push(user.flagGdpr);
|
|
372
412
|
}
|
|
373
|
-
if (user.statoRegistrazione !== undefined) {
|
|
413
|
+
if (allowPrivilegedChanges && user.statoRegistrazione !== undefined) {
|
|
374
414
|
utentiUpdates.push('stareg = ?');
|
|
375
415
|
utentiParams.push(user.statoRegistrazione);
|
|
376
416
|
}
|
|
@@ -379,7 +419,6 @@ let UserService = class UserService {
|
|
|
379
419
|
utentiParams.push(codiceUtente);
|
|
380
420
|
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, queryUtenti, utentiParams);
|
|
381
421
|
}
|
|
382
|
-
// Costruzione dinamica della query per UTENTI_CONFIG
|
|
383
422
|
const utentiConfigUpdates = [];
|
|
384
423
|
const utentiConfigParams = [];
|
|
385
424
|
if (user.cognome !== undefined) {
|
|
@@ -406,11 +445,11 @@ let UserService = class UserService {
|
|
|
406
445
|
utentiConfigUpdates.push('cellulare = ?');
|
|
407
446
|
utentiConfigParams.push(user.cellulare);
|
|
408
447
|
}
|
|
409
|
-
if (user.flagSuper !== undefined) {
|
|
448
|
+
if (allowPrivilegedChanges && user.flagSuper !== undefined) {
|
|
410
449
|
utentiConfigUpdates.push('flgsuper = ?');
|
|
411
450
|
utentiConfigParams.push(user.flagSuper);
|
|
412
451
|
}
|
|
413
|
-
if (user.flagAdminConfigurator !== undefined) {
|
|
452
|
+
if (allowPrivilegedChanges && user.flagAdminConfigurator !== undefined) {
|
|
414
453
|
utentiConfigUpdates.push('flgadminconfig = ?');
|
|
415
454
|
utentiConfigParams.push(user.flagAdminConfigurator);
|
|
416
455
|
}
|
|
@@ -431,13 +470,12 @@ let UserService = class UserService {
|
|
|
431
470
|
utentiConfigParams.push(codiceUtente);
|
|
432
471
|
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, queryUtentiConfig, utentiConfigParams);
|
|
433
472
|
}
|
|
434
|
-
if (!!user.roles && user.roles.length > 0) {
|
|
473
|
+
if (allowPrivilegedChanges && !!user.roles && user.roles.length > 0) {
|
|
435
474
|
yield this.permissionService.assignRolesToUser(codiceUtente, user.roles);
|
|
436
475
|
}
|
|
437
|
-
if (!!user.permissions && user.permissions.length > 0) {
|
|
476
|
+
if (allowPrivilegedChanges && !!user.permissions && user.permissions.length > 0) {
|
|
438
477
|
yield this.permissionService.assignPermissionsToUser(codiceUtente, user.permissions);
|
|
439
478
|
}
|
|
440
|
-
//await this.updateUserFilters(codiceUtente, user);
|
|
441
479
|
yield this.filtriService.upsertFiltriUtente(codiceUtente, user);
|
|
442
480
|
}
|
|
443
481
|
catch (error) {
|
|
@@ -464,7 +502,6 @@ let UserService = class UserService {
|
|
|
464
502
|
const fieldsToUpdate = Object.entries(fieldMapping)
|
|
465
503
|
.filter(([tsField]) => {
|
|
466
504
|
const value = user[tsField];
|
|
467
|
-
// Includiamo il campo se è definito (anche se è una stringa vuota)
|
|
468
505
|
return value !== undefined && value !== null;
|
|
469
506
|
})
|
|
470
507
|
.map(([tsField, config]) => {
|
|
@@ -481,21 +518,18 @@ let UserService = class UserService {
|
|
|
481
518
|
return;
|
|
482
519
|
}
|
|
483
520
|
yield this.executeInTransaction(() => __awaiter(this, void 0, void 0, function* () {
|
|
484
|
-
// Prima verifichiamo se esiste il record
|
|
485
521
|
const checkQuery = `SELECT COUNT(*) as CNT FROM FILTRI WHERE CODUTE = ?`;
|
|
486
522
|
const existingRecord = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, checkQuery, [
|
|
487
523
|
codiceUtente,
|
|
488
524
|
]);
|
|
489
525
|
const exists = existingRecord[0].CNT > 0;
|
|
490
526
|
if (exists) {
|
|
491
|
-
// Se esiste, facciamo l'UPDATE
|
|
492
527
|
const updates = fieldsToUpdate.map((f) => `${f.dbField} = ?`).join(', ');
|
|
493
528
|
const values = [...fieldsToUpdate.map((f) => f.value), codiceUtente];
|
|
494
529
|
const updateQuery = `UPDATE FILTRI SET ${updates} WHERE CODUTE = ?`;
|
|
495
530
|
yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, updateQuery, values);
|
|
496
531
|
}
|
|
497
532
|
else {
|
|
498
|
-
// Se non esiste, facciamo l'INSERT
|
|
499
533
|
const dbFields = ['CODUTE', ...fieldsToUpdate.map((f) => f.dbField)];
|
|
500
534
|
const placeholders = dbFields.map(() => '?');
|
|
501
535
|
const insertValues = [codiceUtente, ...fieldsToUpdate.map((f) => f.value)];
|
|
@@ -540,10 +574,9 @@ let UserService = class UserService {
|
|
|
540
574
|
setGdpr(codiceUtente) {
|
|
541
575
|
return __awaiter(this, void 0, void 0, function* () {
|
|
542
576
|
try {
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
return result;
|
|
577
|
+
const query = ` UPDATE OR INSERT UTENTI_GDPR SET CODUTE = ?, GDPR = ? `;
|
|
578
|
+
const params = [codiceUtente, true];
|
|
579
|
+
return yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, query, params);
|
|
547
580
|
}
|
|
548
581
|
catch (error) {
|
|
549
582
|
throw error;
|