ecrs-auth-core 1.0.89 → 1.0.91
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/dist/auth.controller.js +6 -6
- package/dist/auth.service.d.ts +1 -9
- package/dist/auth.service.js +66 -68
- package/dist/index.d.ts +0 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/auth.controller.js
CHANGED
|
@@ -55,12 +55,12 @@ let AuthController = class AuthController {
|
|
|
55
55
|
console.warn(`⚠️ Invalid module ID provided by user ${body.email}: ${body.moduleId}`);
|
|
56
56
|
throw new common_1.UnauthorizedException('You are not authorized to access this module');
|
|
57
57
|
}
|
|
58
|
-
console.log(`🔍 Checking module access for user ID ${user.id} and module ID ${requestedModuleId}...`);
|
|
59
|
-
const allowedDb = await this.authService.hasModuleAccess(user.id, requestedModuleId);
|
|
60
|
-
console.log(`📊 Module access check result for user ID ${user.id} and module ID ${requestedModuleId}: ${allowedDb ? 'Allowed' : 'Denied'}`);
|
|
61
|
-
if (!allowedDb) {
|
|
62
|
-
|
|
63
|
-
}
|
|
58
|
+
// console.log(`🔍 Checking module access for user ID ${user.id} and module ID ${requestedModuleId}...`);
|
|
59
|
+
// const allowedDb = await this.authService.hasModuleAccess(user.id, requestedModuleId);
|
|
60
|
+
// console.log(`📊 Module access check result for user ID ${user.id} and module ID ${requestedModuleId}: ${allowedDb ? 'Allowed' : 'Denied'}`);
|
|
61
|
+
// if (!allowedDb) {
|
|
62
|
+
// throw new UnauthorizedException('You are not authorized to access this module');
|
|
63
|
+
// }
|
|
64
64
|
// const perms = await this.authService.getPermissions(user.id);
|
|
65
65
|
// console.log(`📊 User permissions for ${body.email}:`, perms);
|
|
66
66
|
// if (!Array.isArray(perms.modules) || !perms.modules.includes(requestedModuleId)) {
|
package/dist/auth.service.d.ts
CHANGED
|
@@ -9,11 +9,6 @@ export type RoutePermissionSet = {
|
|
|
9
9
|
import?: boolean;
|
|
10
10
|
export?: boolean;
|
|
11
11
|
};
|
|
12
|
-
interface PermissionsTree {
|
|
13
|
-
features: Record<string, string[]>;
|
|
14
|
-
modules: number[];
|
|
15
|
-
routes: Record<string, string[]>;
|
|
16
|
-
}
|
|
17
12
|
export declare class AuthService {
|
|
18
13
|
private readonly jwtService;
|
|
19
14
|
private readonly options;
|
|
@@ -22,7 +17,6 @@ export declare class AuthService {
|
|
|
22
17
|
private readonly moduleRepo;
|
|
23
18
|
private readonly featureRepo;
|
|
24
19
|
private readonly routeRepo;
|
|
25
|
-
private readonly featureAccessRepo;
|
|
26
20
|
private readonly moduleAccessRepo;
|
|
27
21
|
private readonly screenPermissionRepo;
|
|
28
22
|
private readonly ipRestrictionsRepo;
|
|
@@ -45,7 +39,7 @@ export declare class AuthService {
|
|
|
45
39
|
private normalizeIp;
|
|
46
40
|
private validateIpRestriction;
|
|
47
41
|
hasModuleAccess(userId: number, moduleId: number): Promise<boolean>;
|
|
48
|
-
getPermissions(userId: number): Promise<
|
|
42
|
+
getPermissions(userId: number): Promise<void>;
|
|
49
43
|
/**
|
|
50
44
|
* Save user last login details
|
|
51
45
|
* Updates the tbl_user_last_login table with latest login info
|
|
@@ -120,7 +114,5 @@ export declare class AuthService {
|
|
|
120
114
|
*/
|
|
121
115
|
extractUserIpv4(clientIp: string | undefined): string;
|
|
122
116
|
findUserById(id: number): Promise<User | null>;
|
|
123
|
-
private loadPermissions;
|
|
124
117
|
private loadModulePermissions;
|
|
125
118
|
}
|
|
126
|
-
export {};
|
package/dist/auth.service.js
CHANGED
|
@@ -61,7 +61,7 @@ let AuthService = class AuthService {
|
|
|
61
61
|
this.moduleRepo = repositories.moduleRepo;
|
|
62
62
|
this.featureRepo = repositories.featureRepo;
|
|
63
63
|
this.routeRepo = repositories.routeRepo;
|
|
64
|
-
this.featureAccessRepo = repositories.featureAccessRepo;
|
|
64
|
+
// this.featureAccessRepo = repositories.featureAccessRepo;
|
|
65
65
|
this.moduleAccessRepo = repositories.moduleAccessRepo;
|
|
66
66
|
this.screenPermissionRepo = repositories.screenPermissionRepo;
|
|
67
67
|
// Optional repositories
|
|
@@ -164,10 +164,6 @@ let AuthService = class AuthService {
|
|
|
164
164
|
if (!Number.isFinite(moduleId))
|
|
165
165
|
return false;
|
|
166
166
|
console.log(`🔍 Checking module access for user ID ${userId} and module ID ${moduleId}...`);
|
|
167
|
-
const access = await this.moduleAccessRepo.findOne({
|
|
168
|
-
where: { userId, moduleId, isDeleted: 0, status: 1 },
|
|
169
|
-
});
|
|
170
|
-
console.log(access);
|
|
171
167
|
const access1 = await this.moduleAccessRepo
|
|
172
168
|
.createQueryBuilder("ma")
|
|
173
169
|
.where("ma.userId = :userId", { userId })
|
|
@@ -176,12 +172,22 @@ let AuthService = class AuthService {
|
|
|
176
172
|
.andWhere("ma.isDeleted = 0")
|
|
177
173
|
.getOne();
|
|
178
174
|
console.log(access1);
|
|
175
|
+
let access;
|
|
176
|
+
try {
|
|
177
|
+
access = await this.moduleAccessRepo.findOne({
|
|
178
|
+
where: { userId, moduleId, isDeleted: 0, status: 1 },
|
|
179
|
+
});
|
|
180
|
+
console.log(access);
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
console.error(error);
|
|
184
|
+
}
|
|
179
185
|
console.log(`📊 Module access check result for user ID ${userId} and module ID ${moduleId}: ${access ? 'Allowed' : 'Denied'}`);
|
|
180
186
|
return !!access;
|
|
181
187
|
}
|
|
182
188
|
async getPermissions(userId) {
|
|
183
189
|
console.log(`🔍 Loading permissions for user ID ${userId}...`);
|
|
184
|
-
return this.loadPermissions(userId);
|
|
190
|
+
// return this.loadPermissions(userId);
|
|
185
191
|
}
|
|
186
192
|
/**
|
|
187
193
|
* Save user last login details
|
|
@@ -545,68 +551,60 @@ let AuthService = class AuthService {
|
|
|
545
551
|
async findUserById(id) {
|
|
546
552
|
return this.userRepo.findOne({ where: { id } });
|
|
547
553
|
}
|
|
548
|
-
async loadPermissions(userId) {
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
return {
|
|
605
|
-
features: featurePermissions,
|
|
606
|
-
modules: moduleIds,
|
|
607
|
-
routes: routePermissions,
|
|
608
|
-
};
|
|
609
|
-
}
|
|
554
|
+
// private async loadPermissions(userId: number): Promise<PermissionsTree> {
|
|
555
|
+
// // Feature Permissions
|
|
556
|
+
// const featureAccessList = await this.featureAccessRepo.find({
|
|
557
|
+
// where: { userId, isDeleted: 0 },
|
|
558
|
+
// });
|
|
559
|
+
// const featurePermissions: Record<string, string[]> = {};
|
|
560
|
+
// const allFeatures = await this.featureRepo.find();
|
|
561
|
+
// const featureMap = new Map(allFeatures.map((f) => [f.id, f]));
|
|
562
|
+
// for (const access of featureAccessList) {
|
|
563
|
+
// const feature = featureMap.get(access.featureId);
|
|
564
|
+
// if (!feature) continue;
|
|
565
|
+
// const perms: string[] = [];
|
|
566
|
+
// if (access.canView) perms.push('view');
|
|
567
|
+
// if (access.canCreate) perms.push('create');
|
|
568
|
+
// if (access.canModify) perms.push('update');
|
|
569
|
+
// if (access.canDelete) perms.push('delete');
|
|
570
|
+
// if (access.canImport) perms.push('import');
|
|
571
|
+
// if (access.canExport) perms.push('export');
|
|
572
|
+
// if (perms.length) {
|
|
573
|
+
// featurePermissions[feature.featureName] = perms;
|
|
574
|
+
// }
|
|
575
|
+
// }
|
|
576
|
+
// // Module Access - only count active (non-deleted, status=1) assignments
|
|
577
|
+
// const moduleAccess = await this.moduleAccessRepo.find({
|
|
578
|
+
// where: { userId, isDeleted: 0, status: 1 },
|
|
579
|
+
// });
|
|
580
|
+
// const moduleIds = moduleAccess.map((m) => m.moduleId);
|
|
581
|
+
// // Route Permissions
|
|
582
|
+
// const screenPermissionsList = await this.screenPermissionRepo.find({
|
|
583
|
+
// where: { userId, isActive: true },
|
|
584
|
+
// });
|
|
585
|
+
// const routePermissions: Record<string, string[]> = {};
|
|
586
|
+
// const allRoutes = await this.routeRepo.find();
|
|
587
|
+
// const routeMap = new Map(allRoutes.map((r) => [r.id, r]));
|
|
588
|
+
// for (const screen of screenPermissionsList) {
|
|
589
|
+
// const route = routeMap.get(screen.moduleRouteId);
|
|
590
|
+
// if (!route) continue;
|
|
591
|
+
// const perms: string[] = [];
|
|
592
|
+
// const keys = ['view', 'create', 'update', 'delete', 'import', 'export'] as const;
|
|
593
|
+
// for (const key of keys) {
|
|
594
|
+
// if (screen.permissions?.[key]) {
|
|
595
|
+
// perms.push(key);
|
|
596
|
+
// }
|
|
597
|
+
// }
|
|
598
|
+
// if (perms.length) {
|
|
599
|
+
// routePermissions[route.routeName] = perms;
|
|
600
|
+
// }
|
|
601
|
+
// }
|
|
602
|
+
// return {
|
|
603
|
+
// features: featurePermissions,
|
|
604
|
+
// modules: moduleIds,
|
|
605
|
+
// routes: routePermissions,
|
|
606
|
+
// };
|
|
607
|
+
// }
|
|
610
608
|
async loadModulePermissions(userId, moduleId) {
|
|
611
609
|
if (!Number.isFinite(moduleId)) {
|
|
612
610
|
return [];
|
package/dist/index.d.ts
CHANGED
|
@@ -22,7 +22,6 @@ export * from './entities/role.entity';
|
|
|
22
22
|
export * from './entities/module.entity';
|
|
23
23
|
export * from './entities/feature.entity';
|
|
24
24
|
export * from './entities/module-route.entity';
|
|
25
|
-
export * from './entities/user-feature-access.entity';
|
|
26
25
|
export * from './entities/user-module-access.entity';
|
|
27
26
|
export * from './entities/module-screen-permission.entity';
|
|
28
27
|
export * from './entities/api-key.entity';
|
package/dist/index.js
CHANGED
|
@@ -45,7 +45,7 @@ __exportStar(require("./entities/role.entity"), exports);
|
|
|
45
45
|
__exportStar(require("./entities/module.entity"), exports);
|
|
46
46
|
__exportStar(require("./entities/feature.entity"), exports);
|
|
47
47
|
__exportStar(require("./entities/module-route.entity"), exports);
|
|
48
|
-
|
|
48
|
+
// export * from './entities/user-feature-access.entity';
|
|
49
49
|
__exportStar(require("./entities/user-module-access.entity"), exports);
|
|
50
50
|
__exportStar(require("./entities/module-screen-permission.entity"), exports);
|
|
51
51
|
__exportStar(require("./entities/api-key.entity"), exports);
|