rez_core 6.5.10 → 6.5.11
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/.claude/settings.local.json +26 -0
- package/.idea/250218_nodejs_core.iml +9 -0
- package/.idea/codeStyles/Project.xml +59 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/copilot.data.migration.agent.xml +6 -0
- package/.idea/copilot.data.migration.ask.xml +6 -0
- package/.idea/copilot.data.migration.ask2agent.xml +6 -0
- package/.idea/copilot.data.migration.edit.xml +6 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/prettier.xml +6 -0
- package/.idea/vcs.xml +6 -0
- package/dist/module/auth/strategies/jwt.strategy.d.ts +1 -0
- package/dist/module/auth/strategies/jwt.strategy.js +2 -1
- package/dist/module/auth/strategies/jwt.strategy.js.map +1 -1
- package/dist/module/meta/entity.module.js +3 -4
- package/dist/module/meta/entity.module.js.map +1 -1
- package/dist/module/module/controller/module-access.controller.d.ts +7 -7
- package/dist/module/module/controller/module-access.controller.js +20 -20
- package/dist/module/module/controller/module-access.controller.js.map +1 -1
- package/dist/module/module/entity/module-access.entity.d.ts +1 -1
- package/dist/module/module/entity/module-access.entity.js +1 -1
- package/dist/module/module/entity/module-access.entity.js.map +1 -1
- package/dist/module/module/module.module.js +3 -1
- package/dist/module/module/module.module.js.map +1 -1
- package/dist/module/module/repository/module-access.repository.d.ts +15 -13
- package/dist/module/module/repository/module-access.repository.js +68 -34
- package/dist/module/module/repository/module-access.repository.js.map +1 -1
- package/dist/module/module/service/module-access.service.d.ts +16 -15
- package/dist/module/module/service/module-access.service.js +34 -28
- package/dist/module/module/service/module-access.service.js.map +1 -1
- package/dist/module/user/repository/role.repository.d.ts +1 -0
- package/dist/module/user/repository/role.repository.js +3 -0
- package/dist/module/user/repository/role.repository.js.map +1 -1
- package/dist/module/user/repository/user-role-mapping.repository.d.ts +1 -0
- package/dist/module/user/repository/user-role-mapping.repository.js +3 -0
- package/dist/module/user/repository/user-role-mapping.repository.js.map +1 -1
- package/dist/module/user/repository/user.repository.d.ts +2 -1
- package/dist/module/user/repository/user.repository.js +11 -2
- package/dist/module/user/repository/user.repository.js.map +1 -1
- package/dist/module/user/service/login.service.js +8 -2
- package/dist/module/user/service/login.service.js.map +1 -1
- package/dist/module/user/service/role.service.d.ts +1 -0
- package/dist/module/user/service/role.service.js +3 -0
- package/dist/module/user/service/role.service.js.map +1 -1
- package/dist/module/user/service/user-role-mapping.service.d.ts +2 -0
- package/dist/module/user/service/user-role-mapping.service.js +6 -0
- package/dist/module/user/service/user-role-mapping.service.js.map +1 -1
- package/dist/module/user/service/user-session.service.d.ts +1 -1
- package/dist/module/user/service/user-session.service.js +2 -1
- package/dist/module/user/service/user-session.service.js.map +1 -1
- package/dist/module/user/service/user.service.d.ts +2 -1
- package/dist/module/user/service/user.service.js +5 -2
- package/dist/module/user/service/user.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/server.log +850 -0
- package/src/module/auth/strategies/jwt.strategy.ts +2 -0
- package/src/module/meta/entity.module.ts +4 -15
- package/src/module/module/controller/module-access.controller.ts +11 -11
- package/src/module/module/entity/module-access.entity.ts +1 -1
- package/src/module/module/module.module.ts +3 -1
- package/src/module/module/repository/module-access.repository.ts +75 -39
- package/src/module/module/service/module-access.service.ts +35 -31
- package/src/module/user/repository/role.repository.ts +6 -2
- package/src/module/user/repository/user-role-mapping.repository.ts +5 -1
- package/src/module/user/repository/user.repository.ts +18 -2
- package/src/module/user/service/login.service.ts +10 -2
- package/src/module/user/service/role.service.ts +4 -0
- package/src/module/user/service/user-role-mapping.service.ts +23 -1
- package/src/module/user/service/user-session.service.ts +2 -1
- package/src/module/user/service/user.service.ts +6 -1
|
@@ -27,6 +27,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
|
|
|
27
27
|
enterprise_id,
|
|
28
28
|
level_id,
|
|
29
29
|
level_type,
|
|
30
|
+
appcode
|
|
30
31
|
} = payload;
|
|
31
32
|
|
|
32
33
|
// Check if session exists and is valid
|
|
@@ -51,6 +52,7 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
|
|
|
51
52
|
enterprise_id: enterprise_id,
|
|
52
53
|
level_id: level_id,
|
|
53
54
|
level_type: level_type,
|
|
55
|
+
appcode: appcode
|
|
54
56
|
};
|
|
55
57
|
|
|
56
58
|
return { userData };
|
|
@@ -82,8 +82,7 @@ import { EntityRelationRepository } from './repository/entity-relation.repositor
|
|
|
82
82
|
forwardRef(() => ListMasterModule),
|
|
83
83
|
forwardRef(() => FilterModule),
|
|
84
84
|
UtilsModule,
|
|
85
|
-
WorkflowAutomationModule
|
|
86
|
-
|
|
85
|
+
WorkflowAutomationModule
|
|
87
86
|
],
|
|
88
87
|
providers: [
|
|
89
88
|
EntityMasterService,
|
|
@@ -104,8 +103,6 @@ import { EntityRelationRepository } from './repository/entity-relation.repositor
|
|
|
104
103
|
MediaDataService,
|
|
105
104
|
AttributeMasterService,
|
|
106
105
|
EntityUpdateService,
|
|
107
|
-
// SectionMasterService,
|
|
108
|
-
// FieldGroupService,
|
|
109
106
|
ViewMaterRespository,
|
|
110
107
|
EntityValidationService,
|
|
111
108
|
{ provide: 'ViewMasterService', useClass: ViewMasterService },
|
|
@@ -114,9 +111,6 @@ import { EntityRelationRepository } from './repository/entity-relation.repositor
|
|
|
114
111
|
provide: 'EntityRelationDataService',
|
|
115
112
|
useClass: EntityRelationDataService,
|
|
116
113
|
},
|
|
117
|
-
|
|
118
|
-
// UserAppMappingService,
|
|
119
|
-
// UserAppMappingRepository,
|
|
120
114
|
UserRoleMappingRepository,
|
|
121
115
|
AppMasterRespository,
|
|
122
116
|
AppMasterService,
|
|
@@ -135,20 +129,15 @@ import { EntityRelationRepository } from './repository/entity-relation.repositor
|
|
|
135
129
|
MediaDataService,
|
|
136
130
|
EntityUpdateService,
|
|
137
131
|
EntityUpdateRepository,
|
|
138
|
-
// SectionMasterService,
|
|
139
|
-
// FieldGroupService,
|
|
140
132
|
'ViewMasterService',
|
|
141
133
|
AttributeMasterService,
|
|
142
|
-
// UserAppMappingService,
|
|
143
|
-
// UserAppMappingRepository,
|
|
144
134
|
AppMasterService,
|
|
145
135
|
MasterService,
|
|
146
136
|
ResolverService,
|
|
147
137
|
EntityDynamicService,
|
|
148
138
|
'CommonService',
|
|
149
139
|
'EntityRelationService',
|
|
150
|
-
|
|
151
|
-
AttributeMasterRepository,
|
|
140
|
+
AppMasterRespository
|
|
152
141
|
],
|
|
153
142
|
controllers: [
|
|
154
143
|
EntityController,
|
|
@@ -161,7 +150,7 @@ import { EntityRelationRepository } from './repository/entity-relation.repositor
|
|
|
161
150
|
EntityDynamicController,
|
|
162
151
|
EntityRelationController,
|
|
163
152
|
EntityMasterController,
|
|
164
|
-
EntityPublicController
|
|
153
|
+
EntityPublicController
|
|
165
154
|
],
|
|
166
155
|
})
|
|
167
|
-
export class EntityModule {}
|
|
156
|
+
export class EntityModule { }
|
|
@@ -26,14 +26,14 @@ export class ModuleAccessController {
|
|
|
26
26
|
@Get('roles')
|
|
27
27
|
@HttpCode(HttpStatus.OK)
|
|
28
28
|
async getRoles(
|
|
29
|
-
@Query('
|
|
29
|
+
@Query('appcode') appcode: string,
|
|
30
30
|
@Query('include') include: string, // ✅ declare it as boolean
|
|
31
31
|
@Request() req,
|
|
32
32
|
) {
|
|
33
33
|
const { level_type, level_id } = req.user.userData;
|
|
34
34
|
|
|
35
35
|
return this.moduleAccessService.getRoles({
|
|
36
|
-
|
|
36
|
+
appcode,
|
|
37
37
|
level_type,
|
|
38
38
|
level_id,
|
|
39
39
|
include: include === 'true', // ensure it's either true or false
|
|
@@ -42,10 +42,10 @@ export class ModuleAccessController {
|
|
|
42
42
|
|
|
43
43
|
@Get('modules')
|
|
44
44
|
@HttpCode(HttpStatus.OK)
|
|
45
|
-
async getModules(@Query('
|
|
45
|
+
async getModules(@Query('appcode') appcode: string, @Request() req) {
|
|
46
46
|
const loggedInUser = req.user.userData;
|
|
47
47
|
return this.moduleAccessService.getModules({
|
|
48
|
-
|
|
48
|
+
appcode,
|
|
49
49
|
loggedInUser
|
|
50
50
|
});
|
|
51
51
|
}
|
|
@@ -54,16 +54,16 @@ export class ModuleAccessController {
|
|
|
54
54
|
@HttpCode(HttpStatus.OK)
|
|
55
55
|
async getAccessListing(
|
|
56
56
|
@Query('roles') roleIds: string,
|
|
57
|
-
@Query('
|
|
57
|
+
@Query('appcode') queryAppCode: string,
|
|
58
58
|
@Request() req,
|
|
59
59
|
) {
|
|
60
60
|
const roleIdArray = roleIds.split(',').map(Number);
|
|
61
|
-
const
|
|
61
|
+
const appcode = queryAppCode || req.user.userData.appcode;
|
|
62
62
|
const level_type = req.user.userData.level_type;
|
|
63
63
|
const level_id = req.user.userData.level_id;
|
|
64
64
|
return this.moduleAccessService.getAccessListing(
|
|
65
65
|
roleIdArray,
|
|
66
|
-
|
|
66
|
+
appcode,
|
|
67
67
|
level_type,
|
|
68
68
|
level_id,
|
|
69
69
|
);
|
|
@@ -73,7 +73,7 @@ export class ModuleAccessController {
|
|
|
73
73
|
@HttpCode(HttpStatus.OK)
|
|
74
74
|
async getMenuListing(
|
|
75
75
|
@Query('mainmod') mainModIds: string,
|
|
76
|
-
@Query('
|
|
76
|
+
@Query('appcode') appcode: string,
|
|
77
77
|
@Request() req,
|
|
78
78
|
) {
|
|
79
79
|
const mainModArray = mainModIds.split(',').map(String);
|
|
@@ -81,7 +81,7 @@ export class ModuleAccessController {
|
|
|
81
81
|
|
|
82
82
|
return this.moduleAccessService.getMenuListing(
|
|
83
83
|
mainModArray,
|
|
84
|
-
|
|
84
|
+
appcode,
|
|
85
85
|
level_type,
|
|
86
86
|
);
|
|
87
87
|
}
|
|
@@ -97,7 +97,7 @@ export class ModuleAccessController {
|
|
|
97
97
|
@Get('ui-config')
|
|
98
98
|
@HttpCode(HttpStatus.OK)
|
|
99
99
|
async getModuleUIConfig(
|
|
100
|
-
@Query('
|
|
100
|
+
@Query('module_code') moduleCode: string,
|
|
101
101
|
@Request() req,
|
|
102
102
|
) {
|
|
103
103
|
const userId = req.user.userData?.id;
|
|
@@ -109,7 +109,7 @@ export class ModuleAccessController {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
return this.moduleAccessService.getModuleUIConfig(
|
|
112
|
-
|
|
112
|
+
moduleCode,
|
|
113
113
|
roles.map((id) => Number(id)),
|
|
114
114
|
);
|
|
115
115
|
}
|
|
@@ -2,8 +2,8 @@ import { Column, Entity, JoinColumn, ManyToMany, ManyToOne, OneToOne, PrimaryGen
|
|
|
2
2
|
import { ModuleData } from './module.entity';
|
|
3
3
|
import { Role } from 'src/module/user/entity/role.entity';
|
|
4
4
|
import { ModuleAction } from './module-action.entity';
|
|
5
|
-
import { AppMaster } from 'src/module/meta/entity/app-master.entity';
|
|
6
5
|
import { EnterpriseData } from 'src/module/enterprise/entity/enterprise.entity';
|
|
6
|
+
import { AppMaster } from '../../meta/entity/app-master.entity';
|
|
7
7
|
|
|
8
8
|
@Entity({ name: 'sso_module_access' })
|
|
9
9
|
export class ModuleAccess {
|
|
@@ -15,6 +15,7 @@ import { UserModule } from '../user/user.module';
|
|
|
15
15
|
import { Role } from '../user/entity/role.entity';
|
|
16
16
|
import { ModuleAccess } from './entity/module-access.entity';
|
|
17
17
|
import { ListMasterModule } from '../listmaster/listmaster.module';
|
|
18
|
+
import { EntityModule } from '../meta/entity.module';
|
|
18
19
|
|
|
19
20
|
@Module({
|
|
20
21
|
imports: [
|
|
@@ -27,7 +28,8 @@ import { ListMasterModule } from '../listmaster/listmaster.module';
|
|
|
27
28
|
Role,
|
|
28
29
|
]),
|
|
29
30
|
UtilsModule,
|
|
30
|
-
UserModule
|
|
31
|
+
UserModule,
|
|
32
|
+
EntityModule
|
|
31
33
|
],
|
|
32
34
|
controllers: [MenuController, ModuleAccessController],
|
|
33
35
|
providers: [
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { BadRequestException, Injectable } from '@nestjs/common';
|
|
2
2
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
3
|
-
import { In, Not, Repository,
|
|
3
|
+
import { In, Not, Repository, Or, DataSource, IsNull } from 'typeorm';
|
|
4
4
|
import { Role } from 'src/module/user/entity/role.entity';
|
|
5
5
|
import { ModuleAccess } from '../entity/module-access.entity';
|
|
6
6
|
import { ModuleAction } from '../entity/module-action.entity';
|
|
7
7
|
import { ModuleData } from '../entity/module.entity';
|
|
8
|
+
import { AppMasterRespository } from '../../meta/repository/app-master.repository';
|
|
8
9
|
|
|
9
10
|
@Injectable()
|
|
10
11
|
export class ModuleAccessRepository {
|
|
@@ -21,36 +22,39 @@ export class ModuleAccessRepository {
|
|
|
21
22
|
@InjectRepository(ModuleAction)
|
|
22
23
|
private readonly moduleActionRepo: Repository<ModuleAction>,
|
|
23
24
|
|
|
25
|
+
private readonly appMasterRepo: AppMasterRespository,
|
|
26
|
+
|
|
24
27
|
private readonly dataSource: DataSource,
|
|
25
28
|
) {}
|
|
26
29
|
|
|
27
30
|
async getRoles({
|
|
28
|
-
|
|
31
|
+
appcode,
|
|
29
32
|
level_type,
|
|
30
33
|
level_id,
|
|
31
34
|
}: {
|
|
32
|
-
|
|
35
|
+
appcode: string;
|
|
33
36
|
level_type?: string;
|
|
34
37
|
level_id?: number;
|
|
35
38
|
}) {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
const where: any = {
|
|
40
|
+
app: {
|
|
41
|
+
code: appcode,
|
|
42
|
+
},
|
|
43
|
+
is_factory: Or(IsNull(), Not(1)), // 👈 include NULL and exclude factory roles
|
|
44
|
+
};
|
|
42
45
|
|
|
43
46
|
if (level_type) {
|
|
44
|
-
|
|
47
|
+
where.level_type = level_type;
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
if (level_id !== undefined) {
|
|
48
|
-
|
|
49
|
-
level_id: String(level_id),
|
|
50
|
-
});
|
|
51
|
+
where.level_id = String(level_id);
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
const roles = await
|
|
54
|
+
const roles = await this.roleRepo.find({
|
|
55
|
+
where,
|
|
56
|
+
select: ['id', 'name'], // keep returned data same as your mapping
|
|
57
|
+
});
|
|
54
58
|
|
|
55
59
|
return roles.map((role) => ({
|
|
56
60
|
label: role.name,
|
|
@@ -59,20 +63,26 @@ export class ModuleAccessRepository {
|
|
|
59
63
|
}
|
|
60
64
|
|
|
61
65
|
async getModules({
|
|
62
|
-
|
|
66
|
+
appcode,
|
|
63
67
|
loggedInUser,
|
|
64
68
|
}: {
|
|
65
|
-
|
|
69
|
+
appcode: string;
|
|
66
70
|
loggedInUser: any;
|
|
67
71
|
}) {
|
|
68
72
|
let modules: any[];
|
|
69
73
|
if (loggedInUser.level_type == 'SCH') {
|
|
70
74
|
modules = await this.moduleRepo.find({
|
|
71
|
-
where: { module_level: 'MAINMOD',
|
|
75
|
+
where: { module_level: 'MAINMOD',
|
|
76
|
+
app: {
|
|
77
|
+
code: appcode
|
|
78
|
+
},
|
|
79
|
+
level_type: 'SCH'
|
|
80
|
+
},
|
|
72
81
|
});
|
|
73
82
|
} else {
|
|
74
83
|
modules = await this.moduleRepo.find({
|
|
75
|
-
where: { module_level: 'MAINMOD',
|
|
84
|
+
where: { module_level: 'MAINMOD', app : {code: appcode
|
|
85
|
+
} },
|
|
76
86
|
});
|
|
77
87
|
}
|
|
78
88
|
|
|
@@ -87,7 +97,7 @@ export class ModuleAccessRepository {
|
|
|
87
97
|
|
|
88
98
|
async getAccessListing(
|
|
89
99
|
roleIds: (number | string)[],
|
|
90
|
-
|
|
100
|
+
appcode: string,
|
|
91
101
|
levelType: string,
|
|
92
102
|
levelId?: number, // add levelId as input so we can fetch roles based on it
|
|
93
103
|
) {
|
|
@@ -96,7 +106,7 @@ export class ModuleAccessRepository {
|
|
|
96
106
|
if (roleIds.length === 1 && roleIds[0] === -1) {
|
|
97
107
|
// Internally call getRoles
|
|
98
108
|
const fetchedRoles = await this.getRoles({
|
|
99
|
-
|
|
109
|
+
appcode,
|
|
100
110
|
level_type: levelType,
|
|
101
111
|
level_id: levelId,
|
|
102
112
|
});
|
|
@@ -105,14 +115,18 @@ export class ModuleAccessRepository {
|
|
|
105
115
|
roles = await this.roleRepo.find({
|
|
106
116
|
where: {
|
|
107
117
|
id: In(fetchedRoleIds),
|
|
108
|
-
|
|
118
|
+
app: {
|
|
119
|
+
code: appcode
|
|
120
|
+
},
|
|
109
121
|
},
|
|
110
122
|
});
|
|
111
123
|
} else {
|
|
112
124
|
roles = await this.roleRepo.find({
|
|
113
125
|
where: {
|
|
114
126
|
id: In(roleIds.map((id) => Number(id))),
|
|
115
|
-
|
|
127
|
+
app: {
|
|
128
|
+
code: appcode
|
|
129
|
+
},
|
|
116
130
|
},
|
|
117
131
|
});
|
|
118
132
|
}
|
|
@@ -122,9 +136,15 @@ export class ModuleAccessRepository {
|
|
|
122
136
|
const moduleAccesses = await this.moduleAccessRepo.find({
|
|
123
137
|
where: {
|
|
124
138
|
role_id: In(roles.map((role) => role.id)),
|
|
125
|
-
|
|
126
|
-
|
|
139
|
+
app: {
|
|
140
|
+
code: appcode
|
|
141
|
+
},
|
|
142
|
+
level_type: levelType
|
|
127
143
|
},
|
|
144
|
+
relations: {
|
|
145
|
+
app: true,
|
|
146
|
+
module: true
|
|
147
|
+
}
|
|
128
148
|
});
|
|
129
149
|
|
|
130
150
|
return roles.map((role) => ({
|
|
@@ -133,23 +153,31 @@ export class ModuleAccessRepository {
|
|
|
133
153
|
permission: moduleAccesses
|
|
134
154
|
.filter((access) => access.role_id === role.id)
|
|
135
155
|
.map((access) => ({
|
|
136
|
-
|
|
156
|
+
action: access.action_type,
|
|
137
157
|
access: access.access_flag,
|
|
138
158
|
module_id: access.module_id,
|
|
139
159
|
level_type: access.level_type,
|
|
140
160
|
app_id: access.app_id,
|
|
161
|
+
code: access.module.module_code,
|
|
162
|
+
appcode: access.app.code
|
|
141
163
|
})),
|
|
142
164
|
}));
|
|
143
165
|
}
|
|
144
166
|
|
|
145
|
-
async getAllModulesByLevel(mainModIds: string[],
|
|
167
|
+
async getAllModulesByLevel(mainModIds: string[], appcode: string, levelType) {
|
|
168
|
+
const appMaster = await this.appMasterRepo.getAppMasterDataByAppCode(appcode);
|
|
169
|
+
|
|
170
|
+
if (!appMaster) {
|
|
171
|
+
return {};
|
|
172
|
+
}
|
|
173
|
+
|
|
146
174
|
const mainModules =
|
|
147
175
|
mainModIds.length === 1 && mainModIds[0] === '-1'
|
|
148
176
|
? await this.moduleRepo.find({
|
|
149
|
-
where: { module_level: 'MAINMOD', app_id },
|
|
177
|
+
where: { module_level: 'MAINMOD', app_id: appMaster[0].id },
|
|
150
178
|
})
|
|
151
179
|
: await this.moduleRepo.find({
|
|
152
|
-
where: { id: In(mainModIds), module_level: 'MAINMOD',
|
|
180
|
+
where: { id: In(mainModIds), module_level: 'MAINMOD', app: {code: appcode} },
|
|
153
181
|
});
|
|
154
182
|
|
|
155
183
|
if (!mainModules.length) return {};
|
|
@@ -164,7 +192,7 @@ export class ModuleAccessRepository {
|
|
|
164
192
|
.join(' OR '),
|
|
165
193
|
Object.fromEntries(wbsCodes.map((code) => [`code${code}`, `${code}%`])),
|
|
166
194
|
)
|
|
167
|
-
.andWhere('module.app_id = :app_id', { app_id })
|
|
195
|
+
.andWhere('module.app_id = :app_id', { app_id: appMaster[0].id })
|
|
168
196
|
.andWhere('module.module_code != :excludedCode', {
|
|
169
197
|
excludedCode: 'all_organization_adm_org',
|
|
170
198
|
})
|
|
@@ -219,6 +247,7 @@ export class ModuleAccessRepository {
|
|
|
219
247
|
.map((mod) => ({
|
|
220
248
|
name: mod.name,
|
|
221
249
|
module_id: mod.id,
|
|
250
|
+
code: mod.module_code,
|
|
222
251
|
permission: actionMap[mod.module_code] || [],
|
|
223
252
|
submod: buildHierarchy(mod.wbs_code),
|
|
224
253
|
}));
|
|
@@ -228,6 +257,7 @@ export class ModuleAccessRepository {
|
|
|
228
257
|
.map((mod) => ({
|
|
229
258
|
name: mod.name,
|
|
230
259
|
module_id: mod.id,
|
|
260
|
+
code: mod.module_code,
|
|
231
261
|
permission: actionMap[mod.module_code] || [],
|
|
232
262
|
submod: buildHierarchy(mod.wbs_code),
|
|
233
263
|
}));
|
|
@@ -241,11 +271,11 @@ export class ModuleAccessRepository {
|
|
|
241
271
|
|
|
242
272
|
async updateModuleAccess(
|
|
243
273
|
accessList: {
|
|
244
|
-
|
|
245
|
-
|
|
274
|
+
role_code: string;
|
|
275
|
+
module_code: string;
|
|
246
276
|
action_type: string;
|
|
247
277
|
access_flag: number;
|
|
248
|
-
|
|
278
|
+
appcode: string;
|
|
249
279
|
level_type: string;
|
|
250
280
|
}[],
|
|
251
281
|
): Promise<boolean> {
|
|
@@ -253,10 +283,16 @@ export class ModuleAccessRepository {
|
|
|
253
283
|
for (const access of accessList) {
|
|
254
284
|
const existing = await this.moduleAccessRepo.findOne({
|
|
255
285
|
where: {
|
|
256
|
-
|
|
257
|
-
|
|
286
|
+
role: {
|
|
287
|
+
code: access.role_code,
|
|
288
|
+
},
|
|
289
|
+
module: {
|
|
290
|
+
module_code: access.module_code
|
|
291
|
+
},
|
|
258
292
|
action_type: access.action_type,
|
|
259
|
-
|
|
293
|
+
app: {
|
|
294
|
+
code: access.appcode
|
|
295
|
+
},
|
|
260
296
|
level_type: access.level_type,
|
|
261
297
|
},
|
|
262
298
|
});
|
|
@@ -266,7 +302,7 @@ export class ModuleAccessRepository {
|
|
|
266
302
|
await this.moduleAccessRepo.save(existing);
|
|
267
303
|
} else {
|
|
268
304
|
await this.moduleAccessRepo.save(
|
|
269
|
-
|
|
305
|
+
this.moduleAccessRepo.create(access),
|
|
270
306
|
);
|
|
271
307
|
}
|
|
272
308
|
}
|
|
@@ -277,16 +313,16 @@ export class ModuleAccessRepository {
|
|
|
277
313
|
}
|
|
278
314
|
}
|
|
279
315
|
|
|
280
|
-
async getModuleUIConfig(
|
|
316
|
+
async getModuleUIConfig(moduleCode: string, roleIds: number[]) {
|
|
281
317
|
const module = await this.moduleRepo.findOne({
|
|
282
|
-
where: {
|
|
318
|
+
where: { module_code: moduleCode },
|
|
283
319
|
});
|
|
284
320
|
|
|
285
321
|
if (!module) throw new BadRequestException('Module not found');
|
|
286
322
|
|
|
287
323
|
const actions = await this.moduleAccessRepo.find({
|
|
288
324
|
where: {
|
|
289
|
-
module_id:
|
|
325
|
+
module_id: module.id,
|
|
290
326
|
role_id: In(roleIds),
|
|
291
327
|
access_flag: 1,
|
|
292
328
|
},
|
|
@@ -1,57 +1,61 @@
|
|
|
1
1
|
import { BadRequestException, Injectable } from '@nestjs/common';
|
|
2
2
|
import { ModuleAccessRepository } from '../repository/module-access.repository';
|
|
3
|
-
import {
|
|
4
|
-
import { DataSource } from 'typeorm';
|
|
3
|
+
import { IsNull, Not, Or, Repository } from 'typeorm';
|
|
5
4
|
import { UserData } from 'src/module/user/entity/user.entity';
|
|
6
5
|
import { MenuRepository } from '../repository/menu.repository';
|
|
7
6
|
import { ReflectionHelper } from '../../../utils/service/reflection-helper.service';
|
|
7
|
+
import { Role } from '../../user/entity/role.entity';
|
|
8
|
+
import { InjectRepository } from '@nestjs/typeorm';
|
|
9
|
+
import { StatusConstant } from '../../../constant/status.constant';
|
|
8
10
|
|
|
9
11
|
@Injectable()
|
|
10
12
|
export class ModuleAccessService {
|
|
11
13
|
constructor(
|
|
12
14
|
private readonly moduleAccessRepository: ModuleAccessRepository,
|
|
13
15
|
private readonly menuRepository: MenuRepository,
|
|
14
|
-
private readonly dataSource: DataSource,
|
|
15
16
|
private readonly reflectionHelper: ReflectionHelper,
|
|
17
|
+
@InjectRepository(Role)
|
|
18
|
+
private readonly roleRepo: Repository<Role>
|
|
16
19
|
) {
|
|
17
20
|
}
|
|
18
21
|
|
|
19
|
-
async getModules({
|
|
22
|
+
async getModules({ appcode, loggedInUser }: { appcode: string, loggedInUser: UserData }) {
|
|
20
23
|
return this.moduleAccessRepository.getModules({
|
|
21
|
-
|
|
24
|
+
appcode, loggedInUser,
|
|
22
25
|
});
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
async getRoles({
|
|
26
|
-
|
|
29
|
+
appcode,
|
|
27
30
|
level_type,
|
|
28
31
|
level_id,
|
|
29
32
|
include,
|
|
30
33
|
}: {
|
|
31
|
-
|
|
34
|
+
appcode: string;
|
|
32
35
|
level_type?: string;
|
|
33
36
|
level_id?: number;
|
|
34
37
|
include?: boolean;
|
|
35
38
|
}) {
|
|
36
|
-
const query = this.dataSource
|
|
37
|
-
.createQueryBuilder()
|
|
38
|
-
.select('*')
|
|
39
|
-
.from('sso_role', 'role')
|
|
40
|
-
.where('role.app_id = :appId', { appId });
|
|
41
39
|
|
|
42
|
-
|
|
40
|
+
const where: any = {
|
|
41
|
+
app: {
|
|
42
|
+
code: appcode
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
43
46
|
if (!include) {
|
|
44
|
-
|
|
47
|
+
where.is_factory = Or(IsNull(), Not(1));
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
if (level_type && level_id) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
level_id: String(level_id),
|
|
51
|
-
});
|
|
51
|
+
where.level_type = level_type;
|
|
52
|
+
where.level_id = String(level_id);
|
|
52
53
|
}
|
|
53
54
|
|
|
54
|
-
const roles = await
|
|
55
|
+
const roles = await this.roleRepo.find({
|
|
56
|
+
where,
|
|
57
|
+
});
|
|
58
|
+
|
|
55
59
|
|
|
56
60
|
return roles.map((role) => ({
|
|
57
61
|
label: role.name,
|
|
@@ -61,13 +65,13 @@ export class ModuleAccessService {
|
|
|
61
65
|
|
|
62
66
|
async getAccessListing(
|
|
63
67
|
roleIds: number[],
|
|
64
|
-
|
|
68
|
+
appcode: string,
|
|
65
69
|
levelType: string,
|
|
66
70
|
level_id?: number,
|
|
67
71
|
) {
|
|
68
72
|
return this.moduleAccessRepository.getAccessListing(
|
|
69
73
|
roleIds,
|
|
70
|
-
|
|
74
|
+
appcode,
|
|
71
75
|
levelType,
|
|
72
76
|
level_id,
|
|
73
77
|
);
|
|
@@ -75,27 +79,27 @@ export class ModuleAccessService {
|
|
|
75
79
|
|
|
76
80
|
async getMenuListing(
|
|
77
81
|
mainModIds: string[],
|
|
78
|
-
|
|
82
|
+
appcode: string,
|
|
79
83
|
levelType: string,
|
|
80
84
|
): Promise<Record<string, any[]>> {
|
|
81
|
-
if (!
|
|
82
|
-
throw new BadRequestException('
|
|
85
|
+
if (!appcode) {
|
|
86
|
+
throw new BadRequestException('App code is required');
|
|
83
87
|
}
|
|
84
88
|
|
|
85
89
|
return this.moduleAccessRepository.getAllModulesByLevel(
|
|
86
90
|
mainModIds,
|
|
87
|
-
|
|
91
|
+
appcode,
|
|
88
92
|
levelType,
|
|
89
93
|
);
|
|
90
94
|
}
|
|
91
95
|
|
|
92
96
|
async updateModuleAccess(
|
|
93
97
|
moduleAccessData: {
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
role_code: string;
|
|
99
|
+
module_code: string;
|
|
96
100
|
action_type: string;
|
|
97
101
|
access_flag: number;
|
|
98
|
-
|
|
102
|
+
appcode: string;
|
|
99
103
|
level_type: string;
|
|
100
104
|
}[],
|
|
101
105
|
): Promise<{ success: boolean; msg: string }> {
|
|
@@ -115,8 +119,8 @@ export class ModuleAccessService {
|
|
|
115
119
|
|
|
116
120
|
// src/module/module-access/service/module-access.service.ts
|
|
117
121
|
|
|
118
|
-
async getModuleUIConfig(
|
|
119
|
-
return this.moduleAccessRepository.getModuleUIConfig(
|
|
122
|
+
async getModuleUIConfig(moduleCode: string, roleIds: number[]) {
|
|
123
|
+
return this.moduleAccessRepository.getModuleUIConfig(moduleCode, roleIds);
|
|
120
124
|
}
|
|
121
125
|
|
|
122
126
|
async getUserPermissions({
|
|
@@ -161,7 +165,7 @@ export class ModuleAccessService {
|
|
|
161
165
|
},
|
|
162
166
|
});
|
|
163
167
|
|
|
164
|
-
if (!school || school.status ===
|
|
168
|
+
if (!school || school.status === StatusConstant.INACTIVE) {
|
|
165
169
|
// Return only VIEW permissions
|
|
166
170
|
return allPermissions.filter((perm) => perm.action === 'VIEW');
|
|
167
171
|
}
|
|
@@ -8,7 +8,7 @@ export class RoleRepository {
|
|
|
8
8
|
constructor(
|
|
9
9
|
@InjectRepository(Role)
|
|
10
10
|
private readonly roleRepo: Repository<Role>,
|
|
11
|
-
) {}
|
|
11
|
+
) { }
|
|
12
12
|
|
|
13
13
|
async findByCode(code: string): Promise<Role | null> {
|
|
14
14
|
return this.roleRepo.findOne({ where: { code } });
|
|
@@ -98,7 +98,11 @@ export class RoleRepository {
|
|
|
98
98
|
return await this.roleRepo.save(entity);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
async updateRole(id:number, role:Role) {
|
|
101
|
+
async updateRole(id: number, role: Role) {
|
|
102
102
|
return await this.roleRepo.update(id, role);
|
|
103
103
|
}
|
|
104
|
+
|
|
105
|
+
async findRoles(options: any): Promise<Role[]> {
|
|
106
|
+
return await this.roleRepo.find(options);
|
|
107
|
+
}
|
|
104
108
|
}
|
|
@@ -9,7 +9,7 @@ export class UserRoleMappingRepository {
|
|
|
9
9
|
constructor(
|
|
10
10
|
@InjectRepository(UserRoleMapping)
|
|
11
11
|
private readonly userRoleMappingRepository: Repository<UserRoleMapping>,
|
|
12
|
-
) {}
|
|
12
|
+
) { }
|
|
13
13
|
|
|
14
14
|
async save(
|
|
15
15
|
userRoleMapping: UserRoleMapping,
|
|
@@ -123,4 +123,8 @@ export class UserRoleMappingRepository {
|
|
|
123
123
|
},
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
|
+
|
|
127
|
+
async find(options: any): Promise<UserRoleMapping[]> {
|
|
128
|
+
return await this.userRoleMappingRepository.find(options);
|
|
129
|
+
}
|
|
126
130
|
}
|