@flusys/nestjs-iam 1.0.0-rc → 2.0.0
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 +219 -118
- package/cjs/controllers/company-action-permission.controller.js +2 -17
- package/cjs/controllers/my-permission.controller.js +1 -2
- package/cjs/controllers/role-permission.controller.js +3 -9
- package/cjs/controllers/user-action-permission.controller.js +3 -9
- package/cjs/dtos/action.dto.js +0 -27
- package/cjs/dtos/permission.dto.js +81 -27
- package/cjs/dtos/role.dto.js +0 -27
- package/cjs/helpers/company-access.helper.js +19 -0
- package/cjs/helpers/index.js +1 -1
- package/cjs/interfaces/iam-module-options.interface.js +0 -14
- package/cjs/interfaces/index.js +0 -1
- package/cjs/modules/iam.module.js +38 -106
- package/cjs/services/action.service.js +30 -41
- package/cjs/services/iam-config.service.js +2 -5
- package/cjs/services/{iam-datasource.provider.js → iam-datasource.service.js} +33 -36
- package/cjs/services/index.js +1 -1
- package/cjs/services/permission-cache.service.js +6 -46
- package/cjs/services/permission.service.js +52 -41
- package/cjs/services/role.service.js +3 -3
- package/controllers/company-action-permission.controller.d.ts +2 -5
- package/controllers/role-permission.controller.d.ts +0 -1
- package/controllers/user-action-permission.controller.d.ts +0 -1
- package/dtos/action.dto.d.ts +0 -4
- package/dtos/role.dto.d.ts +0 -4
- package/fesm/controllers/company-action-permission.controller.js +4 -19
- package/fesm/controllers/my-permission.controller.js +1 -2
- package/fesm/controllers/role-permission.controller.js +4 -10
- package/fesm/controllers/user-action-permission.controller.js +4 -10
- package/fesm/dtos/action.dto.js +0 -24
- package/fesm/dtos/permission.dto.js +81 -27
- package/fesm/dtos/role.dto.js +0 -24
- package/fesm/helpers/company-access.helper.js +14 -0
- package/fesm/helpers/index.js +1 -1
- package/fesm/interfaces/iam-module-options.interface.js +3 -1
- package/fesm/interfaces/index.js +0 -1
- package/fesm/modules/iam.module.js +40 -108
- package/fesm/services/action.service.js +31 -42
- package/fesm/services/iam-config.service.js +2 -5
- package/fesm/services/{iam-datasource.provider.js → iam-datasource.service.js} +31 -34
- package/fesm/services/index.js +1 -1
- package/fesm/services/permission-cache.service.js +6 -46
- package/fesm/services/permission.service.js +53 -42
- package/fesm/services/role.service.js +3 -3
- package/helpers/company-access.helper.d.ts +3 -0
- package/helpers/index.d.ts +1 -1
- package/interfaces/iam-module-options.interface.d.ts +9 -1
- package/interfaces/index.d.ts +0 -1
- package/modules/iam.module.d.ts +1 -2
- package/package.json +3 -3
- package/services/action.service.d.ts +6 -4
- package/services/iam-config.service.d.ts +0 -1
- package/services/{iam-datasource.provider.d.ts → iam-datasource.service.d.ts} +4 -5
- package/services/index.d.ts +1 -1
- package/services/permission-cache.service.d.ts +1 -4
- package/services/permission.service.d.ts +4 -2
- package/services/role.service.d.ts +3 -3
- package/cjs/helpers/permission-evaluator.helper.js +0 -175
- package/cjs/interfaces/iam-module-async-options.interface.js +0 -4
- package/fesm/helpers/permission-evaluator.helper.js +0 -165
- package/fesm/interfaces/iam-module-async-options.interface.js +0 -3
- package/helpers/permission-evaluator.helper.d.ts +0 -26
- package/interfaces/iam-module-async-options.interface.d.ts +0 -11
|
@@ -26,25 +26,19 @@ function _ts_param(paramIndex, decorator) {
|
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
28
|
import { JwtAuthGuard, SingleResponseDto, RequirePermission, USER_ACTION_PERMISSIONS, CurrentUser, ILoggedUserInfo } from '@flusys/nestjs-shared';
|
|
29
|
-
import {
|
|
29
|
+
import { Body, Controller, Inject, Post, UseGuards } from '@nestjs/common';
|
|
30
30
|
import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
31
31
|
import { AssignUserActionsDto, GetUserActionsDto, PermissionOperationResultDto } from '../dtos/permission.dto';
|
|
32
|
+
import { validateCompanyAccess } from '../helpers';
|
|
32
33
|
import { PermissionService } from '../services/permission.service';
|
|
33
34
|
import { IAMConfigService } from '../services/iam-config.service';
|
|
34
35
|
export class UserActionPermissionController {
|
|
35
|
-
/** Validates that user can only manage permissions within their company */ validateCompanyAccess(companyId, user) {
|
|
36
|
-
if (this.config.isCompanyFeatureEnabled() && user.companyId && companyId) {
|
|
37
|
-
if (companyId !== user.companyId) {
|
|
38
|
-
throw new BadRequestException('Cannot manage permissions for users in another company');
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
36
|
async assignUserActions(dto, user) {
|
|
43
|
-
this.
|
|
37
|
+
validateCompanyAccess(this.config, dto.companyId, user, 'Cannot manage permissions for users in another company');
|
|
44
38
|
return this.permissionService.assignUserActions(dto);
|
|
45
39
|
}
|
|
46
40
|
async getUserActions(dto, user) {
|
|
47
|
-
this.
|
|
41
|
+
validateCompanyAccess(this.config, dto.companyId, user, 'Cannot manage permissions for users in another company');
|
|
48
42
|
const actions = await this.permissionService.getUserActions(dto.userId, dto.branchId, dto.companyId);
|
|
49
43
|
return {
|
|
50
44
|
success: true,
|
package/fesm/dtos/action.dto.js
CHANGED
|
@@ -254,30 +254,6 @@ _ts_decorate([
|
|
|
254
254
|
}),
|
|
255
255
|
_ts_metadata("design:type", Array)
|
|
256
256
|
], ActionTreeDto.prototype, "children", void 0);
|
|
257
|
-
export class ActionQueryDto {
|
|
258
|
-
constructor(){
|
|
259
|
-
_define_property(this, "isActive", void 0);
|
|
260
|
-
_define_property(this, "parentId", void 0);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
_ts_decorate([
|
|
264
|
-
ApiProperty({
|
|
265
|
-
description: 'Filter by active status',
|
|
266
|
-
required: false
|
|
267
|
-
}),
|
|
268
|
-
IsBoolean(),
|
|
269
|
-
IsOptional(),
|
|
270
|
-
_ts_metadata("design:type", Boolean)
|
|
271
|
-
], ActionQueryDto.prototype, "isActive", void 0);
|
|
272
|
-
_ts_decorate([
|
|
273
|
-
ApiProperty({
|
|
274
|
-
description: 'Filter by parent ID',
|
|
275
|
-
required: false
|
|
276
|
-
}),
|
|
277
|
-
IsUUID(),
|
|
278
|
-
IsOptional(),
|
|
279
|
-
_ts_metadata("design:type", String)
|
|
280
|
-
], ActionQueryDto.prototype, "parentId", void 0);
|
|
281
257
|
export class ActionTreeQueryDto {
|
|
282
258
|
constructor(){
|
|
283
259
|
_define_property(this, "search", void 0);
|
|
@@ -290,31 +290,45 @@ export class UserActionResponseDto {
|
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
_ts_decorate([
|
|
293
|
-
ApiProperty(
|
|
293
|
+
ApiProperty({
|
|
294
|
+
description: 'Permission ID'
|
|
295
|
+
}),
|
|
294
296
|
_ts_metadata("design:type", String)
|
|
295
297
|
], UserActionResponseDto.prototype, "id", void 0);
|
|
296
298
|
_ts_decorate([
|
|
297
|
-
ApiProperty(
|
|
299
|
+
ApiProperty({
|
|
300
|
+
description: 'User ID'
|
|
301
|
+
}),
|
|
298
302
|
_ts_metadata("design:type", String)
|
|
299
303
|
], UserActionResponseDto.prototype, "userId", void 0);
|
|
300
304
|
_ts_decorate([
|
|
301
|
-
ApiProperty(
|
|
305
|
+
ApiProperty({
|
|
306
|
+
description: 'Action ID'
|
|
307
|
+
}),
|
|
302
308
|
_ts_metadata("design:type", String)
|
|
303
309
|
], UserActionResponseDto.prototype, "actionId", void 0);
|
|
304
310
|
_ts_decorate([
|
|
305
|
-
ApiProperty(
|
|
311
|
+
ApiProperty({
|
|
312
|
+
description: 'Action code'
|
|
313
|
+
}),
|
|
306
314
|
_ts_metadata("design:type", String)
|
|
307
315
|
], UserActionResponseDto.prototype, "actionCode", void 0);
|
|
308
316
|
_ts_decorate([
|
|
309
|
-
ApiProperty(
|
|
317
|
+
ApiProperty({
|
|
318
|
+
description: 'Action name'
|
|
319
|
+
}),
|
|
310
320
|
_ts_metadata("design:type", String)
|
|
311
321
|
], UserActionResponseDto.prototype, "actionName", void 0);
|
|
312
322
|
_ts_decorate([
|
|
313
|
-
ApiPropertyOptional(
|
|
323
|
+
ApiPropertyOptional({
|
|
324
|
+
description: 'Branch ID (null = company-wide)'
|
|
325
|
+
}),
|
|
314
326
|
_ts_metadata("design:type", Object)
|
|
315
327
|
], UserActionResponseDto.prototype, "branchId", void 0);
|
|
316
328
|
_ts_decorate([
|
|
317
|
-
ApiProperty(
|
|
329
|
+
ApiProperty({
|
|
330
|
+
description: 'When this permission was created'
|
|
331
|
+
}),
|
|
318
332
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
319
333
|
], UserActionResponseDto.prototype, "createdAt", void 0);
|
|
320
334
|
export class RoleActionResponseDto {
|
|
@@ -328,27 +342,39 @@ export class RoleActionResponseDto {
|
|
|
328
342
|
}
|
|
329
343
|
}
|
|
330
344
|
_ts_decorate([
|
|
331
|
-
ApiProperty(
|
|
345
|
+
ApiProperty({
|
|
346
|
+
description: 'Permission ID'
|
|
347
|
+
}),
|
|
332
348
|
_ts_metadata("design:type", String)
|
|
333
349
|
], RoleActionResponseDto.prototype, "id", void 0);
|
|
334
350
|
_ts_decorate([
|
|
335
|
-
ApiProperty(
|
|
351
|
+
ApiProperty({
|
|
352
|
+
description: 'Role ID'
|
|
353
|
+
}),
|
|
336
354
|
_ts_metadata("design:type", String)
|
|
337
355
|
], RoleActionResponseDto.prototype, "roleId", void 0);
|
|
338
356
|
_ts_decorate([
|
|
339
|
-
ApiProperty(
|
|
357
|
+
ApiProperty({
|
|
358
|
+
description: 'Action ID'
|
|
359
|
+
}),
|
|
340
360
|
_ts_metadata("design:type", String)
|
|
341
361
|
], RoleActionResponseDto.prototype, "actionId", void 0);
|
|
342
362
|
_ts_decorate([
|
|
343
|
-
ApiProperty(
|
|
363
|
+
ApiProperty({
|
|
364
|
+
description: 'Action code'
|
|
365
|
+
}),
|
|
344
366
|
_ts_metadata("design:type", String)
|
|
345
367
|
], RoleActionResponseDto.prototype, "actionCode", void 0);
|
|
346
368
|
_ts_decorate([
|
|
347
|
-
ApiProperty(
|
|
369
|
+
ApiProperty({
|
|
370
|
+
description: 'Action name'
|
|
371
|
+
}),
|
|
348
372
|
_ts_metadata("design:type", String)
|
|
349
373
|
], RoleActionResponseDto.prototype, "actionName", void 0);
|
|
350
374
|
_ts_decorate([
|
|
351
|
-
ApiProperty(
|
|
375
|
+
ApiProperty({
|
|
376
|
+
description: 'When this permission was created'
|
|
377
|
+
}),
|
|
352
378
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
353
379
|
], RoleActionResponseDto.prototype, "createdAt", void 0);
|
|
354
380
|
export class CompanyActionResponseDto {
|
|
@@ -408,27 +434,39 @@ export class UserRoleResponseDto {
|
|
|
408
434
|
}
|
|
409
435
|
}
|
|
410
436
|
_ts_decorate([
|
|
411
|
-
ApiProperty(
|
|
437
|
+
ApiProperty({
|
|
438
|
+
description: 'Permission ID'
|
|
439
|
+
}),
|
|
412
440
|
_ts_metadata("design:type", String)
|
|
413
441
|
], UserRoleResponseDto.prototype, "id", void 0);
|
|
414
442
|
_ts_decorate([
|
|
415
|
-
ApiProperty(
|
|
443
|
+
ApiProperty({
|
|
444
|
+
description: 'User ID'
|
|
445
|
+
}),
|
|
416
446
|
_ts_metadata("design:type", String)
|
|
417
447
|
], UserRoleResponseDto.prototype, "userId", void 0);
|
|
418
448
|
_ts_decorate([
|
|
419
|
-
ApiProperty(
|
|
449
|
+
ApiProperty({
|
|
450
|
+
description: 'Role ID'
|
|
451
|
+
}),
|
|
420
452
|
_ts_metadata("design:type", String)
|
|
421
453
|
], UserRoleResponseDto.prototype, "roleId", void 0);
|
|
422
454
|
_ts_decorate([
|
|
423
|
-
ApiProperty(
|
|
455
|
+
ApiProperty({
|
|
456
|
+
description: 'Role name'
|
|
457
|
+
}),
|
|
424
458
|
_ts_metadata("design:type", String)
|
|
425
459
|
], UserRoleResponseDto.prototype, "roleName", void 0);
|
|
426
460
|
_ts_decorate([
|
|
427
|
-
ApiPropertyOptional(
|
|
461
|
+
ApiPropertyOptional({
|
|
462
|
+
description: 'Branch ID (null = company-wide)'
|
|
463
|
+
}),
|
|
428
464
|
_ts_metadata("design:type", Object)
|
|
429
465
|
], UserRoleResponseDto.prototype, "branchId", void 0);
|
|
430
466
|
_ts_decorate([
|
|
431
|
-
ApiProperty(
|
|
467
|
+
ApiProperty({
|
|
468
|
+
description: 'When this permission was created'
|
|
469
|
+
}),
|
|
432
470
|
_ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
|
|
433
471
|
], UserRoleResponseDto.prototype, "createdAt", void 0);
|
|
434
472
|
export class FrontendActionDto {
|
|
@@ -440,19 +478,27 @@ export class FrontendActionDto {
|
|
|
440
478
|
}
|
|
441
479
|
}
|
|
442
480
|
_ts_decorate([
|
|
443
|
-
ApiProperty(
|
|
481
|
+
ApiProperty({
|
|
482
|
+
description: 'Action ID'
|
|
483
|
+
}),
|
|
444
484
|
_ts_metadata("design:type", String)
|
|
445
485
|
], FrontendActionDto.prototype, "id", void 0);
|
|
446
486
|
_ts_decorate([
|
|
447
|
-
ApiProperty(
|
|
487
|
+
ApiProperty({
|
|
488
|
+
description: 'Action code'
|
|
489
|
+
}),
|
|
448
490
|
_ts_metadata("design:type", String)
|
|
449
491
|
], FrontendActionDto.prototype, "code", void 0);
|
|
450
492
|
_ts_decorate([
|
|
451
|
-
ApiProperty(
|
|
493
|
+
ApiProperty({
|
|
494
|
+
description: 'Action name'
|
|
495
|
+
}),
|
|
452
496
|
_ts_metadata("design:type", String)
|
|
453
497
|
], FrontendActionDto.prototype, "name", void 0);
|
|
454
498
|
_ts_decorate([
|
|
455
|
-
ApiPropertyOptional(
|
|
499
|
+
ApiPropertyOptional({
|
|
500
|
+
description: 'Action description'
|
|
501
|
+
}),
|
|
456
502
|
_ts_metadata("design:type", Object)
|
|
457
503
|
], FrontendActionDto.prototype, "description", void 0);
|
|
458
504
|
export class MyPermissionsQueryDto {
|
|
@@ -507,18 +553,26 @@ export class PermissionOperationResultDto {
|
|
|
507
553
|
}
|
|
508
554
|
}
|
|
509
555
|
_ts_decorate([
|
|
510
|
-
ApiProperty(
|
|
556
|
+
ApiProperty({
|
|
557
|
+
description: 'Whether the operation succeeded'
|
|
558
|
+
}),
|
|
511
559
|
_ts_metadata("design:type", Boolean)
|
|
512
560
|
], PermissionOperationResultDto.prototype, "success", void 0);
|
|
513
561
|
_ts_decorate([
|
|
514
|
-
ApiProperty(
|
|
562
|
+
ApiProperty({
|
|
563
|
+
description: 'Number of permissions added'
|
|
564
|
+
}),
|
|
515
565
|
_ts_metadata("design:type", Number)
|
|
516
566
|
], PermissionOperationResultDto.prototype, "added", void 0);
|
|
517
567
|
_ts_decorate([
|
|
518
|
-
ApiProperty(
|
|
568
|
+
ApiProperty({
|
|
569
|
+
description: 'Number of permissions removed'
|
|
570
|
+
}),
|
|
519
571
|
_ts_metadata("design:type", Number)
|
|
520
572
|
], PermissionOperationResultDto.prototype, "removed", void 0);
|
|
521
573
|
_ts_decorate([
|
|
522
|
-
ApiProperty(
|
|
574
|
+
ApiProperty({
|
|
575
|
+
description: 'Operation result message'
|
|
576
|
+
}),
|
|
523
577
|
_ts_metadata("design:type", String)
|
|
524
578
|
], PermissionOperationResultDto.prototype, "message", void 0);
|
package/fesm/dtos/role.dto.js
CHANGED
|
@@ -104,30 +104,6 @@ _ts_decorate([
|
|
|
104
104
|
IsNotEmpty(),
|
|
105
105
|
_ts_metadata("design:type", String)
|
|
106
106
|
], UpdateRoleDto.prototype, "id", void 0);
|
|
107
|
-
export class RoleQueryDto {
|
|
108
|
-
constructor(){
|
|
109
|
-
_define_property(this, "companyId", void 0);
|
|
110
|
-
_define_property(this, "isActive", void 0);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
_ts_decorate([
|
|
114
|
-
ApiProperty({
|
|
115
|
-
description: 'Filter by company ID - Only available when company feature is enabled',
|
|
116
|
-
required: false
|
|
117
|
-
}),
|
|
118
|
-
IsUUID(),
|
|
119
|
-
IsOptional(),
|
|
120
|
-
_ts_metadata("design:type", String)
|
|
121
|
-
], RoleQueryDto.prototype, "companyId", void 0);
|
|
122
|
-
_ts_decorate([
|
|
123
|
-
ApiProperty({
|
|
124
|
-
description: 'Filter by active status',
|
|
125
|
-
required: false
|
|
126
|
-
}),
|
|
127
|
-
IsBoolean(),
|
|
128
|
-
IsOptional(),
|
|
129
|
-
_ts_metadata("design:type", Boolean)
|
|
130
|
-
], RoleQueryDto.prototype, "isActive", void 0);
|
|
131
107
|
export class RoleResponseDto {
|
|
132
108
|
constructor(){
|
|
133
109
|
_define_property(this, "id", void 0);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ForbiddenException } from '@nestjs/common';
|
|
2
|
+
/**
|
|
3
|
+
* Validates that user has access to the specified company.
|
|
4
|
+
* Used for user-action and role-permission operations when company feature is enabled.
|
|
5
|
+
*
|
|
6
|
+
* @throws ForbiddenException if user doesn't have access to the company
|
|
7
|
+
*/ export function validateCompanyAccess(config, companyId, user, errorMessage = 'You do not have access to this company') {
|
|
8
|
+
if (!config.isCompanyFeatureEnabled() || !companyId) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (user.companyId !== companyId) {
|
|
12
|
+
throw new ForbiddenException(errorMessage);
|
|
13
|
+
}
|
|
14
|
+
}
|
package/fesm/helpers/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './company-access.helper';
|
|
2
2
|
export * from './permission-mode.helper';
|
package/fesm/interfaces/index.js
CHANGED
|
@@ -6,16 +6,14 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
6
6
|
}
|
|
7
7
|
import { PERMISSION_GUARD_CONFIG } from '@flusys/nestjs-shared';
|
|
8
8
|
import { CacheModule, UtilsModule } from '@flusys/nestjs-shared/modules';
|
|
9
|
-
import { Module
|
|
10
|
-
import { getRepositoryToken } from '@nestjs/typeorm';
|
|
9
|
+
import { Module } from '@nestjs/common';
|
|
11
10
|
import { IAM_MODULE_OPTIONS } from '../config/iam.constants';
|
|
12
11
|
import { ActionController, CompanyActionPermissionController, MyPermissionController, RoleController, RolePermissionController, UserActionPermissionController } from '../controllers';
|
|
13
|
-
import { Action, Role, RoleWithCompany, UserIamPermission, UserIamPermissionWithCompany } from '../entities';
|
|
14
12
|
import { IAMPermissionMode } from '../enums/permission-type.enum';
|
|
15
|
-
import {
|
|
13
|
+
import { PermissionModeHelper } from '../helpers';
|
|
16
14
|
import { ActionService, PermissionService, RoleService } from '../services';
|
|
17
15
|
import { IAMConfigService } from '../services/iam-config.service';
|
|
18
|
-
import {
|
|
16
|
+
import { IAMDataSourceService } from '../services/iam-datasource.service';
|
|
19
17
|
import { PermissionCacheService } from '../services/permission-cache.service';
|
|
20
18
|
export class IAMModule {
|
|
21
19
|
static getControllers(permissionMode, enableCompanyFeature) {
|
|
@@ -44,33 +42,11 @@ export class IAMModule {
|
|
|
44
42
|
}
|
|
45
43
|
return baseControllers;
|
|
46
44
|
}
|
|
47
|
-
static getEntities(permissionMode, enableCompanyFeature) {
|
|
48
|
-
// Core entities
|
|
49
|
-
const entities = [];
|
|
50
|
-
// Action entity - always included
|
|
51
|
-
entities.push(Action);
|
|
52
|
-
// Permission entity is always needed
|
|
53
|
-
if (enableCompanyFeature) {
|
|
54
|
-
entities.push(UserIamPermissionWithCompany);
|
|
55
|
-
} else {
|
|
56
|
-
entities.push(UserIamPermission);
|
|
57
|
-
}
|
|
58
|
-
// Role entity - Only for RBAC or FULL mode
|
|
59
|
-
if (permissionMode === IAMPermissionMode.RBAC || permissionMode === IAMPermissionMode.FULL) {
|
|
60
|
-
if (enableCompanyFeature) {
|
|
61
|
-
entities.push(RoleWithCompany);
|
|
62
|
-
} else {
|
|
63
|
-
entities.push(Role);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return entities;
|
|
67
|
-
}
|
|
68
45
|
static getServices(permissionMode) {
|
|
69
46
|
const services = [
|
|
70
47
|
ActionService,
|
|
71
48
|
PermissionService,
|
|
72
|
-
PermissionCacheService
|
|
73
|
-
PermissionEvaluatorHelper
|
|
49
|
+
PermissionCacheService
|
|
74
50
|
];
|
|
75
51
|
// RoleService - Only for RBAC or FULL mode
|
|
76
52
|
if (permissionMode === IAMPermissionMode.RBAC || permissionMode === IAMPermissionMode.FULL) {
|
|
@@ -78,10 +54,7 @@ export class IAMModule {
|
|
|
78
54
|
}
|
|
79
55
|
return services;
|
|
80
56
|
}
|
|
81
|
-
|
|
82
|
-
* Provide PermissionGuard config with enableCompanyFeature
|
|
83
|
-
* This ensures guard uses correct cache key format matching the permission cache service
|
|
84
|
-
*/ static getPermissionGuardConfigProvider(enableCompanyFeature) {
|
|
57
|
+
static getPermissionGuardConfigProvider(enableCompanyFeature) {
|
|
85
58
|
return {
|
|
86
59
|
provide: PERMISSION_GUARD_CONFIG,
|
|
87
60
|
useValue: {
|
|
@@ -89,30 +62,24 @@ export class IAMModule {
|
|
|
89
62
|
}
|
|
90
63
|
};
|
|
91
64
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
]
|
|
106
|
-
}));
|
|
65
|
+
static getExports(permissionMode) {
|
|
66
|
+
const baseExports = [
|
|
67
|
+
IAMConfigService,
|
|
68
|
+
IAMDataSourceService,
|
|
69
|
+
ActionService,
|
|
70
|
+
PermissionService,
|
|
71
|
+
PermissionCacheService,
|
|
72
|
+
PERMISSION_GUARD_CONFIG
|
|
73
|
+
];
|
|
74
|
+
if (permissionMode === IAMPermissionMode.RBAC || permissionMode === IAMPermissionMode.FULL) {
|
|
75
|
+
baseExports.push(RoleService);
|
|
76
|
+
}
|
|
77
|
+
return baseExports;
|
|
107
78
|
}
|
|
108
79
|
static forRoot(options = {}) {
|
|
109
80
|
const { global = false, includeController = false } = options;
|
|
110
|
-
const databaseMode = options.bootstrapAppConfig?.databaseMode;
|
|
111
81
|
const enableCompanyFeature = options.bootstrapAppConfig?.enableCompanyFeature ?? false;
|
|
112
|
-
// Read permissionMode from bootstrap config using helper
|
|
113
82
|
const permissionMode = PermissionModeHelper.fromString(options.bootstrapAppConfig?.permissionMode);
|
|
114
|
-
const isMultiTenant = databaseMode === 'multi-tenant';
|
|
115
|
-
const entities = this.getEntities(permissionMode, enableCompanyFeature);
|
|
116
83
|
const controllers = includeController ? this.getControllers(permissionMode, enableCompanyFeature) : [];
|
|
117
84
|
const providers = [
|
|
118
85
|
{
|
|
@@ -120,87 +87,52 @@ export class IAMModule {
|
|
|
120
87
|
useValue: options
|
|
121
88
|
},
|
|
122
89
|
IAMConfigService,
|
|
123
|
-
|
|
90
|
+
IAMDataSourceService,
|
|
124
91
|
...this.getServices(permissionMode),
|
|
125
92
|
this.getPermissionGuardConfigProvider(enableCompanyFeature)
|
|
126
93
|
];
|
|
127
|
-
const imports = [
|
|
128
|
-
CacheModule,
|
|
129
|
-
UtilsModule
|
|
130
|
-
];
|
|
131
94
|
const module = {
|
|
132
95
|
module: IAMModule,
|
|
133
|
-
imports
|
|
96
|
+
imports: [
|
|
97
|
+
CacheModule,
|
|
98
|
+
UtilsModule
|
|
99
|
+
],
|
|
134
100
|
controllers,
|
|
135
101
|
providers,
|
|
136
|
-
exports:
|
|
137
|
-
IAMConfigService,
|
|
138
|
-
IAMDataSourceProvider,
|
|
139
|
-
ActionService,
|
|
140
|
-
PermissionService,
|
|
141
|
-
PermissionCacheService,
|
|
142
|
-
PermissionEvaluatorHelper,
|
|
143
|
-
PERMISSION_GUARD_CONFIG,
|
|
144
|
-
...permissionMode === IAMPermissionMode.RBAC || permissionMode === IAMPermissionMode.FULL ? [
|
|
145
|
-
RoleService
|
|
146
|
-
] : []
|
|
147
|
-
]
|
|
102
|
+
exports: this.getExports(permissionMode)
|
|
148
103
|
};
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
return module;
|
|
104
|
+
return global ? {
|
|
105
|
+
...module,
|
|
106
|
+
global: true
|
|
107
|
+
} : module;
|
|
156
108
|
}
|
|
157
109
|
static forRootAsync(asyncOptions) {
|
|
158
110
|
const { global = false, includeController = false, imports: externalImports = [] } = asyncOptions;
|
|
159
|
-
const databaseMode = asyncOptions.bootstrapAppConfig?.databaseMode;
|
|
160
111
|
const enableCompanyFeature = asyncOptions.bootstrapAppConfig?.enableCompanyFeature ?? false;
|
|
161
|
-
// Read permissionMode from bootstrap config using helper
|
|
162
112
|
const permissionMode = PermissionModeHelper.fromString(asyncOptions.bootstrapAppConfig?.permissionMode);
|
|
163
|
-
const isMultiTenant = databaseMode === 'multi-tenant';
|
|
164
|
-
const entities = this.getEntities(permissionMode, enableCompanyFeature);
|
|
165
113
|
const controllers = includeController ? this.getControllers(permissionMode, enableCompanyFeature) : [];
|
|
166
|
-
const asyncProviders = this.createAsyncProviders(asyncOptions);
|
|
167
114
|
const providers = [
|
|
168
|
-
...
|
|
115
|
+
...this.createAsyncProviders(asyncOptions),
|
|
169
116
|
IAMConfigService,
|
|
170
|
-
|
|
117
|
+
IAMDataSourceService,
|
|
171
118
|
...this.getServices(permissionMode),
|
|
172
119
|
this.getPermissionGuardConfigProvider(enableCompanyFeature)
|
|
173
120
|
];
|
|
174
|
-
const imports = [
|
|
175
|
-
...externalImports,
|
|
176
|
-
CacheModule,
|
|
177
|
-
UtilsModule
|
|
178
|
-
];
|
|
179
121
|
const module = {
|
|
180
122
|
module: IAMModule,
|
|
181
|
-
imports
|
|
123
|
+
imports: [
|
|
124
|
+
...externalImports,
|
|
125
|
+
CacheModule,
|
|
126
|
+
UtilsModule
|
|
127
|
+
],
|
|
182
128
|
controllers,
|
|
183
129
|
providers,
|
|
184
|
-
exports:
|
|
185
|
-
IAMConfigService,
|
|
186
|
-
IAMDataSourceProvider,
|
|
187
|
-
ActionService,
|
|
188
|
-
PermissionService,
|
|
189
|
-
PermissionCacheService,
|
|
190
|
-
PermissionEvaluatorHelper,
|
|
191
|
-
PERMISSION_GUARD_CONFIG,
|
|
192
|
-
...permissionMode === IAMPermissionMode.RBAC || permissionMode === IAMPermissionMode.FULL ? [
|
|
193
|
-
RoleService
|
|
194
|
-
] : []
|
|
195
|
-
]
|
|
130
|
+
exports: this.getExports(permissionMode)
|
|
196
131
|
};
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
return module;
|
|
132
|
+
return global ? {
|
|
133
|
+
...module,
|
|
134
|
+
global: true
|
|
135
|
+
} : module;
|
|
204
136
|
}
|
|
205
137
|
static createAsyncProviders(options) {
|
|
206
138
|
if (options.useExisting || options.useFactory) {
|