emilsoftware-utilities 1.6.1-dev.1 → 1.6.1-dev.3

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 (29) hide show
  1. package/dist/accessi-module/AccessiModule.js +10 -2
  2. package/dist/accessi-module/Controllers/AuthController.js +4 -1
  3. package/dist/accessi-module/Controllers/ConfiguratorController.d.ts +13 -0
  4. package/dist/accessi-module/Controllers/ConfiguratorController.js +153 -0
  5. package/dist/accessi-module/Controllers/PermissionController.d.ts +1 -1
  6. package/dist/accessi-module/Controllers/PermissionController.js +14 -4
  7. package/dist/accessi-module/Dtos/GetGroupsWithMenusResponse.d.ts +1 -0
  8. package/dist/accessi-module/Dtos/GetGroupsWithMenusResponse.js +8 -0
  9. package/dist/accessi-module/Dtos/GetMenusResponse.d.ts +1 -0
  10. package/dist/accessi-module/Dtos/GetMenusResponse.js +8 -0
  11. package/dist/accessi-module/Dtos/RegisterRequest.d.ts +1 -0
  12. package/dist/accessi-module/Dtos/RegisterRequest.js +7 -0
  13. package/dist/accessi-module/Dtos/UpdateEnabledStatusRequest.d.ts +3 -0
  14. package/dist/accessi-module/Dtos/UpdateEnabledStatusRequest.js +26 -0
  15. package/dist/accessi-module/Dtos/UserDto.d.ts +1 -0
  16. package/dist/accessi-module/Dtos/UserDto.js +7 -0
  17. package/dist/accessi-module/Dtos/index.d.ts +1 -0
  18. package/dist/accessi-module/Dtos/index.js +1 -0
  19. package/dist/accessi-module/Services/ConfiguratorService/ConfiguratorService.d.ts +7 -0
  20. package/dist/accessi-module/Services/ConfiguratorService/ConfiguratorService.js +53 -0
  21. package/dist/accessi-module/Services/PermissionService/PermissionService.d.ts +1 -1
  22. package/dist/accessi-module/Services/PermissionService/PermissionService.js +60 -24
  23. package/dist/accessi-module/Services/UserService/UserService.d.ts +2 -1
  24. package/dist/accessi-module/Services/UserService/UserService.js +42 -10
  25. package/dist/accessi-module/jwt/jwt.strategy.d.ts +7 -0
  26. package/dist/accessi-module/jwt/jwt.strategy.js +80 -0
  27. package/dist/emilsoftware-utilities-1.6.1-dev.3.tgz +0 -0
  28. package/package.json +1 -1
  29. package/dist/emilsoftware-utilities-1.6.1-dev.1.tgz +0 -0
@@ -19,6 +19,9 @@ const PermissionController_1 = require("./Controllers/PermissionController");
19
19
  const UserController_1 = require("./Controllers/UserController");
20
20
  const FiltriService_1 = require("./Services/FiltriService/FiltriService");
21
21
  const FiltriController_1 = require("./Controllers/FiltriController");
22
+ const ConfiguratorController_1 = require("./Controllers/ConfiguratorController");
23
+ const ConfiguratorService_1 = require("./Services/ConfiguratorService/ConfiguratorService");
24
+ const jwt_strategy_1 = require("./jwt/jwt.strategy");
22
25
  let AccessiModule = AccessiModule_1 = class AccessiModule {
23
26
  static forRoot(options) {
24
27
  return {
@@ -33,6 +36,8 @@ let AccessiModule = AccessiModule_1 = class AccessiModule {
33
36
  EmailService_1.EmailService,
34
37
  PermissionService_1.PermissionService,
35
38
  FiltriService_1.FiltriService,
39
+ ConfiguratorService_1.ConfiguratorService,
40
+ jwt_strategy_1.JwtSimpleGuard
36
41
  ],
37
42
  exports: [
38
43
  'ACCESSI_OPTIONS',
@@ -41,6 +46,8 @@ let AccessiModule = AccessiModule_1 = class AccessiModule {
41
46
  EmailService_1.EmailService,
42
47
  PermissionService_1.PermissionService,
43
48
  FiltriService_1.FiltriService,
49
+ ConfiguratorService_1.ConfiguratorService,
50
+ jwt_strategy_1.JwtSimpleGuard
44
51
  ],
45
52
  };
46
53
  }
@@ -55,8 +62,9 @@ exports.AccessiModule = AccessiModule = AccessiModule_1 = __decorate([
55
62
  PermissionController_1.PermissionController,
56
63
  UserController_1.UserController,
57
64
  FiltriController_1.FiltriController,
65
+ ConfiguratorController_1.ConfiguratorController
58
66
  ],
59
- providers: [AuthService_1.AuthService, UserService_1.UserService, EmailService_1.EmailService, PermissionService_1.PermissionService, FiltriService_1.FiltriService],
60
- exports: [AuthService_1.AuthService, UserService_1.UserService, EmailService_1.EmailService, PermissionService_1.PermissionService, FiltriService_1.FiltriService],
67
+ providers: [AuthService_1.AuthService, UserService_1.UserService, EmailService_1.EmailService, PermissionService_1.PermissionService, FiltriService_1.FiltriService, ConfiguratorService_1.ConfiguratorService, jwt_strategy_1.JwtSimpleGuard],
68
+ exports: [AuthService_1.AuthService, UserService_1.UserService, EmailService_1.EmailService, PermissionService_1.PermissionService, FiltriService_1.FiltriService, ConfiguratorService_1.ConfiguratorService, jwt_strategy_1.JwtSimpleGuard],
61
69
  })
62
70
  ], AccessiModule);
@@ -102,9 +102,12 @@ let AuthController = AuthController_1 = class AuthController {
102
102
  if (!userData) {
103
103
  return Utilities_1.RestUtilities.sendInvalidCredentials(res);
104
104
  }
105
+ const tokenData = {
106
+ utente: userData.utente
107
+ };
105
108
  userData.token = {
106
109
  expiresIn: this.options.jwtOptions.expiresIn,
107
- value: jwt.sign(Object.assign({}, userData), this.options.jwtOptions.secret, {
110
+ value: jwt.sign(tokenData, this.options.jwtOptions.secret, {
108
111
  expiresIn: this.options.jwtOptions.expiresIn,
109
112
  }),
110
113
  type: 'Bearer',
@@ -0,0 +1,13 @@
1
+ import { Request, Response } from 'express';
2
+ import { AccessiOptions } from '../AccessiModule';
3
+ import { UpdateEnabledStatusRequest } from '../Dtos';
4
+ import { ConfiguratorService } from '../Services/ConfiguratorService/ConfiguratorService';
5
+ import { UserService } from '../Services/UserService/UserService';
6
+ export declare class ConfiguratorController {
7
+ private readonly options;
8
+ private userService;
9
+ private configuratorService;
10
+ constructor(options: AccessiOptions, userService: UserService, configuratorService: ConfiguratorService);
11
+ setMenuEnabled(codiceMenu: string, body: UpdateEnabledStatusRequest, req: Request, res: Response): Promise<Response<any, Record<string, any>>>;
12
+ setGroupEnabled(codiceGruppo: string, body: UpdateEnabledStatusRequest, req: Request, res: Response): Promise<Response<any, Record<string, any>>>;
13
+ }
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ var ConfiguratorController_1;
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.ConfiguratorController = void 0;
26
+ const common_1 = require("@nestjs/common");
27
+ const swagger_1 = require("@nestjs/swagger");
28
+ const Utilities_1 = require("../../Utilities");
29
+ const Dtos_1 = require("../Dtos");
30
+ const ConfiguratorService_1 = require("../Services/ConfiguratorService/ConfiguratorService");
31
+ const UserService_1 = require("../Services/UserService/UserService");
32
+ const jwt_strategy_1 = require("../jwt/jwt.strategy");
33
+ let ConfiguratorController = ConfiguratorController_1 = class ConfiguratorController {
34
+ constructor(options, userService, configuratorService) {
35
+ this.options = options;
36
+ this.userService = userService;
37
+ this.configuratorService = configuratorService;
38
+ }
39
+ setMenuEnabled(codiceMenu, body, req, res) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ var _a, _b;
42
+ try {
43
+ if (!codiceMenu)
44
+ throw new Error('Il codice del menu � obbligatorio.');
45
+ if ((body === null || body === void 0 ? void 0 : body.enabled) === undefined)
46
+ throw new Error('Lo stato di abilitazione � obbligatorio.');
47
+ const user = req === null || req === void 0 ? void 0 : req.user;
48
+ const codiceUtente = (_a = user === null || user === void 0 ? void 0 : user.utente) === null || _a === void 0 ? void 0 : _a.codiceUtente;
49
+ if (!codiceUtente) {
50
+ return Utilities_1.RestUtilities.sendErrorMessage(res, 'Utente non riconosciuto dal token.', ConfiguratorController_1.name, 401);
51
+ }
52
+ const canConfigure = ((_b = user === null || user === void 0 ? void 0 : user.utente) === null || _b === void 0 ? void 0 : _b.flagAdminConfigurator) ||
53
+ (yield this.userService.isAdminConfigurator(codiceUtente));
54
+ if (!canConfigure) {
55
+ return Utilities_1.RestUtilities.sendErrorMessage(res, 'Utente non autorizzato ad aggiornare i menu.', ConfiguratorController_1.name, 403);
56
+ }
57
+ yield this.configuratorService.setMenuEnabled(codiceMenu, body.enabled);
58
+ const action = body.enabled ? 'abilitato' : 'disabilitato';
59
+ return Utilities_1.RestUtilities.sendOKMessage(res, `Il menu ${codiceMenu} � stato ${action} con successo.`);
60
+ }
61
+ catch (error) {
62
+ return Utilities_1.RestUtilities.sendErrorMessage(res, error, ConfiguratorController_1.name);
63
+ }
64
+ });
65
+ }
66
+ setGroupEnabled(codiceGruppo, body, req, res) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ var _a, _b;
69
+ try {
70
+ if (!codiceGruppo)
71
+ throw new Error('Il codice del gruppo � obbligatorio.');
72
+ if ((body === null || body === void 0 ? void 0 : body.enabled) === undefined)
73
+ throw new Error('Lo stato di abilitazione � obbligatorio.');
74
+ const user = req === null || req === void 0 ? void 0 : req.user;
75
+ const codiceUtente = (_a = user === null || user === void 0 ? void 0 : user.utente) === null || _a === void 0 ? void 0 : _a.codiceUtente;
76
+ if (!codiceUtente) {
77
+ return Utilities_1.RestUtilities.sendErrorMessage(res, 'Utente non riconosciuto dal token.', ConfiguratorController_1.name, 401);
78
+ }
79
+ const canConfigure = ((_b = user === null || user === void 0 ? void 0 : user.utente) === null || _b === void 0 ? void 0 : _b.flagAdminConfigurator) ||
80
+ (yield this.userService.isAdminConfigurator(codiceUtente));
81
+ if (!canConfigure) {
82
+ return Utilities_1.RestUtilities.sendErrorMessage(res, 'Utente non autorizzato ad aggiornare i gruppi menu.', ConfiguratorController_1.name, 403);
83
+ }
84
+ yield this.configuratorService.setGroupEnabled(codiceGruppo, body.enabled);
85
+ const action = body.enabled ? 'abilitato' : 'disabilitato';
86
+ return Utilities_1.RestUtilities.sendOKMessage(res, `Il gruppo ${codiceGruppo} � stato ${action} con successo.`);
87
+ }
88
+ catch (error) {
89
+ return Utilities_1.RestUtilities.sendErrorMessage(res, error, ConfiguratorController_1.name);
90
+ }
91
+ });
92
+ }
93
+ };
94
+ exports.ConfiguratorController = ConfiguratorController;
95
+ __decorate([
96
+ (0, swagger_1.ApiOperation)({
97
+ summary: 'Aggiorna lo stato di abilitazione di un menu',
98
+ operationId: 'setMenuEnabled',
99
+ }),
100
+ (0, swagger_1.ApiParam)({
101
+ name: 'codiceMenu',
102
+ description: 'Codice identificativo del menu da aggiornare',
103
+ required: true,
104
+ example: 'MNU001',
105
+ }),
106
+ (0, swagger_1.ApiBody)({ type: Dtos_1.UpdateEnabledStatusRequest }),
107
+ (0, swagger_1.ApiResponse)({ status: 200, description: 'Stato del menu aggiornato con successo' }),
108
+ (0, swagger_1.ApiResponse)({ status: 400, description: 'Errore di validazione nei dati inviati' }),
109
+ (0, swagger_1.ApiResponse)({ status: 403, description: "Utente non autorizzato ad eseguire l'operazione" }),
110
+ (0, swagger_1.ApiResponse)({ status: 500, description: 'Errore interno del server' }),
111
+ (0, common_1.Patch)('menus/:codiceMenu/enabled'),
112
+ __param(0, (0, common_1.Param)('codiceMenu')),
113
+ __param(1, (0, common_1.Body)()),
114
+ __param(2, (0, common_1.Req)()),
115
+ __param(3, (0, common_1.Res)()),
116
+ __metadata("design:type", Function),
117
+ __metadata("design:paramtypes", [String, Dtos_1.UpdateEnabledStatusRequest, Object, Object]),
118
+ __metadata("design:returntype", Promise)
119
+ ], ConfiguratorController.prototype, "setMenuEnabled", null);
120
+ __decorate([
121
+ (0, swagger_1.ApiOperation)({
122
+ summary: 'Aggiorna lo stato di abilitazione di un gruppo menu',
123
+ operationId: 'setGroupEnabled',
124
+ }),
125
+ (0, swagger_1.ApiParam)({
126
+ name: 'codiceGruppo',
127
+ description: 'Codice identificativo del gruppo da aggiornare',
128
+ required: true,
129
+ example: 'GRP01',
130
+ }),
131
+ (0, swagger_1.ApiBody)({ type: Dtos_1.UpdateEnabledStatusRequest }),
132
+ (0, swagger_1.ApiResponse)({ status: 200, description: 'Stato del gruppo aggiornato con successo' }),
133
+ (0, swagger_1.ApiResponse)({ status: 400, description: 'Errore di validazione nei dati inviati' }),
134
+ (0, swagger_1.ApiResponse)({ status: 403, description: "Utente non autorizzato ad eseguire l'operazione" }),
135
+ (0, swagger_1.ApiResponse)({ status: 500, description: 'Errore interno del server' }),
136
+ (0, common_1.Patch)('groups/:codiceGruppo/enabled'),
137
+ __param(0, (0, common_1.Param)('codiceGruppo')),
138
+ __param(1, (0, common_1.Body)()),
139
+ __param(2, (0, common_1.Req)()),
140
+ __param(3, (0, common_1.Res)()),
141
+ __metadata("design:type", Function),
142
+ __metadata("design:paramtypes", [String, Dtos_1.UpdateEnabledStatusRequest, Object, Object]),
143
+ __metadata("design:returntype", Promise)
144
+ ], ConfiguratorController.prototype, "setGroupEnabled", null);
145
+ exports.ConfiguratorController = ConfiguratorController = ConfiguratorController_1 = __decorate([
146
+ (0, swagger_1.ApiBearerAuth)(),
147
+ (0, swagger_1.ApiTags)('Configurator'),
148
+ (0, common_1.Controller)('accessi/configurator'),
149
+ (0, common_1.UseGuards)(jwt_strategy_1.JwtSimpleGuard),
150
+ __param(0, (0, common_1.Inject)('ACCESSI_OPTIONS')),
151
+ __metadata("design:paramtypes", [Object, UserService_1.UserService,
152
+ ConfiguratorService_1.ConfiguratorService])
153
+ ], ConfiguratorController);
@@ -19,6 +19,6 @@ export declare class PermissionController {
19
19
  assignPermissionsToUser(res: Response, codiceUtente: number, assignPermissionsRequest: AssignPermissionsToUserRequest): Promise<Response<any, Record<string, any>>>;
20
20
  deleteRole(codiceRuolo: number, res: Response): Promise<Response<any, Record<string, any>>>;
21
21
  getMenus(res: Response): Promise<Response<any, Record<string, any>>>;
22
- getGroupsWithMenus(res: Response): Promise<Response<any, Record<string, any>>>;
22
+ getGroupsWithMenus(includeDisabled: string, res: Response): Promise<Response<any, Record<string, any>>>;
23
23
  getUserRolesAndGrants(codiceUtente: number, res: Response): Promise<Response<any, Record<string, any>>>;
24
24
  }
@@ -158,10 +158,13 @@ let PermissionController = PermissionController_1 = class PermissionController {
158
158
  }
159
159
  });
160
160
  }
161
- getGroupsWithMenus(res) {
161
+ getGroupsWithMenus(includeDisabled, res) {
162
162
  return __awaiter(this, void 0, void 0, function* () {
163
163
  try {
164
- const menus = yield this.permissionService.getGroupsWithMenus();
164
+ const includeDisabledFlag = typeof includeDisabled === 'string'
165
+ ? ['true', '1', 'yes'].includes(includeDisabled.toLowerCase())
166
+ : false;
167
+ const menus = yield this.permissionService.getGroupsWithMenus(includeDisabledFlag);
165
168
  return Utilities_1.RestUtilities.sendBaseResponse(res, menus);
166
169
  }
167
170
  catch (error) {
@@ -314,10 +317,17 @@ __decorate([
314
317
  (0, swagger_1.ApiOkResponse)({ description: 'Elenco gruppi con relativi menù', type: GetGroupsWithMenusResponse_1.GetGroupsWithMenusResponse }),
315
318
  (0, swagger_1.ApiResponse)({ status: 200, description: "Lista dei menù recuperata con successo" }),
316
319
  (0, swagger_1.ApiResponse)({ status: 500, description: "Errore interno del server" }),
320
+ (0, swagger_1.ApiQuery)({
321
+ name: 'includeDisabled',
322
+ required: false,
323
+ type: Boolean,
324
+ description: 'Quando true ritorna anche i menu e gruppi disabilitati.'
325
+ }),
317
326
  (0, common_1.Get)('groups-with-menus'),
318
- __param(0, (0, common_1.Res)()),
327
+ __param(0, (0, common_1.Query)('includeDisabled')),
328
+ __param(1, (0, common_1.Res)()),
319
329
  __metadata("design:type", Function),
320
- __metadata("design:paramtypes", [Object]),
330
+ __metadata("design:paramtypes", [String, Object]),
321
331
  __metadata("design:returntype", Promise)
322
332
  ], PermissionController.prototype, "getGroupsWithMenus", null);
323
333
  __decorate([
@@ -4,6 +4,7 @@ export declare class GroupWithMenusEntity {
4
4
  codiceGruppo: string;
5
5
  descrizioneGruppo: string;
6
6
  ordineGruppo: number;
7
+ enabled?: boolean;
7
8
  menus: MenuEntity[];
8
9
  }
9
10
  export declare class GetGroupsWithMenusResponse extends BaseResponse {
@@ -42,6 +42,14 @@ __decorate([
42
42
  }),
43
43
  __metadata("design:type", Number)
44
44
  ], GroupWithMenusEntity.prototype, "ordineGruppo", void 0);
45
+ __decorate([
46
+ (0, swagger_1.ApiPropertyOptional)({
47
+ description: "Flag che indica se il gruppo e abilitato.",
48
+ type: Boolean,
49
+ example: true
50
+ }),
51
+ __metadata("design:type", Boolean)
52
+ ], GroupWithMenusEntity.prototype, "enabled", void 0);
45
53
  __decorate([
46
54
  (0, swagger_1.ApiProperty)({
47
55
  description: "Lista dei menù associati al gruppo.",
@@ -9,6 +9,7 @@ export declare class MenuEntity {
9
9
  pagina?: string;
10
10
  ordineMenu: number;
11
11
  ordineGruppo: number;
12
+ enabled?: boolean;
12
13
  tipoAbilitazione?: number;
13
14
  }
14
15
  export declare class GetMenusResponse extends BaseResponse {
@@ -94,6 +94,14 @@ __decorate([
94
94
  }),
95
95
  __metadata("design:type", Number)
96
96
  ], MenuEntity.prototype, "ordineGruppo", void 0);
97
+ __decorate([
98
+ (0, swagger_1.ApiPropertyOptional)({
99
+ description: "Flag che indica se il menu e abilitato.",
100
+ type: Boolean,
101
+ example: true
102
+ }),
103
+ __metadata("design:type", Boolean)
104
+ ], MenuEntity.prototype, "enabled", void 0);
97
105
  __decorate([
98
106
  (0, swagger_1.ApiPropertyOptional)({
99
107
  description: "Tipo abilitazione opzionale",
@@ -7,6 +7,7 @@ export declare class RegisterRequest extends RegisterRequest_base {
7
7
  nome?: string;
8
8
  cellulare?: string | null;
9
9
  flagSuper?: boolean;
10
+ flagAdminConfigurator?: boolean;
10
11
  roles?: string[];
11
12
  permissions?: Permission[];
12
13
  avatar?: string;
@@ -47,6 +47,13 @@ __decorate([
47
47
  (0, swagger_1.ApiPropertyOptional)({ description: "Flag superutente.", example: false }),
48
48
  __metadata("design:type", Boolean)
49
49
  ], RegisterRequest.prototype, "flagSuper", void 0);
50
+ __decorate([
51
+ (0, swagger_1.ApiPropertyOptional)({
52
+ description: "Flag che indica se l'utente è configuratore",
53
+ example: false
54
+ }),
55
+ __metadata("design:type", Boolean)
56
+ ], RegisterRequest.prototype, "flagAdminConfigurator", void 0);
50
57
  __decorate([
51
58
  (0, swagger_1.ApiPropertyOptional)({
52
59
  description: "Ruoli assegnati all'utente.",
@@ -0,0 +1,3 @@
1
+ export declare class UpdateEnabledStatusRequest {
2
+ enabled: boolean;
3
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.UpdateEnabledStatusRequest = void 0;
13
+ const swagger_1 = require("@nestjs/swagger");
14
+ const class_validator_1 = require("class-validator");
15
+ class UpdateEnabledStatusRequest {
16
+ }
17
+ exports.UpdateEnabledStatusRequest = UpdateEnabledStatusRequest;
18
+ __decorate([
19
+ (0, swagger_1.ApiProperty)({
20
+ description: 'Nuovo stato di abilitazione',
21
+ example: true,
22
+ type: Boolean,
23
+ }),
24
+ (0, class_validator_1.IsBoolean)({ message: 'Il valore di enabled deve essere booleano.' }),
25
+ __metadata("design:type", Boolean)
26
+ ], UpdateEnabledStatusRequest.prototype, "enabled", void 0);
@@ -19,6 +19,7 @@ export declare class UserDto extends UserDto_base {
19
19
  codiceLingua?: string;
20
20
  cellulare?: string | null;
21
21
  flagSuper?: boolean;
22
+ flagAdminConfigurator?: boolean;
22
23
  paginaDefault?: string;
23
24
  jsonMetadata?: string;
24
25
  ragSocCli?: string;
@@ -116,6 +116,13 @@ __decorate([
116
116
  (0, swagger_1.ApiPropertyOptional)({ description: 'Flag superutente.', example: false }),
117
117
  __metadata("design:type", Boolean)
118
118
  ], UserDto.prototype, "flagSuper", void 0);
119
+ __decorate([
120
+ (0, swagger_1.ApiPropertyOptional)({
121
+ description: "Flag che indica se l'utente è configuratore",
122
+ example: false
123
+ }),
124
+ __metadata("design:type", Boolean)
125
+ ], UserDto.prototype, "flagAdminConfigurator", void 0);
119
126
  __decorate([
120
127
  (0, swagger_1.ApiPropertyOptional)({
121
128
  description: "Pagina di default dell'utente all'accesso.",
@@ -3,6 +3,7 @@ export * from "./AbilitazioneMenu";
3
3
  export * from "./AssignPermissionsToUserRequest";
4
4
  export * from "./AssignRolesToUserRequest";
5
5
  export * from "./BaseResponse";
6
+ export * from "./UpdateEnabledStatusRequest";
6
7
  export * from "./FiltriUtente";
7
8
  export * from "./LoginRequest";
8
9
  export * from "./LoginResponse";
@@ -19,6 +19,7 @@ __exportStar(require("./AbilitazioneMenu"), exports);
19
19
  __exportStar(require("./AssignPermissionsToUserRequest"), exports);
20
20
  __exportStar(require("./AssignRolesToUserRequest"), exports);
21
21
  __exportStar(require("./BaseResponse"), exports);
22
+ __exportStar(require("./UpdateEnabledStatusRequest"), exports);
22
23
  __exportStar(require("./FiltriUtente"), exports);
23
24
  __exportStar(require("./LoginRequest"), exports);
24
25
  __exportStar(require("./LoginResponse"), exports);
@@ -0,0 +1,7 @@
1
+ import { AccessiOptions } from '../../AccessiModule';
2
+ export declare class ConfiguratorService {
3
+ private readonly accessiOptions;
4
+ constructor(accessiOptions: AccessiOptions);
5
+ setMenuEnabled(codiceMenu: string, enabled: boolean): Promise<void>;
6
+ setGroupEnabled(codiceGruppo: string, enabled: boolean): Promise<void>;
7
+ }
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.ConfiguratorService = void 0;
25
+ const common_1 = require("@nestjs/common");
26
+ const autobind_1 = require("../../../autobind");
27
+ const Orm_1 = require("../../../Orm");
28
+ let ConfiguratorService = class ConfiguratorService {
29
+ constructor(accessiOptions) {
30
+ this.accessiOptions = accessiOptions;
31
+ }
32
+ setMenuEnabled(codiceMenu, enabled) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ const query = `UPDATE MENU SET FLGENABLED = ? WHERE CODMNU = ?`;
35
+ const enabledValue = enabled ? 1 : 0;
36
+ yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, query, [enabledValue, codiceMenu]);
37
+ });
38
+ }
39
+ setGroupEnabled(codiceGruppo, enabled) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const query = `UPDATE MENU_GRP SET FLGENABLED = ? WHERE CODGRP = ?`;
42
+ const enabledValue = enabled ? 1 : 0;
43
+ yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, query, [enabledValue, codiceGruppo]);
44
+ });
45
+ }
46
+ };
47
+ exports.ConfiguratorService = ConfiguratorService;
48
+ exports.ConfiguratorService = ConfiguratorService = __decorate([
49
+ autobind_1.autobind,
50
+ (0, common_1.Injectable)(),
51
+ __param(0, (0, common_1.Inject)('ACCESSI_OPTIONS')),
52
+ __metadata("design:paramtypes", [Object])
53
+ ], ConfiguratorService);
@@ -15,7 +15,7 @@ export declare class PermissionService {
15
15
  assignPermissionsToUser(codiceUtente: number, permissions: Permission[]): Promise<void>;
16
16
  deleteRole(codiceRuolo: number): Promise<void>;
17
17
  getMenus(): Promise<MenuEntity[]>;
18
- getGroupsWithMenus(): Promise<GroupWithMenusEntity[]>;
18
+ getGroupsWithMenus(includeDisabled?: boolean): Promise<GroupWithMenusEntity[]>;
19
19
  getUserRolesAndGrants(codiceUtente: number): Promise<{
20
20
  abilitazioni: AbilitazioneMenu[];
21
21
  ruoli: Role[];
@@ -20,10 +20,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
20
20
  step((generator = generator.apply(thisArg, _arguments || [])).next());
21
21
  });
22
22
  };
23
+ var __rest = (this && this.__rest) || function (s, e) {
24
+ var t = {};
25
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
26
+ t[p] = s[p];
27
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
28
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
29
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
30
+ t[p[i]] = s[p[i]];
31
+ }
32
+ return t;
33
+ };
23
34
  Object.defineProperty(exports, "__esModule", { value: true });
24
35
  exports.PermissionService = void 0;
25
36
  const Orm_1 = require("../../../Orm");
26
37
  const Utilities_1 = require("../../../Utilities");
38
+ const Dtos_1 = require("../../Dtos");
27
39
  const common_1 = require("@nestjs/common");
28
40
  let PermissionService = class PermissionService {
29
41
  constructor(accessiOptions) {
@@ -51,11 +63,16 @@ let PermissionService = class PermissionService {
51
63
  }
52
64
  updateOrInsertRole(role_1) {
53
65
  return __awaiter(this, arguments, void 0, function* (role, codiceRuolo = null) {
66
+ var _a, _b, _c, _d, _e;
54
67
  // creazione nuovo ruolo
55
68
  if (!codiceRuolo) {
56
- let createRoleQuery = `INSERT INTO RUOLI (DESRUO) VALUES (?) RETURNING CODRUO`;
57
- let result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, createRoleQuery, [role.descrizioneRuolo]);
58
- codiceRuolo = result[0].CODRUO;
69
+ const createRoleQuery = `INSERT INTO RUOLI (DESRUO) VALUES (?)`;
70
+ yield Orm_1.Orm.execute(this.accessiOptions.databaseOptions, createRoleQuery, [role.descrizioneRuolo]);
71
+ const createdRoleResult = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, 'SELECT FIRST 1 CODRUO FROM RUOLI WHERE DESRUO = ? ORDER BY CODRUO DESC', [role.descrizioneRuolo]);
72
+ codiceRuolo = (_c = (_b = (_a = createdRoleResult === null || createdRoleResult === void 0 ? void 0 : createdRoleResult[0]) === null || _a === void 0 ? void 0 : _a.CODRUO) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : (_e = (_d = createdRoleResult === null || createdRoleResult === void 0 ? void 0 : createdRoleResult[0]) === null || _d === void 0 ? void 0 : _d.codruo) === null || _e === void 0 ? void 0 : _e.toString();
73
+ if (!codiceRuolo) {
74
+ throw new Error('Creazione ruolo non riuscita: impossibile recuperare CODRUO.');
75
+ }
59
76
  }
60
77
  else
61
78
  // aggiornamento ruolo esistente
@@ -97,13 +114,17 @@ let PermissionService = class PermissionService {
97
114
  menu: []
98
115
  });
99
116
  }
100
- if (codiceMenu) {
101
- ruoliMap.get(codiceRuolo).menu.push({
102
- codiceMenu: codiceMenu.trim(),
103
- tipoAbilitazione,
104
- descrizioneMenu: descrizioneMenu === null || descrizioneMenu === void 0 ? void 0 : descrizioneMenu.trim()
105
- });
117
+ const abilitationValue = typeof tipoAbilitazione === 'number'
118
+ ? tipoAbilitazione
119
+ : Number.parseInt(`${tipoAbilitazione !== null && tipoAbilitazione !== void 0 ? tipoAbilitazione : ''}`, 10);
120
+ if (!codiceMenu || Number.isNaN(abilitationValue) || abilitationValue <= Dtos_1.TipoAbilitazione.NESSUNA) {
121
+ continue;
106
122
  }
123
+ ruoliMap.get(codiceRuolo).menu.push({
124
+ codiceMenu: codiceMenu.trim(),
125
+ tipoAbilitazione: abilitationValue,
126
+ descrizioneMenu: descrizioneMenu === null || descrizioneMenu === void 0 ? void 0 : descrizioneMenu.trim()
127
+ });
107
128
  }
108
129
  return Array.from(ruoliMap.values());
109
130
  });
@@ -174,7 +195,10 @@ let PermissionService = class PermissionService {
174
195
  });
175
196
  }
176
197
  getGroupsWithMenus() {
177
- return __awaiter(this, void 0, void 0, function* () {
198
+ return __awaiter(this, arguments, void 0, function* (includeDisabled = false) {
199
+ const filtersClause = includeDisabled
200
+ ? ''
201
+ : 'WHERE M.FLGENABLED = 1 AND (G.FLGENABLED IS NULL OR G.FLGENABLED = 1)';
178
202
  const query = `
179
203
  SELECT
180
204
  M.CODMNU AS codice_menu,
@@ -185,30 +209,42 @@ let PermissionService = class PermissionService {
185
209
  M.CODTIP AS tipo,
186
210
  M.PAGINA AS pagina,
187
211
  G.ORDINE AS ordine_gruppo,
188
- M.ORDINE as ordine_menu
212
+ M.ORDINE as ordine_menu,
213
+ M.FLGENABLED AS menu_enabled,
214
+ G.FLGENABLED AS group_enabled
189
215
  FROM MENU M
190
216
  LEFT JOIN MENU_GRP G ON M.CODGRP = G.CODGRP
191
- WHERE M.FLGENABLED = 1
217
+ ${filtersClause}
192
218
  ORDER BY G.CODGRP, M.CODMNU
193
219
  `;
194
220
  const result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, []);
195
- // Process the result to group menus by their respective groups
196
221
  const groupMap = new Map();
197
222
  result.forEach(row => {
198
- const menu = Utilities_1.RestUtilities.convertKeysToCamelCase(row);
199
- const groupKey = menu.codiceGruppo;
200
- if (!groupMap.has(groupKey)) {
201
- groupMap.set(groupKey, {
202
- codiceGruppo: menu.codiceGruppo,
203
- descrizioneGruppo: menu.descrizioneGruppo,
204
- ordineGruppo: menu.ordineGruppo,
205
- menus: []
223
+ var _a, _b;
224
+ const converted = Utilities_1.RestUtilities.convertKeysToCamelCase(row);
225
+ const _c = converted, { menuEnabled, groupEnabled } = _c, menuBase = __rest(_c, ["menuEnabled", "groupEnabled"]);
226
+ const normalizedGroupKey = (_a = menuBase.codiceGruppo) !== null && _a !== void 0 ? _a : '__UNGROUPED__';
227
+ const groupEnabledFlag = groupEnabled === undefined ? true : Number(groupEnabled) === 1 || groupEnabled === true;
228
+ const menuEnabledFlag = menuEnabled === undefined ? true : Number(menuEnabled) === 1 || menuEnabled === true;
229
+ if (!groupMap.has(normalizedGroupKey)) {
230
+ groupMap.set(normalizedGroupKey, {
231
+ codiceGruppo: (_b = menuBase.codiceGruppo) !== null && _b !== void 0 ? _b : normalizedGroupKey,
232
+ descrizioneGruppo: menuBase.descrizioneGruppo,
233
+ ordineGruppo: menuBase.ordineGruppo,
234
+ enabled: groupEnabledFlag,
235
+ menus: [],
206
236
  });
207
237
  }
208
- groupMap.get(groupKey).menus.push(menu);
209
- groupMap.get(groupKey).menus = groupMap.get(groupKey).menus.sort((a, b) => a.ordineMenu - b.ordineMenu);
238
+ if (menuBase.codiceMenu) {
239
+ groupMap.get(normalizedGroupKey).menus.push(Object.assign(Object.assign({}, menuBase), { enabled: menuEnabledFlag }));
240
+ }
210
241
  });
211
- let groupsArray = Array.from(groupMap.values()).sort((a, b) => a.ordineGruppo - b.ordineGruppo);
242
+ const groupsArray = Array.from(groupMap.values())
243
+ .map(group => {
244
+ var _a;
245
+ return (Object.assign(Object.assign({}, group), { menus: ((_a = group.menus) !== null && _a !== void 0 ? _a : []).sort((a, b) => { var _a, _b; return ((_a = a.ordineMenu) !== null && _a !== void 0 ? _a : Number.MAX_SAFE_INTEGER) - ((_b = b.ordineMenu) !== null && _b !== void 0 ? _b : Number.MAX_SAFE_INTEGER); }) }));
246
+ })
247
+ .sort((a, b) => { var _a, _b; return ((_a = a.ordineGruppo) !== null && _a !== void 0 ? _a : Number.MAX_SAFE_INTEGER) - ((_b = b.ordineGruppo) !== null && _b !== void 0 ? _b : Number.MAX_SAFE_INTEGER); });
212
248
  return groupsArray;
213
249
  });
214
250
  }
@@ -12,6 +12,7 @@ export declare class UserService {
12
12
  private readonly permissionService;
13
13
  private readonly filtriService;
14
14
  constructor(accessiOptions: AccessiOptions, emailService: EmailService, permissionService: PermissionService, filtriService: FiltriService);
15
+ isAdminConfigurator(codiceUtente: number): Promise<boolean>;
15
16
  getUsers(filters?: {
16
17
  email?: string;
17
18
  codiceUtente?: number;
@@ -25,7 +26,7 @@ export declare class UserService {
25
26
  getUserByEmail(email: string): Promise<UserDto | null>;
26
27
  insertUserFilters(codiceUtente: number, filterData: RegisterRequest): Promise<void>;
27
28
  private executeInTransaction;
28
- register(registrationData: RegisterRequest): Promise<string>;
29
+ register(registrationData: RegisterRequest): Promise<number>;
29
30
  updateUser(codiceUtente: number, user: UserDto): Promise<void>;
30
31
  updateUserFilters(codiceUtente: number, user: UserDto): Promise<void>;
31
32
  deleteUser(codiceCliente: number): Promise<void>;
@@ -38,6 +38,25 @@ let UserService = class UserService {
38
38
  this.permissionService = permissionService;
39
39
  this.filtriService = filtriService;
40
40
  }
41
+ isAdminConfigurator(codiceUtente) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ var _a;
44
+ if (!codiceUtente) {
45
+ return false;
46
+ }
47
+ const query = `SELECT FLGADMINCONFIG AS flag_admin_configurator FROM UTENTI_CONFIG WHERE CODUTE = ?`;
48
+ const result = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, query, [codiceUtente]);
49
+ if (!result || result === 0) {
50
+ return false;
51
+ }
52
+ const mapped = result.map(Utilities_1.RestUtilities.convertKeysToCamelCase);
53
+ const flagValue = (_a = mapped[0]) === null || _a === void 0 ? void 0 : _a.flag_admin_configurator;
54
+ if (typeof flagValue === 'boolean') {
55
+ return flagValue;
56
+ }
57
+ return flagValue === 1;
58
+ });
59
+ }
41
60
  getUsers(filters, options) {
42
61
  return __awaiter(this, void 0, void 0, function* () {
43
62
  try {
@@ -58,6 +77,7 @@ let UserService = class UserService {
58
77
  G.CODLINGUA as codice_lingua,
59
78
  G.CELLULARE as cellulare,
60
79
  G.FLGSUPER as flag_super,
80
+ G.FLGADMINCONFIG as flag_admin_configurator,
61
81
  G.PAGDEF as pagina_default,
62
82
  G.JSON_METADATA as json_metadata,
63
83
  G.RAGSOCCLI as rag_soc_cli,
@@ -145,7 +165,8 @@ let UserService = class UserService {
145
165
  C.FLG2FATT AS flag_due_fattori,
146
166
  C.CODLINGUA AS codice_lingua,
147
167
  C.CELLULARE AS cellulare,
148
- C.FLGSUPER AS flag_super,
168
+ C.FLGSUPER AS flag_super,
169
+ C.FLGADMINCONFIG AS flag_admin_configurator,
149
170
  C.PAGDEF AS pagina_default,
150
171
  C.RAGSOCCLI AS rag_soc_cli
151
172
  FROM UTENTI U
@@ -172,14 +193,14 @@ let UserService = class UserService {
172
193
  }
173
194
  // async getUserFilters(codiceUtente: number): Promise<FiltriUtente[]> {
174
195
  // const query = `
175
- // SELECT
176
- // F.PROG AS progressivo,
177
- // F.NUMREP AS numero_report,
196
+ // SELECT
197
+ // F.PROG AS progressivo,
198
+ // F.NUMREP AS numero_report,
178
199
  // F.IDXPERS AS indice_personale,
179
- // F.CODCLISUPER AS codice_cliente_super,
180
- // F.CODAGE AS cod_age,
200
+ // F.CODCLISUPER AS codice_cliente_super,
201
+ // F.CODAGE AS cod_age,
181
202
  // F.CODCLICOL AS codice_cliente_collegato,
182
- // F.CODCLIENTI AS codice_clienti,
203
+ // F.CODCLIENTI AS codice_clienti,
183
204
  // F.TIPFIL AS tipo_filtro,
184
205
  // F.IDXPOS AS idx_postazione
185
206
  // FROM FILTRI F
@@ -244,14 +265,20 @@ let UserService = class UserService {
244
265
  }
245
266
  register(registrationData) {
246
267
  return __awaiter(this, void 0, void 0, function* () {
268
+ var _a, _b, _c;
247
269
  try {
248
270
  const existingUser = yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, 'SELECT CODUTE FROM UTENTI WHERE USRNAME = ?', [registrationData.email]);
249
271
  if (existingUser.length > 0) {
250
272
  throw new Error('Questa e-mail è già stata utilizzata!');
251
273
  }
252
- const queryUtenti = `INSERT INTO UTENTI (USRNAME, STAREG) VALUES (?,?) RETURNING CODUTE`;
274
+ const queryUtenti = `INSERT INTO UTENTI (USRNAME, STAREG) VALUES (?,?)`;
253
275
  const paramsUtenti = [registrationData.email, StatoRegistrazione_1.StatoRegistrazione.INVIO];
254
- const codiceUtente = (yield Orm_1.Orm.query(this.accessiOptions.databaseOptions, queryUtenti, paramsUtenti)).CODUTE;
276
+ 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', [registrationData.email]);
278
+ 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
+ if (!codiceUtente) {
280
+ throw new Error('Creazione utente non riuscita: impossibile recuperare CODUTE.');
281
+ }
255
282
  const utentiConfigFields = ['CODUTE', 'COGNOME', 'NOME'];
256
283
  const utentiConfigPlaceholders = ['?', '?', '?'];
257
284
  const utentiConfigParams = [codiceUtente, registrationData.cognome, registrationData.nome];
@@ -259,6 +286,7 @@ let UserService = class UserService {
259
286
  const optionalFields = [
260
287
  ['cellulare', 'CELLULARE'],
261
288
  ['flagSuper', 'FLGSUPER'],
289
+ ['flagAdminConfigurator', 'FLGADMINCONFIG'],
262
290
  ['avatar', 'AVATAR'],
263
291
  ['flagDueFattori', 'FLG2FATT'],
264
292
  ['paginaDefault', 'PAGDEF'],
@@ -269,7 +297,7 @@ let UserService = class UserService {
269
297
  if (value !== undefined && value !== null) {
270
298
  utentiConfigFields.push(dbField);
271
299
  utentiConfigPlaceholders.push('?');
272
- utentiConfigParams.push(value);
300
+ utentiConfigParams.push(Number(value));
273
301
  }
274
302
  }
275
303
  const queryUtentiConfig = `INSERT INTO UTENTI_CONFIG (${utentiConfigFields.join(', ')}) VALUES (${utentiConfigPlaceholders.join(', ')})`;
@@ -345,6 +373,10 @@ let UserService = class UserService {
345
373
  utentiConfigUpdates.push('flgsuper = ?');
346
374
  utentiConfigParams.push(user.flagSuper);
347
375
  }
376
+ if (user.flagAdminConfigurator !== undefined) {
377
+ utentiConfigUpdates.push('flgadminconfig = ?');
378
+ utentiConfigParams.push(user.flagAdminConfigurator);
379
+ }
348
380
  if (user.paginaDefault !== undefined) {
349
381
  utentiConfigUpdates.push('pagdef = ?');
350
382
  utentiConfigParams.push(user.paginaDefault);
@@ -0,0 +1,7 @@
1
+ import { CanActivate, ExecutionContext } from '@nestjs/common';
2
+ import { AccessiOptions } from '../AccessiModule';
3
+ export declare class JwtSimpleGuard implements CanActivate {
4
+ private readonly accessiOptions;
5
+ constructor(accessiOptions: AccessiOptions);
6
+ canActivate(context: ExecutionContext): boolean;
7
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
23
+ };
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ var __metadata = (this && this.__metadata) || function (k, v) {
42
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
43
+ };
44
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
45
+ return function (target, key) { decorator(target, key, paramIndex); }
46
+ };
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ exports.JwtSimpleGuard = void 0;
49
+ const common_1 = require("@nestjs/common");
50
+ const jwt = __importStar(require("jsonwebtoken"));
51
+ let JwtSimpleGuard = class JwtSimpleGuard {
52
+ constructor(accessiOptions) {
53
+ this.accessiOptions = accessiOptions;
54
+ }
55
+ canActivate(context) {
56
+ var _a, _b;
57
+ const request = context.switchToHttp().getRequest();
58
+ const authHeader = request.headers['authorization'];
59
+ if (!authHeader)
60
+ throw new common_1.UnauthorizedException('Token mancante.');
61
+ const token = authHeader.split(' ')[1];
62
+ if (!token)
63
+ throw new common_1.UnauthorizedException('Formato token non valido.');
64
+ try {
65
+ const secret = ((_b = (_a = this.accessiOptions) === null || _a === void 0 ? void 0 : _a.jwtOptions) === null || _b === void 0 ? void 0 : _b.secret) || process.env.ACC_JWT_SECRET || 'super-secret';
66
+ const payload = jwt.verify(token, secret);
67
+ request.user = payload;
68
+ return true;
69
+ }
70
+ catch (error) {
71
+ throw new common_1.UnauthorizedException('Token non valido o scaduto.');
72
+ }
73
+ }
74
+ };
75
+ exports.JwtSimpleGuard = JwtSimpleGuard;
76
+ exports.JwtSimpleGuard = JwtSimpleGuard = __decorate([
77
+ (0, common_1.Injectable)(),
78
+ __param(0, (0, common_1.Inject)('ACCESSI_OPTIONS')),
79
+ __metadata("design:paramtypes", [Object])
80
+ ], JwtSimpleGuard);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emilsoftware-utilities",
3
- "version": "1.6.1-dev.1",
3
+ "version": "1.6.1-dev.3",
4
4
  "description": "Utilities for EmilSoftware",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",