@flusys/nestjs-iam 7.1.0 → 8.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/config/index.d.ts +3 -3
- package/config/message-keys.d.ts +2 -0
- package/controllers/action.controller.d.ts +4 -4
- package/controllers/company-action-permission.controller.d.ts +2 -2
- package/controllers/index.d.ts +6 -6
- package/controllers/my-permission.controller.d.ts +3 -3
- package/controllers/role-permission.controller.d.ts +5 -4
- package/controllers/role.controller.d.ts +2 -2
- package/controllers/user-action-permission.controller.d.ts +5 -4
- package/docs/iam-swagger.config.d.ts +2 -2
- package/docs/index.d.ts +1 -1
- package/dtos/action.dto.d.ts +2 -2
- package/dtos/index.d.ts +3 -3
- package/dtos/permission.dto.d.ts +16 -0
- package/entities/action.entity.d.ts +2 -2
- package/entities/index.d.ts +11 -11
- package/entities/permission-with-company.entity.d.ts +1 -1
- package/entities/role-with-company.entity.d.ts +1 -1
- package/entities/role.entity.d.ts +1 -1
- package/entities/user-iam-permission.entity.d.ts +1 -1
- package/enums/index.d.ts +4 -4
- package/fesm/284.js +1316 -0
- package/fesm/867.js +3801 -0
- package/fesm/chunks/364.js +86 -0
- package/fesm/config/index.js +135 -3
- package/fesm/controllers/index.js +18 -7
- package/fesm/docs/index.js +240 -1
- package/fesm/dtos/index.js +1168 -3
- package/fesm/entities/index.js +670 -31
- package/fesm/enums/index.js +97 -4
- package/fesm/helpers/index.js +125 -2
- package/fesm/index.js +818 -11
- package/fesm/interfaces/index.js +17 -3
- package/fesm/modules/index.js +259 -1
- package/fesm/runtime.js +134 -0
- package/fesm/services/index.js +43 -6
- package/fesm/types/index.js +15 -1
- package/helpers/company-access.helper.d.ts +2 -2
- package/helpers/index.d.ts +2 -2
- package/helpers/permission-mode.helper.d.ts +1 -1
- package/index.d.ts +11 -11
- package/interfaces/action.interface.d.ts +2 -2
- package/interfaces/iam-module-options.interface.d.ts +3 -3
- package/interfaces/index.d.ts +3 -3
- package/modules/iam.module.d.ts +2 -2
- package/modules/index.d.ts +1 -1
- package/package.json +30 -37
- package/services/action.service.d.ts +9 -9
- package/services/iam-config.service.d.ts +4 -4
- package/services/iam-datasource.service.d.ts +3 -3
- package/services/index.d.ts +6 -6
- package/services/permission-cache.service.d.ts +5 -5
- package/services/permission.service.d.ts +6 -4
- package/services/role.service.d.ts +8 -8
- package/types/index.d.ts +1 -1
- package/cjs/config/event-actions.js +0 -36
- package/cjs/config/iam.constants.js +0 -11
- package/cjs/config/index.js +0 -20
- package/cjs/config/message-keys.js +0 -71
- package/cjs/controllers/action.controller.js +0 -174
- package/cjs/controllers/action.controller.spec.js +0 -79
- package/cjs/controllers/company-action-permission.controller.js +0 -119
- package/cjs/controllers/company-action-permission.controller.spec.js +0 -65
- package/cjs/controllers/index.js +0 -23
- package/cjs/controllers/my-permission.controller.js +0 -147
- package/cjs/controllers/my-permission.controller.spec.js +0 -128
- package/cjs/controllers/role-permission.controller.js +0 -191
- package/cjs/controllers/role-permission.controller.spec.js +0 -140
- package/cjs/controllers/role.controller.js +0 -102
- package/cjs/controllers/role.controller.spec.js +0 -86
- package/cjs/controllers/user-action-permission.controller.js +0 -129
- package/cjs/controllers/user-action-permission.controller.spec.js +0 -68
- package/cjs/docs/iam-swagger.config.js +0 -209
- package/cjs/docs/iam-swagger.config.spec.js +0 -99
- package/cjs/docs/index.js +0 -18
- package/cjs/dtos/action.dto.js +0 -282
- package/cjs/dtos/index.js +0 -21
- package/cjs/dtos/permission.dto.js +0 -637
- package/cjs/dtos/role.dto.js +0 -155
- package/cjs/entities/action.entity.js +0 -138
- package/cjs/entities/index.js +0 -80
- package/cjs/entities/index.spec.js +0 -56
- package/cjs/entities/permission-base.entity.js +0 -107
- package/cjs/entities/permission-with-company.entity.js +0 -100
- package/cjs/entities/role-base.entity.js +0 -80
- package/cjs/entities/role-with-company.entity.js +0 -55
- package/cjs/entities/role.entity.js +0 -25
- package/cjs/entities/user-iam-permission.entity.js +0 -43
- package/cjs/enums/action-type.enum.js +0 -22
- package/cjs/enums/iam-entity-type.enum.js +0 -17
- package/cjs/enums/iam-permission-type.enum.js +0 -17
- package/cjs/enums/index.js +0 -21
- package/cjs/enums/permission-type.enum.js +0 -16
- package/cjs/helpers/company-access.helper.js +0 -23
- package/cjs/helpers/company-access.helper.spec.js +0 -68
- package/cjs/helpers/index.js +0 -19
- package/cjs/helpers/permission-mode.helper.js +0 -49
- package/cjs/helpers/permission-mode.helper.spec.js +0 -54
- package/cjs/index.js +0 -28
- package/cjs/interfaces/action.interface.js +0 -4
- package/cjs/interfaces/iam-module-options.interface.js +0 -4
- package/cjs/interfaces/index.js +0 -20
- package/cjs/interfaces/role.interface.js +0 -7
- package/cjs/modules/iam.module.js +0 -186
- package/cjs/modules/iam.module.spec.js +0 -282
- package/cjs/modules/index.js +0 -18
- package/cjs/services/action.service.js +0 -337
- package/cjs/services/action.service.spec.js +0 -351
- package/cjs/services/iam-config.service.js +0 -87
- package/cjs/services/iam-config.service.spec.js +0 -110
- package/cjs/services/iam-datasource.service.js +0 -129
- package/cjs/services/iam-datasource.service.spec.js +0 -110
- package/cjs/services/index.js +0 -23
- package/cjs/services/permission-cache.service.js +0 -544
- package/cjs/services/permission-cache.service.spec.js +0 -718
- package/cjs/services/permission.service.js +0 -914
- package/cjs/services/permission.service.spec.js +0 -918
- package/cjs/services/role.service.js +0 -224
- package/cjs/services/role.service.spec.js +0 -347
- package/cjs/types/index.js +0 -18
- package/cjs/types/logic-node.type.js +0 -30
- package/fesm/config/event-actions.js +0 -15
- package/fesm/config/iam.constants.js +0 -1
- package/fesm/config/message-keys.js +0 -35
- package/fesm/controllers/action.controller.js +0 -164
- package/fesm/controllers/action.controller.spec.js +0 -75
- package/fesm/controllers/company-action-permission.controller.js +0 -109
- package/fesm/controllers/company-action-permission.controller.spec.js +0 -61
- package/fesm/controllers/my-permission.controller.js +0 -137
- package/fesm/controllers/my-permission.controller.spec.js +0 -124
- package/fesm/controllers/role-permission.controller.js +0 -181
- package/fesm/controllers/role-permission.controller.spec.js +0 -136
- package/fesm/controllers/role.controller.js +0 -92
- package/fesm/controllers/role.controller.spec.js +0 -82
- package/fesm/controllers/user-action-permission.controller.js +0 -119
- package/fesm/controllers/user-action-permission.controller.spec.js +0 -64
- package/fesm/docs/iam-swagger.config.js +0 -199
- package/fesm/docs/iam-swagger.config.spec.js +0 -95
- package/fesm/dtos/action.dto.js +0 -252
- package/fesm/dtos/permission.dto.js +0 -571
- package/fesm/dtos/role.dto.js +0 -134
- package/fesm/entities/action.entity.js +0 -128
- package/fesm/entities/index.spec.js +0 -52
- package/fesm/entities/permission-base.entity.js +0 -100
- package/fesm/entities/permission-with-company.entity.js +0 -90
- package/fesm/entities/role-base.entity.js +0 -70
- package/fesm/entities/role-with-company.entity.js +0 -45
- package/fesm/entities/role.entity.js +0 -15
- package/fesm/entities/user-iam-permission.entity.js +0 -33
- package/fesm/enums/action-type.enum.js +0 -12
- package/fesm/enums/iam-entity-type.enum.js +0 -7
- package/fesm/enums/iam-permission-type.enum.js +0 -7
- package/fesm/enums/permission-type.enum.js +0 -6
- package/fesm/helpers/company-access.helper.js +0 -18
- package/fesm/helpers/company-access.helper.spec.js +0 -64
- package/fesm/helpers/permission-mode.helper.js +0 -49
- package/fesm/helpers/permission-mode.helper.spec.js +0 -50
- package/fesm/interfaces/action.interface.js +0 -3
- package/fesm/interfaces/iam-module-options.interface.js +0 -3
- package/fesm/interfaces/role.interface.js +0 -4
- package/fesm/modules/iam.module.js +0 -176
- package/fesm/modules/iam.module.spec.js +0 -278
- package/fesm/services/action.service.js +0 -327
- package/fesm/services/action.service.spec.js +0 -347
- package/fesm/services/iam-config.service.js +0 -77
- package/fesm/services/iam-config.service.spec.js +0 -106
- package/fesm/services/iam-datasource.service.js +0 -78
- package/fesm/services/iam-datasource.service.spec.js +0 -106
- package/fesm/services/permission-cache.service.js +0 -527
- package/fesm/services/permission-cache.service.spec.js +0 -714
- package/fesm/services/permission.service.js +0 -904
- package/fesm/services/permission.service.spec.js +0 -914
- package/fesm/services/role.service.js +0 -214
- package/fesm/services/role.service.spec.js +0 -343
- package/fesm/types/logic-node.type.js +0 -27
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
15
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
-
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;
|
|
18
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
-
}
|
|
20
|
-
function _ts_metadata(k, v) {
|
|
21
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
-
}
|
|
23
|
-
function _ts_param(paramIndex, decorator) {
|
|
24
|
-
return function(target, key) {
|
|
25
|
-
decorator(target, key, paramIndex);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
import { ACTION_PERMISSIONS, createApiController, CurrentUser, ILoggedUserInfo, SingleResponseDto } from '@flusys/nestjs-shared';
|
|
29
|
-
import { JwtAuthGuard } from '@flusys/nestjs-shared/guards';
|
|
30
|
-
import { Body, Controller, Inject, Post, UseGuards } from '@nestjs/common';
|
|
31
|
-
import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
32
|
-
import { ACTION_MESSAGES } from '../config';
|
|
33
|
-
import { ActionResponseDto, ActionTreeForPermissionDto, ActionTreeQueryDto, CreateActionDto, UpdateActionDto } from '../dtos/action.dto';
|
|
34
|
-
import { ActionService } from '../services/action.service';
|
|
35
|
-
import { IAMConfigService } from '../services/iam-config.service';
|
|
36
|
-
export class ActionController extends createApiController(CreateActionDto, UpdateActionDto, ActionResponseDto, {
|
|
37
|
-
entityName: 'action',
|
|
38
|
-
security: {
|
|
39
|
-
insert: {
|
|
40
|
-
level: 'permission',
|
|
41
|
-
permissions: [
|
|
42
|
-
ACTION_PERMISSIONS.CREATE
|
|
43
|
-
]
|
|
44
|
-
},
|
|
45
|
-
insertMany: {
|
|
46
|
-
level: 'permission',
|
|
47
|
-
permissions: [
|
|
48
|
-
ACTION_PERMISSIONS.CREATE
|
|
49
|
-
]
|
|
50
|
-
},
|
|
51
|
-
getById: {
|
|
52
|
-
level: 'permission',
|
|
53
|
-
permissions: [
|
|
54
|
-
ACTION_PERMISSIONS.READ
|
|
55
|
-
]
|
|
56
|
-
},
|
|
57
|
-
getAll: {
|
|
58
|
-
level: 'permission',
|
|
59
|
-
permissions: [
|
|
60
|
-
ACTION_PERMISSIONS.READ
|
|
61
|
-
]
|
|
62
|
-
},
|
|
63
|
-
update: {
|
|
64
|
-
level: 'permission',
|
|
65
|
-
permissions: [
|
|
66
|
-
ACTION_PERMISSIONS.UPDATE
|
|
67
|
-
]
|
|
68
|
-
},
|
|
69
|
-
updateMany: {
|
|
70
|
-
level: 'permission',
|
|
71
|
-
permissions: [
|
|
72
|
-
ACTION_PERMISSIONS.UPDATE
|
|
73
|
-
]
|
|
74
|
-
},
|
|
75
|
-
delete: {
|
|
76
|
-
level: 'permission',
|
|
77
|
-
permissions: [
|
|
78
|
-
ACTION_PERMISSIONS.DELETE
|
|
79
|
-
]
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}) {
|
|
83
|
-
async getActionsForPermission(dto, user) {
|
|
84
|
-
const actions = await this.actionService.getActionsForPermission(user, dto?.companyId);
|
|
85
|
-
return {
|
|
86
|
-
success: true,
|
|
87
|
-
message: 'Actions retrieved successfully',
|
|
88
|
-
messageKey: ACTION_MESSAGES.GET_ALL_SUCCESS,
|
|
89
|
-
data: actions
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
async getActionTree(query, user) {
|
|
93
|
-
const tree = await this.actionService.getActionTree(user, query.search, query.isActive, query.withDeleted);
|
|
94
|
-
return {
|
|
95
|
-
success: true,
|
|
96
|
-
message: 'Action tree retrieved successfully',
|
|
97
|
-
messageKey: ACTION_MESSAGES.GET_ALL_SUCCESS,
|
|
98
|
-
data: tree
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
constructor(actionService, iamConfigService){
|
|
102
|
-
super(actionService), _define_property(this, "actionService", void 0), _define_property(this, "iamConfigService", void 0), this.actionService = actionService, this.iamConfigService = iamConfigService;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
_ts_decorate([
|
|
106
|
-
Post('tree-for-permission'),
|
|
107
|
-
UseGuards(JwtAuthGuard),
|
|
108
|
-
ApiBearerAuth(),
|
|
109
|
-
ApiOperation({
|
|
110
|
-
summary: 'Get actions for permission assignment',
|
|
111
|
-
description: "Returns actions available for permission assignment, filtered by company whitelist when company feature is enabled. Optional companyId scopes the whitelist to a specific company (must match the caller's own company); defaults to the caller's session company when omitted."
|
|
112
|
-
}),
|
|
113
|
-
ApiResponse({
|
|
114
|
-
status: 200,
|
|
115
|
-
type: SingleResponseDto
|
|
116
|
-
}),
|
|
117
|
-
ApiBody({
|
|
118
|
-
type: ActionTreeForPermissionDto
|
|
119
|
-
}),
|
|
120
|
-
_ts_param(0, Body()),
|
|
121
|
-
_ts_param(1, CurrentUser()),
|
|
122
|
-
_ts_metadata("design:type", Function),
|
|
123
|
-
_ts_metadata("design:paramtypes", [
|
|
124
|
-
typeof ActionTreeForPermissionDto === "undefined" ? Object : ActionTreeForPermissionDto,
|
|
125
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
126
|
-
]),
|
|
127
|
-
_ts_metadata("design:returntype", Promise)
|
|
128
|
-
], ActionController.prototype, "getActionsForPermission", null);
|
|
129
|
-
_ts_decorate([
|
|
130
|
-
Post('tree'),
|
|
131
|
-
UseGuards(JwtAuthGuard),
|
|
132
|
-
ApiBearerAuth(),
|
|
133
|
-
ApiOperation({
|
|
134
|
-
summary: 'Get actions in hierarchical tree structure',
|
|
135
|
-
description: 'Returns all actions organized in a parent-child tree structure. Supports optional search and filtering.'
|
|
136
|
-
}),
|
|
137
|
-
ApiResponse({
|
|
138
|
-
status: 200,
|
|
139
|
-
description: 'Actions tree retrieved successfully',
|
|
140
|
-
type: SingleResponseDto
|
|
141
|
-
}),
|
|
142
|
-
ApiBody({
|
|
143
|
-
type: ActionTreeQueryDto
|
|
144
|
-
}),
|
|
145
|
-
_ts_param(0, Body()),
|
|
146
|
-
_ts_param(1, CurrentUser()),
|
|
147
|
-
_ts_metadata("design:type", Function),
|
|
148
|
-
_ts_metadata("design:paramtypes", [
|
|
149
|
-
typeof ActionTreeQueryDto === "undefined" ? Object : ActionTreeQueryDto,
|
|
150
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
151
|
-
]),
|
|
152
|
-
_ts_metadata("design:returntype", Promise)
|
|
153
|
-
], ActionController.prototype, "getActionTree", null);
|
|
154
|
-
ActionController = _ts_decorate([
|
|
155
|
-
ApiTags('IAM - Actions'),
|
|
156
|
-
Controller('iam/actions'),
|
|
157
|
-
_ts_param(0, Inject(ActionService)),
|
|
158
|
-
_ts_param(1, Inject(IAMConfigService)),
|
|
159
|
-
_ts_metadata("design:type", Function),
|
|
160
|
-
_ts_metadata("design:paramtypes", [
|
|
161
|
-
typeof ActionService === "undefined" ? Object : ActionService,
|
|
162
|
-
typeof IAMConfigService === "undefined" ? Object : IAMConfigService
|
|
163
|
-
])
|
|
164
|
-
], ActionController);
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { buildMockUser } from '@test-utils/mocks/logged-user.mock';
|
|
2
|
-
import { ActionController } from './action.controller';
|
|
3
|
-
describe('ActionController', ()=>{
|
|
4
|
-
let controller;
|
|
5
|
-
let mockActionService;
|
|
6
|
-
let mockIamConfigService;
|
|
7
|
-
beforeEach(()=>{
|
|
8
|
-
mockActionService = {
|
|
9
|
-
insert: jest.fn(),
|
|
10
|
-
findById: jest.fn(),
|
|
11
|
-
getAll: jest.fn(),
|
|
12
|
-
update: jest.fn(),
|
|
13
|
-
delete: jest.fn(),
|
|
14
|
-
getActionsForPermission: jest.fn(),
|
|
15
|
-
getActionTree: jest.fn()
|
|
16
|
-
};
|
|
17
|
-
mockIamConfigService = {};
|
|
18
|
-
controller = new ActionController(mockActionService, mockIamConfigService);
|
|
19
|
-
});
|
|
20
|
-
it('wires the injected service onto the generated controller base', ()=>{
|
|
21
|
-
expect(controller.actionService).toBe(mockActionService);
|
|
22
|
-
expect(controller.service).toBe(mockActionService);
|
|
23
|
-
});
|
|
24
|
-
describe('getActionsForPermission', ()=>{
|
|
25
|
-
it('returns actions scoped to the caller session company when no companyId is given', async ()=>{
|
|
26
|
-
const user = buildMockUser();
|
|
27
|
-
mockActionService.getActionsForPermission.mockResolvedValue([
|
|
28
|
-
{
|
|
29
|
-
id: 'action-1',
|
|
30
|
-
code: 'user.create'
|
|
31
|
-
}
|
|
32
|
-
]);
|
|
33
|
-
const result = await controller.getActionsForPermission({}, user);
|
|
34
|
-
expect(mockActionService.getActionsForPermission).toHaveBeenCalledWith(user, undefined);
|
|
35
|
-
expect(result.success).toBe(true);
|
|
36
|
-
expect(result.data).toEqual([
|
|
37
|
-
{
|
|
38
|
-
id: 'action-1',
|
|
39
|
-
code: 'user.create'
|
|
40
|
-
}
|
|
41
|
-
]);
|
|
42
|
-
});
|
|
43
|
-
it('forwards an explicit companyId override', async ()=>{
|
|
44
|
-
const user = buildMockUser();
|
|
45
|
-
mockActionService.getActionsForPermission.mockResolvedValue([]);
|
|
46
|
-
await controller.getActionsForPermission({
|
|
47
|
-
companyId: 'company-2'
|
|
48
|
-
}, user);
|
|
49
|
-
expect(mockActionService.getActionsForPermission).toHaveBeenCalledWith(user, 'company-2');
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
describe('getActionTree', ()=>{
|
|
53
|
-
it('returns the hierarchical action tree with query filters applied', async ()=>{
|
|
54
|
-
const user = buildMockUser();
|
|
55
|
-
mockActionService.getActionTree.mockResolvedValue([
|
|
56
|
-
{
|
|
57
|
-
id: 'action-1',
|
|
58
|
-
children: []
|
|
59
|
-
}
|
|
60
|
-
]);
|
|
61
|
-
const result = await controller.getActionTree({
|
|
62
|
-
search: 'user',
|
|
63
|
-
isActive: true,
|
|
64
|
-
withDeleted: false
|
|
65
|
-
}, user);
|
|
66
|
-
expect(mockActionService.getActionTree).toHaveBeenCalledWith(user, 'user', true, false);
|
|
67
|
-
expect(result.data).toEqual([
|
|
68
|
-
{
|
|
69
|
-
id: 'action-1',
|
|
70
|
-
children: []
|
|
71
|
-
}
|
|
72
|
-
]);
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
15
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
-
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;
|
|
18
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
-
}
|
|
20
|
-
function _ts_metadata(k, v) {
|
|
21
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
-
}
|
|
23
|
-
function _ts_param(paramIndex, decorator) {
|
|
24
|
-
return function(target, key) {
|
|
25
|
-
decorator(target, key, paramIndex);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
import { ApiResponseDto, COMPANY_ACTION_PERMISSIONS, JwtAuthGuard, PermissionGuard, RequirePermission } from '@flusys/nestjs-shared';
|
|
29
|
-
import { Body, Controller, Inject, Post, UseGuards } from '@nestjs/common';
|
|
30
|
-
import { ApiBearerAuth, ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
31
|
-
import { COMPANY_ACTION_PERMISSION_MESSAGES, PERMISSION_OPERATION_MESSAGES } from '../config';
|
|
32
|
-
import { AssignCompanyActionsDto, CompanyActionResponseDto, GetCompanyActionsDto, PermissionOperationResultDto } from '../dtos/permission.dto';
|
|
33
|
-
import { PermissionService } from '../services/permission.service';
|
|
34
|
-
export class CompanyActionPermissionController {
|
|
35
|
-
async assignCompanyActions(dto) {
|
|
36
|
-
const result = await this.permissionService.assignCompanyActions(dto);
|
|
37
|
-
return {
|
|
38
|
-
success: true,
|
|
39
|
-
message: 'Company actions updated successfully',
|
|
40
|
-
messageKey: PERMISSION_OPERATION_MESSAGES.PROCESS_SUCCESS,
|
|
41
|
-
messageVariables: {
|
|
42
|
-
added: result.added,
|
|
43
|
-
removed: result.removed,
|
|
44
|
-
total: result.total
|
|
45
|
-
},
|
|
46
|
-
data: result
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
async getCompanyActions(dto) {
|
|
50
|
-
const actions = await this.permissionService.getCompanyActions(dto.companyId, false);
|
|
51
|
-
return {
|
|
52
|
-
success: true,
|
|
53
|
-
message: 'Company actions retrieved successfully',
|
|
54
|
-
messageKey: COMPANY_ACTION_PERMISSION_MESSAGES.GET_SUCCESS,
|
|
55
|
-
data: actions
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
constructor(permissionService){
|
|
59
|
-
_define_property(this, "permissionService", void 0);
|
|
60
|
-
this.permissionService = permissionService;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
_ts_decorate([
|
|
64
|
-
Post('company-actions/assign'),
|
|
65
|
-
RequirePermission(COMPANY_ACTION_PERMISSIONS.ASSIGN),
|
|
66
|
-
ApiOperation({
|
|
67
|
-
summary: 'Whitelist actions for company',
|
|
68
|
-
description: 'Controls which actions are available to company users/roles.'
|
|
69
|
-
}),
|
|
70
|
-
ApiResponseDto(PermissionOperationResultDto),
|
|
71
|
-
ApiBody({
|
|
72
|
-
type: AssignCompanyActionsDto
|
|
73
|
-
}),
|
|
74
|
-
_ts_param(0, Body()),
|
|
75
|
-
_ts_metadata("design:type", Function),
|
|
76
|
-
_ts_metadata("design:paramtypes", [
|
|
77
|
-
typeof AssignCompanyActionsDto === "undefined" ? Object : AssignCompanyActionsDto
|
|
78
|
-
]),
|
|
79
|
-
_ts_metadata("design:returntype", Promise)
|
|
80
|
-
], CompanyActionPermissionController.prototype, "assignCompanyActions", null);
|
|
81
|
-
_ts_decorate([
|
|
82
|
-
Post('get-company-actions'),
|
|
83
|
-
RequirePermission(COMPANY_ACTION_PERMISSIONS.READ),
|
|
84
|
-
ApiOperation({
|
|
85
|
-
summary: 'Get company whitelisted actions',
|
|
86
|
-
description: 'Returns actions available to company.'
|
|
87
|
-
}),
|
|
88
|
-
ApiResponseDto(CompanyActionResponseDto, true, 'single'),
|
|
89
|
-
ApiBody({
|
|
90
|
-
type: GetCompanyActionsDto
|
|
91
|
-
}),
|
|
92
|
-
_ts_param(0, Body()),
|
|
93
|
-
_ts_metadata("design:type", Function),
|
|
94
|
-
_ts_metadata("design:paramtypes", [
|
|
95
|
-
typeof GetCompanyActionsDto === "undefined" ? Object : GetCompanyActionsDto
|
|
96
|
-
]),
|
|
97
|
-
_ts_metadata("design:returntype", Promise)
|
|
98
|
-
], CompanyActionPermissionController.prototype, "getCompanyActions", null);
|
|
99
|
-
CompanyActionPermissionController = _ts_decorate([
|
|
100
|
-
ApiTags('IAM - Company Action Permissions'),
|
|
101
|
-
Controller('iam/permissions'),
|
|
102
|
-
UseGuards(JwtAuthGuard, PermissionGuard),
|
|
103
|
-
ApiBearerAuth(),
|
|
104
|
-
_ts_param(0, Inject(PermissionService)),
|
|
105
|
-
_ts_metadata("design:type", Function),
|
|
106
|
-
_ts_metadata("design:paramtypes", [
|
|
107
|
-
typeof PermissionService === "undefined" ? Object : PermissionService
|
|
108
|
-
])
|
|
109
|
-
], CompanyActionPermissionController);
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { CompanyActionPermissionController } from './company-action-permission.controller';
|
|
2
|
-
describe('CompanyActionPermissionController', ()=>{
|
|
3
|
-
let controller;
|
|
4
|
-
let mockPermissionService;
|
|
5
|
-
beforeEach(()=>{
|
|
6
|
-
mockPermissionService = {
|
|
7
|
-
assignCompanyActions: jest.fn(),
|
|
8
|
-
getCompanyActions: jest.fn()
|
|
9
|
-
};
|
|
10
|
-
controller = new CompanyActionPermissionController(mockPermissionService);
|
|
11
|
-
});
|
|
12
|
-
describe('assignCompanyActions', ()=>{
|
|
13
|
-
it('whitelists actions for a company', async ()=>{
|
|
14
|
-
mockPermissionService.assignCompanyActions.mockResolvedValue({
|
|
15
|
-
added: 3,
|
|
16
|
-
removed: 0,
|
|
17
|
-
total: 3
|
|
18
|
-
});
|
|
19
|
-
const result = await controller.assignCompanyActions({
|
|
20
|
-
companyId: 'company-1',
|
|
21
|
-
actionIds: [
|
|
22
|
-
'action-1',
|
|
23
|
-
'action-2',
|
|
24
|
-
'action-3'
|
|
25
|
-
]
|
|
26
|
-
});
|
|
27
|
-
expect(mockPermissionService.assignCompanyActions).toHaveBeenCalledWith({
|
|
28
|
-
companyId: 'company-1',
|
|
29
|
-
actionIds: [
|
|
30
|
-
'action-1',
|
|
31
|
-
'action-2',
|
|
32
|
-
'action-3'
|
|
33
|
-
]
|
|
34
|
-
});
|
|
35
|
-
expect(result.success).toBe(true);
|
|
36
|
-
expect(result.data).toEqual({
|
|
37
|
-
added: 3,
|
|
38
|
-
removed: 0,
|
|
39
|
-
total: 3
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
describe('getCompanyActions', ()=>{
|
|
44
|
-
it('returns the whitelisted actions for a company', async ()=>{
|
|
45
|
-
mockPermissionService.getCompanyActions.mockResolvedValue([
|
|
46
|
-
{
|
|
47
|
-
actionId: 'action-1'
|
|
48
|
-
}
|
|
49
|
-
]);
|
|
50
|
-
const result = await controller.getCompanyActions({
|
|
51
|
-
companyId: 'company-1'
|
|
52
|
-
});
|
|
53
|
-
expect(mockPermissionService.getCompanyActions).toHaveBeenCalledWith('company-1', false);
|
|
54
|
-
expect(result.data).toEqual([
|
|
55
|
-
{
|
|
56
|
-
actionId: 'action-1'
|
|
57
|
-
}
|
|
58
|
-
]);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
});
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
function _define_property(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
15
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
-
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;
|
|
18
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
-
}
|
|
20
|
-
function _ts_metadata(k, v) {
|
|
21
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
22
|
-
}
|
|
23
|
-
function _ts_param(paramIndex, decorator) {
|
|
24
|
-
return function(target, key) {
|
|
25
|
-
decorator(target, key, paramIndex);
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
import { ApiResponseDto, CurrentUser, ILoggedUserInfo, JwtAuthGuard } from '@flusys/nestjs-shared';
|
|
29
|
-
import { MY_PERMISSION_MESSAGES } from '../config';
|
|
30
|
-
import { Body, Controller, Inject, Post, UseGuards } from '@nestjs/common';
|
|
31
|
-
import { ApiBearerAuth, ApiBody, ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
|
32
|
-
import { MyPermissionsQueryDto, MyPermissionsResponseDto, UserActionResponseDto, UserRoleResponseDto } from '../dtos/permission.dto';
|
|
33
|
-
import { PermissionService } from '../services/permission.service';
|
|
34
|
-
export class MyPermissionController {
|
|
35
|
-
async getMyPermissions(query, user) {
|
|
36
|
-
const data = await this.permissionService.getMyPermissions(user.id, user.branchId ?? null, user.companyId ?? null, query.parentCodes);
|
|
37
|
-
return {
|
|
38
|
-
success: true,
|
|
39
|
-
message: 'Permissions loaded successfully',
|
|
40
|
-
messageKey: MY_PERMISSION_MESSAGES.GET_SUCCESS,
|
|
41
|
-
data
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
async getMyRoles(user) {
|
|
45
|
-
const data = await this.permissionService.getUserEffectiveRoles(user.id, user.companyId ?? null, user.branchId ?? null);
|
|
46
|
-
return {
|
|
47
|
-
success: true,
|
|
48
|
-
message: 'Roles loaded successfully',
|
|
49
|
-
messageKey: MY_PERMISSION_MESSAGES.MY_ROLES_SUCCESS,
|
|
50
|
-
data
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
async getMyActions(user) {
|
|
54
|
-
const data = await this.permissionService.getUserEffectiveActions(user.id, user.companyId ?? null, user.branchId ?? null);
|
|
55
|
-
return {
|
|
56
|
-
success: true,
|
|
57
|
-
message: 'Actions loaded successfully',
|
|
58
|
-
messageKey: MY_PERMISSION_MESSAGES.MY_ACTIONS_SUCCESS,
|
|
59
|
-
data
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
// NOTE: @Inject() required for bundled code - type metadata may be lost during esbuild
|
|
63
|
-
constructor(permissionService){
|
|
64
|
-
_define_property(this, "permissionService", void 0);
|
|
65
|
-
this.permissionService = permissionService;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
_ts_decorate([
|
|
69
|
-
Post('my-permissions'),
|
|
70
|
-
ApiOperation({
|
|
71
|
-
summary: 'Get current user permissions',
|
|
72
|
-
description: 'Returns complete permissions for authenticated user. Includes menus, frontend actions, and caches endpoint permissions. Optionally filter by parent codes.'
|
|
73
|
-
}),
|
|
74
|
-
ApiResponseDto(MyPermissionsResponseDto),
|
|
75
|
-
ApiResponse({
|
|
76
|
-
status: 401,
|
|
77
|
-
description: 'Unauthorized'
|
|
78
|
-
}),
|
|
79
|
-
ApiBody({
|
|
80
|
-
type: MyPermissionsQueryDto
|
|
81
|
-
}),
|
|
82
|
-
_ts_param(0, Body()),
|
|
83
|
-
_ts_param(1, CurrentUser()),
|
|
84
|
-
_ts_metadata("design:type", Function),
|
|
85
|
-
_ts_metadata("design:paramtypes", [
|
|
86
|
-
typeof MyPermissionsQueryDto === "undefined" ? Object : MyPermissionsQueryDto,
|
|
87
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
88
|
-
]),
|
|
89
|
-
_ts_metadata("design:returntype", Promise)
|
|
90
|
-
], MyPermissionController.prototype, "getMyPermissions", null);
|
|
91
|
-
_ts_decorate([
|
|
92
|
-
Post('my-roles'),
|
|
93
|
-
ApiOperation({
|
|
94
|
-
summary: 'Get current user roles',
|
|
95
|
-
description: 'Returns effective roles for the authenticated user, merging company-wide (branch-independent) and login-branch-specific role assignments.'
|
|
96
|
-
}),
|
|
97
|
-
ApiResponseDto(UserRoleResponseDto, true, 'single'),
|
|
98
|
-
ApiResponse({
|
|
99
|
-
status: 401,
|
|
100
|
-
description: 'Unauthorized'
|
|
101
|
-
}),
|
|
102
|
-
_ts_param(0, CurrentUser()),
|
|
103
|
-
_ts_metadata("design:type", Function),
|
|
104
|
-
_ts_metadata("design:paramtypes", [
|
|
105
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
106
|
-
]),
|
|
107
|
-
_ts_metadata("design:returntype", Promise)
|
|
108
|
-
], MyPermissionController.prototype, "getMyRoles", null);
|
|
109
|
-
_ts_decorate([
|
|
110
|
-
Post('my-actions'),
|
|
111
|
-
ApiOperation({
|
|
112
|
-
summary: 'Get current user direct actions',
|
|
113
|
-
description: 'Returns effective direct action assignments for the authenticated user, merging company-wide (branch-independent) and login-branch-specific assignments.'
|
|
114
|
-
}),
|
|
115
|
-
ApiResponseDto(UserActionResponseDto, true, 'single'),
|
|
116
|
-
ApiResponse({
|
|
117
|
-
status: 401,
|
|
118
|
-
description: 'Unauthorized'
|
|
119
|
-
}),
|
|
120
|
-
_ts_param(0, CurrentUser()),
|
|
121
|
-
_ts_metadata("design:type", Function),
|
|
122
|
-
_ts_metadata("design:paramtypes", [
|
|
123
|
-
typeof ILoggedUserInfo === "undefined" ? Object : ILoggedUserInfo
|
|
124
|
-
]),
|
|
125
|
-
_ts_metadata("design:returntype", Promise)
|
|
126
|
-
], MyPermissionController.prototype, "getMyActions", null);
|
|
127
|
-
MyPermissionController = _ts_decorate([
|
|
128
|
-
ApiTags('IAM - My Permissions'),
|
|
129
|
-
Controller('iam/permissions'),
|
|
130
|
-
UseGuards(JwtAuthGuard),
|
|
131
|
-
ApiBearerAuth(),
|
|
132
|
-
_ts_param(0, Inject(PermissionService)),
|
|
133
|
-
_ts_metadata("design:type", Function),
|
|
134
|
-
_ts_metadata("design:paramtypes", [
|
|
135
|
-
typeof PermissionService === "undefined" ? Object : PermissionService
|
|
136
|
-
])
|
|
137
|
-
], MyPermissionController);
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { buildMockUser } from '@test-utils/mocks/logged-user.mock';
|
|
2
|
-
import { MyPermissionController } from './my-permission.controller';
|
|
3
|
-
describe('MyPermissionController', ()=>{
|
|
4
|
-
let controller;
|
|
5
|
-
let mockPermissionService;
|
|
6
|
-
beforeEach(()=>{
|
|
7
|
-
mockPermissionService = {
|
|
8
|
-
getMyPermissions: jest.fn(),
|
|
9
|
-
getUserEffectiveRoles: jest.fn(),
|
|
10
|
-
getUserEffectiveActions: jest.fn()
|
|
11
|
-
};
|
|
12
|
-
controller = new MyPermissionController(mockPermissionService);
|
|
13
|
-
});
|
|
14
|
-
describe('getMyPermissions', ()=>{
|
|
15
|
-
it('resolves permissions for the current user, branch, and company', async ()=>{
|
|
16
|
-
const user = buildMockUser({
|
|
17
|
-
id: 'user-1',
|
|
18
|
-
companyId: 'company-1',
|
|
19
|
-
branchId: 'branch-1'
|
|
20
|
-
});
|
|
21
|
-
const permissions = {
|
|
22
|
-
menus: [],
|
|
23
|
-
actions: [
|
|
24
|
-
'user.create'
|
|
25
|
-
]
|
|
26
|
-
};
|
|
27
|
-
mockPermissionService.getMyPermissions.mockResolvedValue(permissions);
|
|
28
|
-
const result = await controller.getMyPermissions({
|
|
29
|
-
parentCodes: [
|
|
30
|
-
'user'
|
|
31
|
-
]
|
|
32
|
-
}, user);
|
|
33
|
-
expect(mockPermissionService.getMyPermissions).toHaveBeenCalledWith('user-1', 'branch-1', 'company-1', [
|
|
34
|
-
'user'
|
|
35
|
-
]);
|
|
36
|
-
expect(result).toEqual({
|
|
37
|
-
success: true,
|
|
38
|
-
message: 'Permissions loaded successfully',
|
|
39
|
-
messageKey: expect.any(String),
|
|
40
|
-
data: permissions
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
it('passes null for missing branch and company context', async ()=>{
|
|
44
|
-
const user = buildMockUser({
|
|
45
|
-
id: 'user-1',
|
|
46
|
-
companyId: undefined,
|
|
47
|
-
branchId: undefined
|
|
48
|
-
});
|
|
49
|
-
mockPermissionService.getMyPermissions.mockResolvedValue({});
|
|
50
|
-
await controller.getMyPermissions({}, user);
|
|
51
|
-
expect(mockPermissionService.getMyPermissions).toHaveBeenCalledWith('user-1', null, null, undefined);
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
describe('getMyRoles', ()=>{
|
|
55
|
-
it('resolves effective roles for the current user, company, and branch', async ()=>{
|
|
56
|
-
const user = buildMockUser({
|
|
57
|
-
id: 'user-1',
|
|
58
|
-
companyId: 'company-1',
|
|
59
|
-
branchId: 'branch-1'
|
|
60
|
-
});
|
|
61
|
-
const roles = [
|
|
62
|
-
{
|
|
63
|
-
id: 'perm-1',
|
|
64
|
-
roleId: 'role-1',
|
|
65
|
-
roleName: 'Manager'
|
|
66
|
-
}
|
|
67
|
-
];
|
|
68
|
-
mockPermissionService.getUserEffectiveRoles.mockResolvedValue(roles);
|
|
69
|
-
const result = await controller.getMyRoles(user);
|
|
70
|
-
expect(mockPermissionService.getUserEffectiveRoles).toHaveBeenCalledWith('user-1', 'company-1', 'branch-1');
|
|
71
|
-
expect(result).toEqual({
|
|
72
|
-
success: true,
|
|
73
|
-
message: 'Roles loaded successfully',
|
|
74
|
-
messageKey: expect.any(String),
|
|
75
|
-
data: roles
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
it('passes null for missing company and branch context', async ()=>{
|
|
79
|
-
const user = buildMockUser({
|
|
80
|
-
id: 'user-1',
|
|
81
|
-
companyId: undefined,
|
|
82
|
-
branchId: undefined
|
|
83
|
-
});
|
|
84
|
-
mockPermissionService.getUserEffectiveRoles.mockResolvedValue([]);
|
|
85
|
-
await controller.getMyRoles(user);
|
|
86
|
-
expect(mockPermissionService.getUserEffectiveRoles).toHaveBeenCalledWith('user-1', null, null);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
describe('getMyActions', ()=>{
|
|
90
|
-
it('resolves effective actions for the current user, company, and branch', async ()=>{
|
|
91
|
-
const user = buildMockUser({
|
|
92
|
-
id: 'user-1',
|
|
93
|
-
companyId: 'company-1',
|
|
94
|
-
branchId: 'branch-1'
|
|
95
|
-
});
|
|
96
|
-
const actions = [
|
|
97
|
-
{
|
|
98
|
-
id: 'perm-1',
|
|
99
|
-
actionId: 'action-1',
|
|
100
|
-
actionCode: 'user.view'
|
|
101
|
-
}
|
|
102
|
-
];
|
|
103
|
-
mockPermissionService.getUserEffectiveActions.mockResolvedValue(actions);
|
|
104
|
-
const result = await controller.getMyActions(user);
|
|
105
|
-
expect(mockPermissionService.getUserEffectiveActions).toHaveBeenCalledWith('user-1', 'company-1', 'branch-1');
|
|
106
|
-
expect(result).toEqual({
|
|
107
|
-
success: true,
|
|
108
|
-
message: 'Actions loaded successfully',
|
|
109
|
-
messageKey: expect.any(String),
|
|
110
|
-
data: actions
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
it('passes null for missing company and branch context', async ()=>{
|
|
114
|
-
const user = buildMockUser({
|
|
115
|
-
id: 'user-1',
|
|
116
|
-
companyId: undefined,
|
|
117
|
-
branchId: undefined
|
|
118
|
-
});
|
|
119
|
-
mockPermissionService.getUserEffectiveActions.mockResolvedValue([]);
|
|
120
|
-
await controller.getMyActions(user);
|
|
121
|
-
expect(mockPermissionService.getUserEffectiveActions).toHaveBeenCalledWith('user-1', null, null);
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
});
|