@flusys/nestjs-iam 1.1.0-beta → 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.
Files changed (76) hide show
  1. package/README.md +285 -115
  2. package/cjs/controllers/action.controller.js +45 -2
  3. package/cjs/controllers/company-action-permission.controller.js +16 -10
  4. package/cjs/controllers/my-permission.controller.js +7 -3
  5. package/cjs/controllers/role-permission.controller.js +35 -17
  6. package/cjs/controllers/role.controller.js +46 -3
  7. package/cjs/controllers/user-action-permission.controller.js +26 -11
  8. package/cjs/dtos/action.dto.js +0 -27
  9. package/cjs/dtos/permission.dto.js +117 -27
  10. package/cjs/dtos/role.dto.js +0 -27
  11. package/cjs/entities/permission-base.entity.js +0 -12
  12. package/cjs/helpers/company-access.helper.js +19 -0
  13. package/cjs/helpers/index.js +1 -1
  14. package/cjs/interfaces/iam-module-options.interface.js +0 -14
  15. package/cjs/interfaces/index.js +0 -1
  16. package/cjs/modules/iam.module.js +50 -102
  17. package/cjs/services/action.service.js +30 -41
  18. package/cjs/services/iam-config.service.js +2 -5
  19. package/cjs/services/{iam-datasource.provider.js → iam-datasource.service.js} +33 -36
  20. package/cjs/services/index.js +1 -1
  21. package/cjs/services/permission-cache.service.js +31 -61
  22. package/cjs/services/permission.service.js +160 -188
  23. package/cjs/services/role.service.js +8 -8
  24. package/cjs/types/logic-node.type.js +0 -24
  25. package/controllers/company-action-permission.controller.d.ts +3 -3
  26. package/controllers/my-permission.controller.d.ts +2 -2
  27. package/controllers/role-permission.controller.d.ts +7 -5
  28. package/controllers/user-action-permission.controller.d.ts +6 -4
  29. package/dtos/action.dto.d.ts +0 -7
  30. package/dtos/permission.dto.d.ts +4 -0
  31. package/dtos/role.dto.d.ts +0 -7
  32. package/entities/permission-base.entity.d.ts +0 -4
  33. package/fesm/controllers/action.controller.js +47 -4
  34. package/fesm/controllers/company-action-permission.controller.js +18 -12
  35. package/fesm/controllers/index.js +1 -1
  36. package/fesm/controllers/my-permission.controller.js +7 -3
  37. package/fesm/controllers/role-permission.controller.js +37 -19
  38. package/fesm/controllers/role.controller.js +45 -2
  39. package/fesm/controllers/user-action-permission.controller.js +28 -13
  40. package/fesm/dtos/action.dto.js +0 -24
  41. package/fesm/dtos/permission.dto.js +117 -29
  42. package/fesm/dtos/role.dto.js +0 -24
  43. package/fesm/entities/permission-base.entity.js +0 -12
  44. package/fesm/helpers/company-access.helper.js +14 -0
  45. package/fesm/helpers/index.js +1 -1
  46. package/fesm/interfaces/iam-module-options.interface.js +3 -1
  47. package/fesm/interfaces/index.js +0 -1
  48. package/fesm/modules/iam.module.js +52 -104
  49. package/fesm/services/action.service.js +32 -43
  50. package/fesm/services/iam-config.service.js +2 -5
  51. package/fesm/services/{iam-datasource.provider.js → iam-datasource.service.js} +31 -34
  52. package/fesm/services/index.js +1 -1
  53. package/fesm/services/permission-cache.service.js +31 -61
  54. package/fesm/services/permission.service.js +161 -189
  55. package/fesm/services/role.service.js +8 -8
  56. package/fesm/types/logic-node.type.js +1 -10
  57. package/helpers/company-access.helper.d.ts +3 -0
  58. package/helpers/index.d.ts +1 -1
  59. package/interfaces/iam-module-options.interface.d.ts +9 -1
  60. package/interfaces/index.d.ts +0 -1
  61. package/modules/iam.module.d.ts +2 -2
  62. package/package.json +3 -3
  63. package/services/action.service.d.ts +6 -4
  64. package/services/iam-config.service.d.ts +2 -2
  65. package/services/{iam-datasource.provider.d.ts → iam-datasource.service.d.ts} +4 -5
  66. package/services/index.d.ts +1 -1
  67. package/services/permission-cache.service.d.ts +4 -6
  68. package/services/permission.service.d.ts +8 -4
  69. package/services/role.service.d.ts +3 -3
  70. package/types/logic-node.type.d.ts +0 -8
  71. package/cjs/helpers/permission-evaluator.helper.js +0 -175
  72. package/cjs/interfaces/iam-module-async-options.interface.js +0 -4
  73. package/fesm/helpers/permission-evaluator.helper.js +0 -165
  74. package/fesm/interfaces/iam-module-async-options.interface.js +0 -3
  75. package/helpers/permission-evaluator.helper.d.ts +0 -26
  76. package/interfaces/iam-module-async-options.interface.d.ts +0 -11
@@ -10,11 +10,12 @@ Object.defineProperty(exports, "RoleService", {
10
10
  });
11
11
  const _classes = require("@flusys/nestjs-shared/classes");
12
12
  const _modules = require("@flusys/nestjs-shared/modules");
13
+ const _utils = require("@flusys/nestjs-shared/utils");
13
14
  const _common = require("@nestjs/common");
14
15
  const _rolewithcompanyentity = require("../entities/role-with-company.entity");
15
16
  const _roleentity = require("../entities/role.entity");
16
17
  const _iamconfigservice = require("./iam-config.service");
17
- const _iamdatasourceprovider = require("./iam-datasource.provider");
18
+ const _iamdatasourceservice = require("./iam-datasource.service");
18
19
  function _define_property(obj, key, value) {
19
20
  if (key in obj) {
20
21
  Object.defineProperty(obj, key, {
@@ -95,11 +96,10 @@ let RoleService = class RoleService extends _classes.RequestScopedApiService {
95
96
  }
96
97
  async getExtraManipulateQuery(query, filterDto, user) {
97
98
  const result = await super.getExtraManipulateQuery(query, filterDto, user);
98
- if (this.iamConfigService.isCompanyFeatureEnabled() && user?.companyId) {
99
- query.andWhere('role.companyId = :companyId', {
100
- companyId: user.companyId
101
- });
102
- }
99
+ (0, _utils.applyCompanyFilter)(query, {
100
+ isCompanyFeatureEnabled: this.iamConfigService.isCompanyFeatureEnabled(),
101
+ entityAlias: 'role'
102
+ }, user);
103
103
  return result;
104
104
  }
105
105
  // Response Conversion
@@ -132,12 +132,12 @@ RoleService = _ts_decorate([
132
132
  _ts_param(0, (0, _common.Inject)('CACHE_INSTANCE')),
133
133
  _ts_param(1, (0, _common.Inject)(_modules.UtilsService)),
134
134
  _ts_param(2, (0, _common.Inject)(_iamconfigservice.IAMConfigService)),
135
- _ts_param(3, (0, _common.Inject)(_iamdatasourceprovider.IAMDataSourceProvider)),
135
+ _ts_param(3, (0, _common.Inject)(_iamdatasourceservice.IAMDataSourceService)),
136
136
  _ts_metadata("design:type", Function),
137
137
  _ts_metadata("design:paramtypes", [
138
138
  typeof _classes.HybridCache === "undefined" ? Object : _classes.HybridCache,
139
139
  typeof _modules.UtilsService === "undefined" ? Object : _modules.UtilsService,
140
140
  typeof _iamconfigservice.IAMConfigService === "undefined" ? Object : _iamconfigservice.IAMConfigService,
141
- typeof _iamdatasourceprovider.IAMDataSourceProvider === "undefined" ? Object : _iamdatasourceprovider.IAMDataSourceProvider
141
+ typeof _iamdatasourceservice.IAMDataSourceService === "undefined" ? Object : _iamdatasourceservice.IAMDataSourceService
142
142
  ])
143
143
  ], RoleService);
@@ -28,27 +28,3 @@
28
28
  Object.defineProperty(exports, "__esModule", {
29
29
  value: true
30
30
  });
31
- function _export(target, all) {
32
- for(var name in all)Object.defineProperty(target, name, {
33
- enumerable: true,
34
- get: Object.getOwnPropertyDescriptor(all, name).get
35
- });
36
- }
37
- _export(exports, {
38
- get LogicNodeType () {
39
- return LogicNodeType;
40
- },
41
- get LogicOperator () {
42
- return LogicOperator;
43
- }
44
- });
45
- var LogicOperator = /*#__PURE__*/ function(LogicOperator) {
46
- LogicOperator["AND"] = "AND";
47
- LogicOperator["OR"] = "OR";
48
- return LogicOperator;
49
- }({});
50
- var LogicNodeType = /*#__PURE__*/ function(LogicNodeType) {
51
- LogicNodeType["GROUP"] = "group";
52
- LogicNodeType["ACTION"] = "action";
53
- return LogicNodeType;
54
- }({});
@@ -1,9 +1,9 @@
1
- import { SingleResponseDto } from '@flusys/nestjs-shared';
1
+ import { ILoggedUserInfo, SingleResponseDto } from '@flusys/nestjs-shared';
2
2
  import { AssignCompanyActionsDto, CompanyActionResponseDto, GetCompanyActionsDto, PermissionOperationResultDto } from '../dtos/permission.dto';
3
3
  import { PermissionService } from '../services/permission.service';
4
4
  export declare class CompanyActionPermissionController {
5
5
  private readonly permissionService;
6
6
  constructor(permissionService: PermissionService);
7
- assignCompanyActions(dto: AssignCompanyActionsDto): Promise<PermissionOperationResultDto>;
8
- getCompanyActions(companyId: string, query: GetCompanyActionsDto): Promise<SingleResponseDto<CompanyActionResponseDto[]>>;
7
+ assignCompanyActions(dto: AssignCompanyActionsDto, user: ILoggedUserInfo): Promise<PermissionOperationResultDto>;
8
+ getCompanyActions(dto: GetCompanyActionsDto, user: ILoggedUserInfo): Promise<SingleResponseDto<CompanyActionResponseDto[]>>;
9
9
  }
@@ -1,8 +1,8 @@
1
- import { ILoggedUserInfo } from '@flusys/nestjs-shared';
1
+ import { ILoggedUserInfo, SingleResponseDto } from '@flusys/nestjs-shared';
2
2
  import { MyPermissionsQueryDto, MyPermissionsResponseDto } from '../dtos/permission.dto';
3
3
  import { PermissionService } from '../services/permission.service';
4
4
  export declare class MyPermissionController {
5
5
  private readonly permissionService;
6
6
  constructor(permissionService: PermissionService);
7
- getMyPermissions(query: MyPermissionsQueryDto, user: ILoggedUserInfo): Promise<MyPermissionsResponseDto>;
7
+ getMyPermissions(query: MyPermissionsQueryDto, user: ILoggedUserInfo): Promise<SingleResponseDto<MyPermissionsResponseDto>>;
8
8
  }
@@ -1,11 +1,13 @@
1
- import { SingleResponseDto } from '@flusys/nestjs-shared';
1
+ import { SingleResponseDto, ILoggedUserInfo } from '@flusys/nestjs-shared';
2
2
  import { AssignRoleActionsDto, AssignUserRolesDto, GetRoleActionsDto, GetUserRolesDto, PermissionOperationResultDto, RoleActionResponseDto, UserRoleResponseDto } from '../dtos/permission.dto';
3
3
  import { PermissionService } from '../services/permission.service';
4
+ import { IAMConfigService } from '../services/iam-config.service';
4
5
  export declare class RolePermissionController {
5
6
  private readonly permissionService;
6
- constructor(permissionService: PermissionService);
7
+ private readonly config;
8
+ constructor(permissionService: PermissionService, config: IAMConfigService);
7
9
  assignRoleActions(dto: AssignRoleActionsDto): Promise<PermissionOperationResultDto>;
8
- getRoleActions(roleId: string, query: GetRoleActionsDto): Promise<SingleResponseDto<RoleActionResponseDto[]>>;
9
- assignUserRoles(dto: AssignUserRolesDto): Promise<PermissionOperationResultDto>;
10
- getUserRoles(userId: string, query: GetUserRolesDto): Promise<SingleResponseDto<UserRoleResponseDto[]>>;
10
+ getRoleActions(dto: GetRoleActionsDto): Promise<SingleResponseDto<RoleActionResponseDto[]>>;
11
+ assignUserRoles(dto: AssignUserRolesDto, user: ILoggedUserInfo): Promise<PermissionOperationResultDto>;
12
+ getUserRoles(dto: GetUserRolesDto, user: ILoggedUserInfo): Promise<SingleResponseDto<UserRoleResponseDto[]>>;
11
13
  }
@@ -1,9 +1,11 @@
1
- import { SingleResponseDto } from '@flusys/nestjs-shared';
1
+ import { SingleResponseDto, ILoggedUserInfo } from '@flusys/nestjs-shared';
2
2
  import { AssignUserActionsDto, GetUserActionsDto, PermissionOperationResultDto, UserActionResponseDto } from '../dtos/permission.dto';
3
3
  import { PermissionService } from '../services/permission.service';
4
+ import { IAMConfigService } from '../services/iam-config.service';
4
5
  export declare class UserActionPermissionController {
5
6
  private readonly permissionService;
6
- constructor(permissionService: PermissionService);
7
- assignUserActions(dto: AssignUserActionsDto): Promise<PermissionOperationResultDto>;
8
- getUserActions(userId: string, query: GetUserActionsDto): Promise<SingleResponseDto<UserActionResponseDto[]>>;
7
+ private readonly config;
8
+ constructor(permissionService: PermissionService, config: IAMConfigService);
9
+ assignUserActions(dto: AssignUserActionsDto, user: ILoggedUserInfo): Promise<PermissionOperationResultDto>;
10
+ getUserActions(dto: GetUserActionsDto, user: ILoggedUserInfo): Promise<SingleResponseDto<UserActionResponseDto[]>>;
9
11
  }
@@ -1,7 +1,6 @@
1
1
  import { ActionType } from '../enums';
2
2
  import { LogicNode } from '../types';
3
3
  export declare class CreateActionDto {
4
- [key: string]: any;
5
4
  name: string;
6
5
  description?: string;
7
6
  code?: string;
@@ -14,11 +13,9 @@ export declare class CreateActionDto {
14
13
  }
15
14
  declare const UpdateActionDto_base: import("@nestjs/common").Type<Partial<CreateActionDto>>;
16
15
  export declare class UpdateActionDto extends UpdateActionDto_base {
17
- [key: string]: any;
18
16
  id: string;
19
17
  }
20
18
  export declare class ActionResponseDto {
21
- [key: string]: any;
22
19
  id: string;
23
20
  readOnly: boolean;
24
21
  name: string;
@@ -40,10 +37,6 @@ export declare class ActionResponseDto {
40
37
  export declare class ActionTreeDto extends ActionResponseDto {
41
38
  children: ActionTreeDto[];
42
39
  }
43
- export declare class ActionQueryDto {
44
- isActive?: boolean;
45
- parentId?: string;
46
- }
47
40
  export declare class ActionTreeQueryDto {
48
41
  search?: string;
49
42
  isActive?: boolean;
@@ -27,14 +27,18 @@ export declare class AssignUserRolesDto {
27
27
  items: PermissionItemDto[];
28
28
  }
29
29
  export declare class GetUserActionsDto {
30
+ userId: string;
30
31
  companyId?: string;
31
32
  branchId?: string;
32
33
  }
33
34
  export declare class GetRoleActionsDto {
35
+ roleId: string;
34
36
  }
35
37
  export declare class GetCompanyActionsDto {
38
+ companyId: string;
36
39
  }
37
40
  export declare class GetUserRolesDto {
41
+ userId: string;
38
42
  companyId?: string;
39
43
  branchId?: string;
40
44
  }
@@ -1,5 +1,4 @@
1
1
  export declare class CreateRoleDto {
2
- [key: string]: any;
3
2
  name: string;
4
3
  description?: string;
5
4
  companyId?: string;
@@ -9,15 +8,9 @@ export declare class CreateRoleDto {
9
8
  }
10
9
  declare const UpdateRoleDto_base: import("@nestjs/common").Type<Partial<CreateRoleDto>>;
11
10
  export declare class UpdateRoleDto extends UpdateRoleDto_base {
12
- [key: string]: any;
13
11
  id: string;
14
12
  }
15
- export declare class RoleQueryDto {
16
- companyId?: string;
17
- isActive?: boolean;
18
- }
19
13
  export declare class RoleResponseDto {
20
- [key: string]: any;
21
14
  id: string;
22
15
  readOnly: boolean;
23
16
  name: string;
@@ -22,9 +22,5 @@ export declare abstract class PermissionBase extends Identity {
22
22
  validUntil: Date | null;
23
23
  reason: string | null;
24
24
  metadata: Record<string, any> | null;
25
- isUserRole(): boolean;
26
- isRoleAction(): boolean;
27
- isUserAction(): boolean;
28
- isCompanyAction(): boolean;
29
25
  isValid(now?: Date): boolean;
30
26
  }
@@ -26,13 +26,56 @@ function _ts_param(paramIndex, decorator) {
26
26
  };
27
27
  }
28
28
  import { JwtAuthGuard } from '@flusys/nestjs-shared/guards';
29
- import { createApiController, CurrentUser, ILoggedUserInfo, SingleResponseDto } from '@flusys/nestjs-shared';
30
- import { Body, Controller, Get, Inject, Post, UseGuards } from '@nestjs/common';
29
+ import { createApiController, CurrentUser, ILoggedUserInfo, SingleResponseDto, ACTION_PERMISSIONS } from '@flusys/nestjs-shared';
30
+ import { Body, Controller, Inject, Post, UseGuards } from '@nestjs/common';
31
31
  import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
32
32
  import { ActionResponseDto, ActionTreeQueryDto, CreateActionDto, UpdateActionDto } from '../dtos/action.dto';
33
33
  import { ActionService } from '../services/action.service';
34
34
  export class ActionController extends createApiController(CreateActionDto, UpdateActionDto, ActionResponseDto, {
35
- security: 'jwt'
35
+ security: {
36
+ insert: {
37
+ level: 'permission',
38
+ permissions: [
39
+ ACTION_PERMISSIONS.CREATE
40
+ ]
41
+ },
42
+ insertMany: {
43
+ level: 'permission',
44
+ permissions: [
45
+ ACTION_PERMISSIONS.CREATE
46
+ ]
47
+ },
48
+ getById: {
49
+ level: 'permission',
50
+ permissions: [
51
+ ACTION_PERMISSIONS.READ
52
+ ]
53
+ },
54
+ getAll: {
55
+ level: 'permission',
56
+ permissions: [
57
+ ACTION_PERMISSIONS.READ
58
+ ]
59
+ },
60
+ update: {
61
+ level: 'permission',
62
+ permissions: [
63
+ ACTION_PERMISSIONS.UPDATE
64
+ ]
65
+ },
66
+ updateMany: {
67
+ level: 'permission',
68
+ permissions: [
69
+ ACTION_PERMISSIONS.UPDATE
70
+ ]
71
+ },
72
+ delete: {
73
+ level: 'permission',
74
+ permissions: [
75
+ ACTION_PERMISSIONS.DELETE
76
+ ]
77
+ }
78
+ }
36
79
  }) {
37
80
  async getActionsForPermission(user) {
38
81
  const actions = await this.actionService.getActionsForPermission(user);
@@ -55,7 +98,7 @@ export class ActionController extends createApiController(CreateActionDto, Updat
55
98
  }
56
99
  }
57
100
  _ts_decorate([
58
- Get('tree-for-permission'),
101
+ Post('tree-for-permission'),
59
102
  UseGuards(JwtAuthGuard),
60
103
  ApiBearerAuth(),
61
104
  ApiOperation({
@@ -25,24 +25,23 @@ function _ts_param(paramIndex, decorator) {
25
25
  decorator(target, key, paramIndex);
26
26
  };
27
27
  }
28
- import { JwtAuthGuard, SingleResponseDto } from '@flusys/nestjs-shared';
29
- import { Body, Controller, Get, Inject, Param, Post, Query, UseGuards } from '@nestjs/common';
28
+ import { COMPANY_ACTION_PERMISSIONS, CurrentUser, ILoggedUserInfo, JwtAuthGuard, RequirePermission, SingleResponseDto } from '@flusys/nestjs-shared';
29
+ import { Body, Controller, Inject, Post, UseGuards } from '@nestjs/common';
30
30
  import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
31
31
  import { AssignCompanyActionsDto, GetCompanyActionsDto, PermissionOperationResultDto } from '../dtos/permission.dto';
32
32
  import { PermissionService } from '../services/permission.service';
33
33
  export class CompanyActionPermissionController {
34
- async assignCompanyActions(dto) {
34
+ async assignCompanyActions(dto, user) {
35
35
  return this.permissionService.assignCompanyActions(dto);
36
36
  }
37
- async getCompanyActions(companyId, query) {
38
- const actions = await this.permissionService.getCompanyActions(companyId);
37
+ async getCompanyActions(dto, user) {
38
+ const actions = await this.permissionService.getCompanyActions(dto.companyId);
39
39
  return {
40
40
  success: true,
41
41
  message: 'Company actions retrieved successfully',
42
42
  data: actions
43
43
  };
44
44
  }
45
- // NOTE: @Inject() required for bundled code - type metadata may be lost during esbuild
46
45
  constructor(permissionService){
47
46
  _define_property(this, "permissionService", void 0);
48
47
  this.permissionService = permissionService;
@@ -50,6 +49,7 @@ export class CompanyActionPermissionController {
50
49
  }
51
50
  _ts_decorate([
52
51
  Post('company-actions/assign'),
52
+ RequirePermission(COMPANY_ACTION_PERMISSIONS.ASSIGN),
53
53
  ApiOperation({
54
54
  summary: 'Whitelist actions for company',
55
55
  description: 'Controls which actions are available to company users/roles.'
@@ -62,14 +62,17 @@ _ts_decorate([
62
62
  type: AssignCompanyActionsDto
63
63
  }),
64
64
  _ts_param(0, Body()),
65
+ _ts_param(1, CurrentUser()),
65
66
  _ts_metadata("design:type", Function),
66
67
  _ts_metadata("design:paramtypes", [
67
- typeof AssignCompanyActionsDto === "undefined" ? Object : AssignCompanyActionsDto
68
+ typeof AssignCompanyActionsDto === "undefined" ? Object : AssignCompanyActionsDto,
69
+ typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
68
70
  ]),
69
71
  _ts_metadata("design:returntype", Promise)
70
72
  ], CompanyActionPermissionController.prototype, "assignCompanyActions", null);
71
73
  _ts_decorate([
72
- Get('company-actions/:companyId'),
74
+ Post('get-company-actions'),
75
+ RequirePermission(COMPANY_ACTION_PERMISSIONS.READ),
73
76
  ApiOperation({
74
77
  summary: 'Get company whitelisted actions',
75
78
  description: 'Returns actions available to company.'
@@ -78,12 +81,15 @@ _ts_decorate([
78
81
  status: 200,
79
82
  type: SingleResponseDto
80
83
  }),
81
- _ts_param(0, Param('companyId')),
82
- _ts_param(1, Query()),
84
+ ApiBody({
85
+ type: GetCompanyActionsDto
86
+ }),
87
+ _ts_param(0, Body()),
88
+ _ts_param(1, CurrentUser()),
83
89
  _ts_metadata("design:type", Function),
84
90
  _ts_metadata("design:paramtypes", [
85
- String,
86
- typeof GetCompanyActionsDto === "undefined" ? Object : GetCompanyActionsDto
91
+ typeof GetCompanyActionsDto === "undefined" ? Object : GetCompanyActionsDto,
92
+ typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
87
93
  ]),
88
94
  _ts_metadata("design:returntype", Promise)
89
95
  ], CompanyActionPermissionController.prototype, "getCompanyActions", null);
@@ -1,6 +1,6 @@
1
1
  export * from './action.controller';
2
2
  export * from './role.controller';
3
- // Legacy permission controllers (deprecated - use PermissionController instead)
3
+ // Permission controllers (conditionally registered based on permission mode)
4
4
  export * from './company-action-permission.controller';
5
5
  export * from './my-permission.controller';
6
6
  export * from './role-permission.controller';
@@ -25,15 +25,19 @@ function _ts_param(paramIndex, decorator) {
25
25
  decorator(target, key, paramIndex);
26
26
  };
27
27
  }
28
- import { CurrentUser, ILoggedUserInfo } from '@flusys/nestjs-shared';
29
- import { JwtAuthGuard } from '@flusys/nestjs-shared/guards';
28
+ import { CurrentUser, ILoggedUserInfo, JwtAuthGuard } from '@flusys/nestjs-shared';
30
29
  import { Body, Controller, Inject, Post, UseGuards } from '@nestjs/common';
31
30
  import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
32
31
  import { MyPermissionsQueryDto, MyPermissionsResponseDto } from '../dtos/permission.dto';
33
32
  import { PermissionService } from '../services/permission.service';
34
33
  export class MyPermissionController {
35
34
  async getMyPermissions(query, user) {
36
- return this.permissionService.getMyPermissions(user.id, user.branchId ?? null, user.companyId ?? null, query.parentCodes);
35
+ const data = await this.permissionService.getMyPermissions(user.id, user.branchId ?? null, user.companyId ?? null, query.parentCodes);
36
+ return {
37
+ success: true,
38
+ message: 'Permissions loaded successfully',
39
+ data
40
+ };
37
41
  }
38
42
  // NOTE: @Inject() required for bundled code - type metadata may be lost during esbuild
39
43
  constructor(permissionService){
@@ -25,28 +25,32 @@ function _ts_param(paramIndex, decorator) {
25
25
  decorator(target, key, paramIndex);
26
26
  };
27
27
  }
28
- import { JwtAuthGuard, SingleResponseDto } from '@flusys/nestjs-shared';
29
- import { Body, Controller, Get, Inject, Param, Post, Query, UseGuards } from '@nestjs/common';
28
+ import { JwtAuthGuard, SingleResponseDto, RequirePermission, ROLE_ACTION_PERMISSIONS, USER_ROLE_PERMISSIONS, CurrentUser, ILoggedUserInfo } from '@flusys/nestjs-shared';
29
+ import { Body, Controller, Inject, Post, UseGuards } from '@nestjs/common';
30
30
  import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
31
31
  import { AssignRoleActionsDto, AssignUserRolesDto, GetRoleActionsDto, GetUserRolesDto, PermissionOperationResultDto } from '../dtos/permission.dto';
32
+ import { validateCompanyAccess } from '../helpers';
32
33
  import { PermissionService } from '../services/permission.service';
34
+ import { IAMConfigService } from '../services/iam-config.service';
33
35
  export class RolePermissionController {
34
36
  async assignRoleActions(dto) {
35
37
  return this.permissionService.assignRoleActions(dto);
36
38
  }
37
- async getRoleActions(roleId, query) {
38
- const actions = await this.permissionService.getRoleActions(roleId);
39
+ async getRoleActions(dto) {
40
+ const actions = await this.permissionService.getRoleActions(dto.roleId);
39
41
  return {
40
42
  success: true,
41
43
  message: 'Role actions retrieved successfully',
42
44
  data: actions
43
45
  };
44
46
  }
45
- async assignUserRoles(dto) {
47
+ async assignUserRoles(dto, user) {
48
+ validateCompanyAccess(this.config, dto.companyId, user, 'Cannot manage permissions for users in another company');
46
49
  return this.permissionService.assignUserRoles(dto);
47
50
  }
48
- async getUserRoles(userId, query) {
49
- const roles = await this.permissionService.getUserRoles(userId, query.branchId, query.companyId);
51
+ async getUserRoles(dto, user) {
52
+ validateCompanyAccess(this.config, dto.companyId, user, 'Cannot manage permissions for users in another company');
53
+ const roles = await this.permissionService.getUserRoles(dto.userId, dto.branchId, dto.companyId);
50
54
  return {
51
55
  success: true,
52
56
  message: 'User roles retrieved successfully',
@@ -54,13 +58,16 @@ export class RolePermissionController {
54
58
  };
55
59
  }
56
60
  // NOTE: @Inject() required for bundled code - type metadata may be lost during esbuild
57
- constructor(permissionService){
61
+ constructor(permissionService, config){
58
62
  _define_property(this, "permissionService", void 0);
63
+ _define_property(this, "config", void 0);
59
64
  this.permissionService = permissionService;
65
+ this.config = config;
60
66
  }
61
67
  }
62
68
  _ts_decorate([
63
69
  Post('role-actions/assign'),
70
+ RequirePermission(ROLE_ACTION_PERMISSIONS.ASSIGN),
64
71
  ApiOperation({
65
72
  summary: 'Assign/remove actions to/from role',
66
73
  description: 'RBAC mode. No branch scoping.'
@@ -80,7 +87,8 @@ _ts_decorate([
80
87
  _ts_metadata("design:returntype", Promise)
81
88
  ], RolePermissionController.prototype, "assignRoleActions", null);
82
89
  _ts_decorate([
83
- Get('role-actions/:roleId'),
90
+ Post('get-role-actions'),
91
+ RequirePermission(ROLE_ACTION_PERMISSIONS.READ),
84
92
  ApiOperation({
85
93
  summary: 'Get role actions',
86
94
  description: 'Returns actions assigned to role.'
@@ -89,17 +97,19 @@ _ts_decorate([
89
97
  status: 200,
90
98
  type: SingleResponseDto
91
99
  }),
92
- _ts_param(0, Param('roleId')),
93
- _ts_param(1, Query()),
100
+ ApiBody({
101
+ type: GetRoleActionsDto
102
+ }),
103
+ _ts_param(0, Body()),
94
104
  _ts_metadata("design:type", Function),
95
105
  _ts_metadata("design:paramtypes", [
96
- String,
97
106
  typeof GetRoleActionsDto === "undefined" ? Object : GetRoleActionsDto
98
107
  ]),
99
108
  _ts_metadata("design:returntype", Promise)
100
109
  ], RolePermissionController.prototype, "getRoleActions", null);
101
110
  _ts_decorate([
102
111
  Post('user-roles/assign'),
112
+ RequirePermission(USER_ROLE_PERMISSIONS.ASSIGN),
103
113
  ApiOperation({
104
114
  summary: 'Assign/remove roles to/from user',
105
115
  description: 'RBAC mode. If company feature enabled, branchId is required.'
@@ -112,14 +122,17 @@ _ts_decorate([
112
122
  type: AssignUserRolesDto
113
123
  }),
114
124
  _ts_param(0, Body()),
125
+ _ts_param(1, CurrentUser()),
115
126
  _ts_metadata("design:type", Function),
116
127
  _ts_metadata("design:paramtypes", [
117
- typeof AssignUserRolesDto === "undefined" ? Object : AssignUserRolesDto
128
+ typeof AssignUserRolesDto === "undefined" ? Object : AssignUserRolesDto,
129
+ typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
118
130
  ]),
119
131
  _ts_metadata("design:returntype", Promise)
120
132
  ], RolePermissionController.prototype, "assignUserRoles", null);
121
133
  _ts_decorate([
122
- Get('user-roles/:userId'),
134
+ Post('get-user-roles'),
135
+ RequirePermission(USER_ROLE_PERMISSIONS.READ),
123
136
  ApiOperation({
124
137
  summary: 'Get user roles',
125
138
  description: 'Returns roles assigned to user. Filter by companyId and branchId.'
@@ -128,12 +141,15 @@ _ts_decorate([
128
141
  status: 200,
129
142
  type: SingleResponseDto
130
143
  }),
131
- _ts_param(0, Param('userId')),
132
- _ts_param(1, Query()),
144
+ ApiBody({
145
+ type: GetUserRolesDto
146
+ }),
147
+ _ts_param(0, Body()),
148
+ _ts_param(1, CurrentUser()),
133
149
  _ts_metadata("design:type", Function),
134
150
  _ts_metadata("design:paramtypes", [
135
- String,
136
- typeof GetUserRolesDto === "undefined" ? Object : GetUserRolesDto
151
+ typeof GetUserRolesDto === "undefined" ? Object : GetUserRolesDto,
152
+ typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
137
153
  ]),
138
154
  _ts_metadata("design:returntype", Promise)
139
155
  ], RolePermissionController.prototype, "getUserRoles", null);
@@ -143,8 +159,10 @@ RolePermissionController = _ts_decorate([
143
159
  UseGuards(JwtAuthGuard),
144
160
  ApiBearerAuth(),
145
161
  _ts_param(0, Inject(PermissionService)),
162
+ _ts_param(1, Inject(IAMConfigService)),
146
163
  _ts_metadata("design:type", Function),
147
164
  _ts_metadata("design:paramtypes", [
148
- typeof PermissionService === "undefined" ? Object : PermissionService
165
+ typeof PermissionService === "undefined" ? Object : PermissionService,
166
+ typeof IAMConfigService === "undefined" ? Object : IAMConfigService
149
167
  ])
150
168
  ], RolePermissionController);
@@ -25,13 +25,56 @@ function _ts_param(paramIndex, decorator) {
25
25
  decorator(target, key, paramIndex);
26
26
  };
27
27
  }
28
- import { createApiController } from '@flusys/nestjs-shared/classes';
28
+ import { createApiController, ROLE_PERMISSIONS } from '@flusys/nestjs-shared';
29
29
  import { Controller, Inject } from '@nestjs/common';
30
30
  import { ApiTags } from '@nestjs/swagger';
31
31
  import { CreateRoleDto, RoleResponseDto, UpdateRoleDto } from '../dtos/role.dto';
32
32
  import { RoleService } from '../services/role.service';
33
33
  export class RoleController extends createApiController(CreateRoleDto, UpdateRoleDto, RoleResponseDto, {
34
- security: 'jwt'
34
+ security: {
35
+ insert: {
36
+ level: 'permission',
37
+ permissions: [
38
+ ROLE_PERMISSIONS.CREATE
39
+ ]
40
+ },
41
+ insertMany: {
42
+ level: 'permission',
43
+ permissions: [
44
+ ROLE_PERMISSIONS.CREATE
45
+ ]
46
+ },
47
+ getById: {
48
+ level: 'permission',
49
+ permissions: [
50
+ ROLE_PERMISSIONS.READ
51
+ ]
52
+ },
53
+ getAll: {
54
+ level: 'permission',
55
+ permissions: [
56
+ ROLE_PERMISSIONS.READ
57
+ ]
58
+ },
59
+ update: {
60
+ level: 'permission',
61
+ permissions: [
62
+ ROLE_PERMISSIONS.UPDATE
63
+ ]
64
+ },
65
+ updateMany: {
66
+ level: 'permission',
67
+ permissions: [
68
+ ROLE_PERMISSIONS.UPDATE
69
+ ]
70
+ },
71
+ delete: {
72
+ level: 'permission',
73
+ permissions: [
74
+ ROLE_PERMISSIONS.DELETE
75
+ ]
76
+ }
77
+ }
35
78
  }) {
36
79
  constructor(roleService){
37
80
  super(roleService), _define_property(this, "roleService", void 0), this.roleService = roleService;