@flusys/nestjs-iam 7.1.0 → 8.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/index.d.ts +3 -3
- 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 +4 -4
- package/controllers/role.controller.d.ts +2 -2
- package/controllers/user-action-permission.controller.d.ts +4 -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/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 +1262 -0
- package/fesm/867.js +3699 -0
- package/fesm/chunks/364.js +86 -0
- package/fesm/config/index.js +133 -3
- package/fesm/controllers/index.js +18 -7
- package/fesm/docs/index.js +240 -1
- package/fesm/dtos/index.js +1090 -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 +806 -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 +4 -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,128 +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
|
-
import { Identity, getJsonColumnType } from '@flusys/nestjs-shared';
|
|
24
|
-
import { Column, Entity, Index, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
|
|
25
|
-
import { ActionType } from '../enums';
|
|
26
|
-
export class Action extends Identity {
|
|
27
|
-
constructor(...args){
|
|
28
|
-
super(...args), _define_property(this, "readOnly", void 0), _define_property(this, "name", void 0), _define_property(this, "description", void 0), _define_property(this, "code", void 0), _define_property(this, "actionType", void 0), _define_property(this, "permissionLogic", void 0), _define_property(this, "serial", void 0), _define_property(this, "isActive", void 0), _define_property(this, "parent", void 0), _define_property(this, "parentId", void 0), _define_property(this, "children", void 0);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
_ts_decorate([
|
|
32
|
-
Column({
|
|
33
|
-
type: 'boolean',
|
|
34
|
-
nullable: false,
|
|
35
|
-
default: false,
|
|
36
|
-
name: 'read_only'
|
|
37
|
-
}),
|
|
38
|
-
_ts_metadata("design:type", Boolean)
|
|
39
|
-
], Action.prototype, "readOnly", void 0);
|
|
40
|
-
_ts_decorate([
|
|
41
|
-
Column({
|
|
42
|
-
type: 'varchar',
|
|
43
|
-
length: 255,
|
|
44
|
-
nullable: false
|
|
45
|
-
}),
|
|
46
|
-
_ts_metadata("design:type", String)
|
|
47
|
-
], Action.prototype, "name", void 0);
|
|
48
|
-
_ts_decorate([
|
|
49
|
-
Column({
|
|
50
|
-
type: 'varchar',
|
|
51
|
-
length: 500,
|
|
52
|
-
nullable: true
|
|
53
|
-
}),
|
|
54
|
-
_ts_metadata("design:type", Object)
|
|
55
|
-
], Action.prototype, "description", void 0);
|
|
56
|
-
_ts_decorate([
|
|
57
|
-
Column({
|
|
58
|
-
type: 'varchar',
|
|
59
|
-
length: 255,
|
|
60
|
-
nullable: true,
|
|
61
|
-
unique: true
|
|
62
|
-
}),
|
|
63
|
-
_ts_metadata("design:type", Object)
|
|
64
|
-
], Action.prototype, "code", void 0);
|
|
65
|
-
_ts_decorate([
|
|
66
|
-
Column({
|
|
67
|
-
type: 'varchar',
|
|
68
|
-
length: 50,
|
|
69
|
-
nullable: false,
|
|
70
|
-
default: 'BACKEND',
|
|
71
|
-
name: 'action_type'
|
|
72
|
-
}),
|
|
73
|
-
_ts_metadata("design:type", typeof ActionType === "undefined" ? Object : ActionType)
|
|
74
|
-
], Action.prototype, "actionType", void 0);
|
|
75
|
-
_ts_decorate([
|
|
76
|
-
Column({
|
|
77
|
-
type: getJsonColumnType(),
|
|
78
|
-
nullable: true,
|
|
79
|
-
name: 'permission_logic'
|
|
80
|
-
}),
|
|
81
|
-
_ts_metadata("design:type", Object)
|
|
82
|
-
], Action.prototype, "permissionLogic", void 0);
|
|
83
|
-
_ts_decorate([
|
|
84
|
-
Column({
|
|
85
|
-
type: 'int',
|
|
86
|
-
nullable: true
|
|
87
|
-
}),
|
|
88
|
-
_ts_metadata("design:type", Object)
|
|
89
|
-
], Action.prototype, "serial", void 0);
|
|
90
|
-
_ts_decorate([
|
|
91
|
-
Column({
|
|
92
|
-
type: 'boolean',
|
|
93
|
-
nullable: false,
|
|
94
|
-
default: true,
|
|
95
|
-
name: 'is_active'
|
|
96
|
-
}),
|
|
97
|
-
_ts_metadata("design:type", Boolean)
|
|
98
|
-
], Action.prototype, "isActive", void 0);
|
|
99
|
-
_ts_decorate([
|
|
100
|
-
ManyToOne('Action', 'children', {
|
|
101
|
-
nullable: true,
|
|
102
|
-
onDelete: 'CASCADE'
|
|
103
|
-
}),
|
|
104
|
-
JoinColumn({
|
|
105
|
-
name: 'parent_id'
|
|
106
|
-
}),
|
|
107
|
-
_ts_metadata("design:type", Object)
|
|
108
|
-
], Action.prototype, "parent", void 0);
|
|
109
|
-
_ts_decorate([
|
|
110
|
-
Column({
|
|
111
|
-
type: 'uuid',
|
|
112
|
-
nullable: true,
|
|
113
|
-
name: 'parent_id'
|
|
114
|
-
}),
|
|
115
|
-
_ts_metadata("design:type", Object)
|
|
116
|
-
], Action.prototype, "parentId", void 0);
|
|
117
|
-
_ts_decorate([
|
|
118
|
-
OneToMany('Action', 'parent'),
|
|
119
|
-
_ts_metadata("design:type", Array)
|
|
120
|
-
], Action.prototype, "children", void 0);
|
|
121
|
-
Action = _ts_decorate([
|
|
122
|
-
Entity({
|
|
123
|
-
name: 'action'
|
|
124
|
-
}),
|
|
125
|
-
Index([
|
|
126
|
-
'parentId'
|
|
127
|
-
])
|
|
128
|
-
], Action);
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { getIAMEntitiesByConfig } from './index';
|
|
2
|
-
import { Action } from './action.entity';
|
|
3
|
-
import { Role } from './role.entity';
|
|
4
|
-
import { RoleWithCompany } from './role-with-company.entity';
|
|
5
|
-
import { UserIamPermission } from './user-iam-permission.entity';
|
|
6
|
-
import { UserIamPermissionWithCompany } from './permission-with-company.entity';
|
|
7
|
-
describe('getIAMEntitiesByConfig', ()=>{
|
|
8
|
-
it('should always include Action', ()=>{
|
|
9
|
-
expect(getIAMEntitiesByConfig(false)).toContain(Action);
|
|
10
|
-
expect(getIAMEntitiesByConfig(true)).toContain(Action);
|
|
11
|
-
});
|
|
12
|
-
it('should default permissionMode to FULL and include Role + UserIamPermission when company feature is off', ()=>{
|
|
13
|
-
const entities = getIAMEntitiesByConfig(false);
|
|
14
|
-
expect(entities).toEqual(expect.arrayContaining([
|
|
15
|
-
Action,
|
|
16
|
-
UserIamPermission,
|
|
17
|
-
Role
|
|
18
|
-
]));
|
|
19
|
-
expect(entities).not.toContain(RoleWithCompany);
|
|
20
|
-
expect(entities).not.toContain(UserIamPermissionWithCompany);
|
|
21
|
-
});
|
|
22
|
-
it('should use the company-scoped permission entity when enableCompanyFeature is true', ()=>{
|
|
23
|
-
const entities = getIAMEntitiesByConfig(true, 'FULL');
|
|
24
|
-
expect(entities).toContain(UserIamPermissionWithCompany);
|
|
25
|
-
expect(entities).not.toContain(UserIamPermission);
|
|
26
|
-
});
|
|
27
|
-
it('should use the company-scoped role entity when enableCompanyFeature is true', ()=>{
|
|
28
|
-
const entities = getIAMEntitiesByConfig(true, 'RBAC');
|
|
29
|
-
expect(entities).toContain(RoleWithCompany);
|
|
30
|
-
expect(entities).not.toContain(Role);
|
|
31
|
-
});
|
|
32
|
-
it('should include Role for RBAC mode', ()=>{
|
|
33
|
-
expect(getIAMEntitiesByConfig(false, 'RBAC')).toContain(Role);
|
|
34
|
-
});
|
|
35
|
-
it('should include Role for FULL mode', ()=>{
|
|
36
|
-
expect(getIAMEntitiesByConfig(false, 'FULL')).toContain(Role);
|
|
37
|
-
});
|
|
38
|
-
it('should exclude Role entirely for DIRECT mode', ()=>{
|
|
39
|
-
const entities = getIAMEntitiesByConfig(false, 'DIRECT');
|
|
40
|
-
expect(entities).not.toContain(Role);
|
|
41
|
-
expect(entities).not.toContain(RoleWithCompany);
|
|
42
|
-
expect(entities).toEqual(expect.arrayContaining([
|
|
43
|
-
Action,
|
|
44
|
-
UserIamPermission
|
|
45
|
-
]));
|
|
46
|
-
});
|
|
47
|
-
it('should exclude the company-scoped Role for DIRECT mode even with company feature enabled', ()=>{
|
|
48
|
-
const entities = getIAMEntitiesByConfig(true, 'DIRECT');
|
|
49
|
-
expect(entities).not.toContain(RoleWithCompany);
|
|
50
|
-
expect(entities).toContain(UserIamPermissionWithCompany);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
@@ -1,100 +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
|
-
import { Identity } from '@flusys/nestjs-shared';
|
|
24
|
-
import { Column } from 'typeorm';
|
|
25
|
-
/**
|
|
26
|
-
* Permission Base Entity
|
|
27
|
-
* Core permission fields - always included regardless of company feature
|
|
28
|
-
*/ export class PermissionBase extends Identity {
|
|
29
|
-
isValid(now = new Date()) {
|
|
30
|
-
if (this.validFrom && now < this.validFrom) return false;
|
|
31
|
-
if (this.validUntil && now > this.validUntil) return false;
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
constructor(...args){
|
|
35
|
-
super(...args), _define_property(this, "permissionType", void 0), _define_property(this, "sourceType", void 0), _define_property(this, "sourceId", void 0), _define_property(this, "targetType", void 0), _define_property(this, "targetId", void 0), _define_property(this, "validFrom", void 0), _define_property(this, "validUntil", void 0), _define_property(this, "reason", void 0);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
_ts_decorate([
|
|
39
|
-
Column({
|
|
40
|
-
type: 'varchar',
|
|
41
|
-
length: 50,
|
|
42
|
-
name: 'permission_type'
|
|
43
|
-
}),
|
|
44
|
-
_ts_metadata("design:type", String)
|
|
45
|
-
], PermissionBase.prototype, "permissionType", void 0);
|
|
46
|
-
_ts_decorate([
|
|
47
|
-
Column({
|
|
48
|
-
type: 'varchar',
|
|
49
|
-
length: 50,
|
|
50
|
-
name: 'source_type'
|
|
51
|
-
}),
|
|
52
|
-
_ts_metadata("design:type", String)
|
|
53
|
-
], PermissionBase.prototype, "sourceType", void 0);
|
|
54
|
-
_ts_decorate([
|
|
55
|
-
Column({
|
|
56
|
-
type: 'varchar',
|
|
57
|
-
length: 150,
|
|
58
|
-
name: 'source_id'
|
|
59
|
-
}),
|
|
60
|
-
_ts_metadata("design:type", String)
|
|
61
|
-
], PermissionBase.prototype, "sourceId", void 0);
|
|
62
|
-
_ts_decorate([
|
|
63
|
-
Column({
|
|
64
|
-
type: 'varchar',
|
|
65
|
-
length: 50,
|
|
66
|
-
name: 'target_type'
|
|
67
|
-
}),
|
|
68
|
-
_ts_metadata("design:type", String)
|
|
69
|
-
], PermissionBase.prototype, "targetType", void 0);
|
|
70
|
-
_ts_decorate([
|
|
71
|
-
Column({
|
|
72
|
-
type: 'varchar',
|
|
73
|
-
length: 150,
|
|
74
|
-
name: 'target_id'
|
|
75
|
-
}),
|
|
76
|
-
_ts_metadata("design:type", String)
|
|
77
|
-
], PermissionBase.prototype, "targetId", void 0);
|
|
78
|
-
_ts_decorate([
|
|
79
|
-
Column({
|
|
80
|
-
type: 'timestamp',
|
|
81
|
-
nullable: true,
|
|
82
|
-
name: 'valid_from'
|
|
83
|
-
}),
|
|
84
|
-
_ts_metadata("design:type", Object)
|
|
85
|
-
], PermissionBase.prototype, "validFrom", void 0);
|
|
86
|
-
_ts_decorate([
|
|
87
|
-
Column({
|
|
88
|
-
type: 'timestamp',
|
|
89
|
-
nullable: true,
|
|
90
|
-
name: 'valid_until'
|
|
91
|
-
}),
|
|
92
|
-
_ts_metadata("design:type", Object)
|
|
93
|
-
], PermissionBase.prototype, "validUntil", void 0);
|
|
94
|
-
_ts_decorate([
|
|
95
|
-
Column({
|
|
96
|
-
type: 'text',
|
|
97
|
-
nullable: true
|
|
98
|
-
}),
|
|
99
|
-
_ts_metadata("design:type", Object)
|
|
100
|
-
], PermissionBase.prototype, "reason", void 0);
|
|
@@ -1,90 +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
|
-
import { Column, Entity, Index } from 'typeorm';
|
|
24
|
-
import { PermissionBase } from './permission-base.entity';
|
|
25
|
-
export class UserIamPermissionWithCompany extends PermissionBase {
|
|
26
|
-
constructor(...args){
|
|
27
|
-
super(...args), /**
|
|
28
|
-
* Company ID - Company scope for this permission
|
|
29
|
-
* - null: Global permission (not company-specific)
|
|
30
|
-
* - set: Permission belongs to this company
|
|
31
|
-
*/ _define_property(this, "companyId", void 0), /**
|
|
32
|
-
* Branch ID - Branch scope for this permission
|
|
33
|
-
* - null: Company-wide permission (all branches in company)
|
|
34
|
-
* - set: Permission applies only to this specific branch
|
|
35
|
-
*/ _define_property(this, "branchId", void 0);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
_ts_decorate([
|
|
39
|
-
Column({
|
|
40
|
-
type: 'varchar',
|
|
41
|
-
length: 150,
|
|
42
|
-
nullable: true,
|
|
43
|
-
name: 'company_id'
|
|
44
|
-
}),
|
|
45
|
-
_ts_metadata("design:type", Object)
|
|
46
|
-
], UserIamPermissionWithCompany.prototype, "companyId", void 0);
|
|
47
|
-
_ts_decorate([
|
|
48
|
-
Column({
|
|
49
|
-
type: 'varchar',
|
|
50
|
-
length: 150,
|
|
51
|
-
nullable: true,
|
|
52
|
-
name: 'branch_id'
|
|
53
|
-
}),
|
|
54
|
-
_ts_metadata("design:type", Object)
|
|
55
|
-
], UserIamPermissionWithCompany.prototype, "branchId", void 0);
|
|
56
|
-
UserIamPermissionWithCompany = _ts_decorate([
|
|
57
|
-
Entity({
|
|
58
|
-
name: 'user_iam_permission'
|
|
59
|
-
}),
|
|
60
|
-
Index([
|
|
61
|
-
'permissionType',
|
|
62
|
-
'sourceId',
|
|
63
|
-
'targetId',
|
|
64
|
-
'companyId',
|
|
65
|
-
'branchId'
|
|
66
|
-
], {
|
|
67
|
-
unique: true
|
|
68
|
-
}),
|
|
69
|
-
Index([
|
|
70
|
-
'sourceId',
|
|
71
|
-
'sourceType'
|
|
72
|
-
]),
|
|
73
|
-
Index([
|
|
74
|
-
'targetId',
|
|
75
|
-
'targetType'
|
|
76
|
-
]),
|
|
77
|
-
Index([
|
|
78
|
-
'permissionType'
|
|
79
|
-
]),
|
|
80
|
-
Index([
|
|
81
|
-
'companyId'
|
|
82
|
-
]),
|
|
83
|
-
Index([
|
|
84
|
-
'branchId'
|
|
85
|
-
]),
|
|
86
|
-
Index([
|
|
87
|
-
'companyId',
|
|
88
|
-
'branchId'
|
|
89
|
-
])
|
|
90
|
-
], UserIamPermissionWithCompany);
|
|
@@ -1,70 +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
|
-
import { Identity } from '@flusys/nestjs-shared';
|
|
24
|
-
import { Column } from 'typeorm';
|
|
25
|
-
export class RoleBase extends Identity {
|
|
26
|
-
constructor(...args){
|
|
27
|
-
super(...args), _define_property(this, "readOnly", void 0), _define_property(this, "name", void 0), _define_property(this, "description", void 0), _define_property(this, "isActive", void 0), _define_property(this, "serial", void 0);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
_ts_decorate([
|
|
31
|
-
Column({
|
|
32
|
-
type: 'boolean',
|
|
33
|
-
nullable: false,
|
|
34
|
-
default: false,
|
|
35
|
-
name: 'read_only'
|
|
36
|
-
}),
|
|
37
|
-
_ts_metadata("design:type", Boolean)
|
|
38
|
-
], RoleBase.prototype, "readOnly", void 0);
|
|
39
|
-
_ts_decorate([
|
|
40
|
-
Column({
|
|
41
|
-
type: 'varchar',
|
|
42
|
-
length: 255,
|
|
43
|
-
nullable: false
|
|
44
|
-
}),
|
|
45
|
-
_ts_metadata("design:type", String)
|
|
46
|
-
], RoleBase.prototype, "name", void 0);
|
|
47
|
-
_ts_decorate([
|
|
48
|
-
Column({
|
|
49
|
-
type: 'varchar',
|
|
50
|
-
length: 500,
|
|
51
|
-
nullable: true
|
|
52
|
-
}),
|
|
53
|
-
_ts_metadata("design:type", Object)
|
|
54
|
-
], RoleBase.prototype, "description", void 0);
|
|
55
|
-
_ts_decorate([
|
|
56
|
-
Column({
|
|
57
|
-
type: 'boolean',
|
|
58
|
-
nullable: false,
|
|
59
|
-
default: true,
|
|
60
|
-
name: 'is_active'
|
|
61
|
-
}),
|
|
62
|
-
_ts_metadata("design:type", Boolean)
|
|
63
|
-
], RoleBase.prototype, "isActive", void 0);
|
|
64
|
-
_ts_decorate([
|
|
65
|
-
Column({
|
|
66
|
-
type: 'int',
|
|
67
|
-
nullable: true
|
|
68
|
-
}),
|
|
69
|
-
_ts_metadata("design:type", Object)
|
|
70
|
-
], RoleBase.prototype, "serial", void 0);
|
|
@@ -1,45 +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
|
-
import { Column, Entity, Index } from 'typeorm';
|
|
24
|
-
import { RoleBase } from './role-base.entity';
|
|
25
|
-
export class RoleWithCompany extends RoleBase {
|
|
26
|
-
constructor(...args){
|
|
27
|
-
super(...args), _define_property(this, "companyId", void 0);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
_ts_decorate([
|
|
31
|
-
Column({
|
|
32
|
-
type: 'uuid',
|
|
33
|
-
nullable: true,
|
|
34
|
-
name: 'company_id'
|
|
35
|
-
}),
|
|
36
|
-
_ts_metadata("design:type", Object)
|
|
37
|
-
], RoleWithCompany.prototype, "companyId", void 0);
|
|
38
|
-
RoleWithCompany = _ts_decorate([
|
|
39
|
-
Entity({
|
|
40
|
-
name: 'role'
|
|
41
|
-
}),
|
|
42
|
-
Index([
|
|
43
|
-
'companyId'
|
|
44
|
-
])
|
|
45
|
-
], RoleWithCompany);
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
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;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
import { Entity } from 'typeorm';
|
|
8
|
-
import { RoleBase } from './role-base.entity';
|
|
9
|
-
export class Role extends RoleBase {
|
|
10
|
-
}
|
|
11
|
-
Role = _ts_decorate([
|
|
12
|
-
Entity({
|
|
13
|
-
name: 'role'
|
|
14
|
-
})
|
|
15
|
-
], Role);
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
function _ts_decorate(decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
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;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
import { Entity, Index } from 'typeorm';
|
|
8
|
-
import { PermissionBase } from './permission-base.entity';
|
|
9
|
-
export class UserIamPermission extends PermissionBase {
|
|
10
|
-
}
|
|
11
|
-
UserIamPermission = _ts_decorate([
|
|
12
|
-
Entity({
|
|
13
|
-
name: 'user_iam_permission'
|
|
14
|
-
}),
|
|
15
|
-
Index([
|
|
16
|
-
'permissionType',
|
|
17
|
-
'sourceId',
|
|
18
|
-
'targetId'
|
|
19
|
-
], {
|
|
20
|
-
unique: true
|
|
21
|
-
}),
|
|
22
|
-
Index([
|
|
23
|
-
'sourceId',
|
|
24
|
-
'sourceType'
|
|
25
|
-
]),
|
|
26
|
-
Index([
|
|
27
|
-
'targetId',
|
|
28
|
-
'targetType'
|
|
29
|
-
]),
|
|
30
|
-
Index([
|
|
31
|
-
'permissionType'
|
|
32
|
-
])
|
|
33
|
-
], UserIamPermission);
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ActionType Enum - Categorizes actions by their usage context
|
|
3
|
-
*
|
|
4
|
-
* - BACKEND: Actions for API endpoint permissions (cached for PermissionGuard)
|
|
5
|
-
* - FRONTEND: Actions for frontend features (returned in my-permissions API)
|
|
6
|
-
* - BOTH: Actions used for both backend and frontend (cached + returned)
|
|
7
|
-
*/ export var ActionType = /*#__PURE__*/ function(ActionType) {
|
|
8
|
-
ActionType["BACKEND"] = "backend";
|
|
9
|
-
ActionType["FRONTEND"] = "frontend";
|
|
10
|
-
ActionType["BOTH"] = "both";
|
|
11
|
-
return ActionType;
|
|
12
|
-
}({});
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export var IamPermissionType = /*#__PURE__*/ function(IamPermissionType) {
|
|
2
|
-
IamPermissionType["USER_ROLE"] = "user_role";
|
|
3
|
-
IamPermissionType["ROLE_ACTION"] = "role_action";
|
|
4
|
-
IamPermissionType["USER_ACTION"] = "user_action";
|
|
5
|
-
IamPermissionType["COMPANY_ACTION"] = "company_action";
|
|
6
|
-
return IamPermissionType;
|
|
7
|
-
}({});
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export var IAMPermissionMode = /*#__PURE__*/ function(IAMPermissionMode) {
|
|
2
|
-
IAMPermissionMode[IAMPermissionMode["RBAC"] = 1] = "RBAC";
|
|
3
|
-
IAMPermissionMode[IAMPermissionMode["DIRECT"] = 2] = "DIRECT";
|
|
4
|
-
IAMPermissionMode[IAMPermissionMode["FULL"] = 3] = "FULL";
|
|
5
|
-
return IAMPermissionMode;
|
|
6
|
-
}({});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { ForbiddenException } from '@nestjs/common';
|
|
2
|
-
import { AUTH_MESSAGES } from '@flusys/nestjs-shared/constants';
|
|
3
|
-
/**
|
|
4
|
-
* Validates that user has access to the specified company.
|
|
5
|
-
* Used for user-action and role-permission operations when company feature is enabled.
|
|
6
|
-
*
|
|
7
|
-
* @throws ForbiddenException if user doesn't have access to the company
|
|
8
|
-
*/ export function validateCompanyAccess(config, companyId, user, errorMessage = 'You do not have access to this company', messageKey = AUTH_MESSAGES.COMPANY_NO_ACCESS) {
|
|
9
|
-
if (!config.isCompanyFeatureEnabled() || !companyId) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
if (user.companyId !== companyId) {
|
|
13
|
-
throw new ForbiddenException({
|
|
14
|
-
message: errorMessage,
|
|
15
|
-
messageKey
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { ForbiddenException } from '@nestjs/common';
|
|
2
|
-
import { AUTH_MESSAGES } from '@flusys/nestjs-shared/constants';
|
|
3
|
-
import { buildMockUser } from '@test-utils/mocks/logged-user.mock';
|
|
4
|
-
import { validateCompanyAccess } from './company-access.helper';
|
|
5
|
-
describe('validateCompanyAccess', ()=>{
|
|
6
|
-
function buildConfig(isCompanyFeatureEnabled) {
|
|
7
|
-
return {
|
|
8
|
-
isCompanyFeatureEnabled: jest.fn().mockReturnValue(isCompanyFeatureEnabled)
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
it('does not throw when company feature is disabled', ()=>{
|
|
12
|
-
const config = buildConfig(false);
|
|
13
|
-
const user = buildMockUser({
|
|
14
|
-
companyId: 'company-uuid-1'
|
|
15
|
-
});
|
|
16
|
-
expect(()=>validateCompanyAccess(config, 'company-uuid-2', user)).not.toThrow();
|
|
17
|
-
});
|
|
18
|
-
it('does not throw when companyId is undefined', ()=>{
|
|
19
|
-
const config = buildConfig(true);
|
|
20
|
-
const user = buildMockUser({
|
|
21
|
-
companyId: 'company-uuid-1'
|
|
22
|
-
});
|
|
23
|
-
expect(()=>validateCompanyAccess(config, undefined, user)).not.toThrow();
|
|
24
|
-
});
|
|
25
|
-
it('does not throw when the companyId matches the user company', ()=>{
|
|
26
|
-
const config = buildConfig(true);
|
|
27
|
-
const user = buildMockUser({
|
|
28
|
-
companyId: 'company-uuid-1'
|
|
29
|
-
});
|
|
30
|
-
expect(()=>validateCompanyAccess(config, 'company-uuid-1', user)).not.toThrow();
|
|
31
|
-
});
|
|
32
|
-
it('throws ForbiddenException with default message/key when the company does not match', ()=>{
|
|
33
|
-
const config = buildConfig(true);
|
|
34
|
-
const user = buildMockUser({
|
|
35
|
-
companyId: 'company-uuid-1'
|
|
36
|
-
});
|
|
37
|
-
try {
|
|
38
|
-
validateCompanyAccess(config, 'company-uuid-2', user);
|
|
39
|
-
fail('expected validateCompanyAccess to throw');
|
|
40
|
-
} catch (error) {
|
|
41
|
-
expect(error).toBeInstanceOf(ForbiddenException);
|
|
42
|
-
expect(error.getResponse()).toEqual(expect.objectContaining({
|
|
43
|
-
message: 'You do not have access to this company',
|
|
44
|
-
messageKey: AUTH_MESSAGES.COMPANY_NO_ACCESS
|
|
45
|
-
}));
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
it('throws with a custom message and messageKey when provided', ()=>{
|
|
49
|
-
const config = buildConfig(true);
|
|
50
|
-
const user = buildMockUser({
|
|
51
|
-
companyId: 'company-uuid-1'
|
|
52
|
-
});
|
|
53
|
-
try {
|
|
54
|
-
validateCompanyAccess(config, 'company-uuid-2', user, 'Custom message', 'custom.message.key');
|
|
55
|
-
fail('expected validateCompanyAccess to throw');
|
|
56
|
-
} catch (error) {
|
|
57
|
-
expect(error).toBeInstanceOf(ForbiddenException);
|
|
58
|
-
expect(error.getResponse()).toEqual(expect.objectContaining({
|
|
59
|
-
message: 'Custom message',
|
|
60
|
-
messageKey: 'custom.message.key'
|
|
61
|
-
}));
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
});
|