ecrs-auth-core 1.0.90 → 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 +56 -64
- 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
|
|
@@ -187,7 +187,7 @@ let AuthService = class AuthService {
|
|
|
187
187
|
}
|
|
188
188
|
async getPermissions(userId) {
|
|
189
189
|
console.log(`🔍 Loading permissions for user ID ${userId}...`);
|
|
190
|
-
return this.loadPermissions(userId);
|
|
190
|
+
// return this.loadPermissions(userId);
|
|
191
191
|
}
|
|
192
192
|
/**
|
|
193
193
|
* Save user last login details
|
|
@@ -551,68 +551,60 @@ let AuthService = class AuthService {
|
|
|
551
551
|
async findUserById(id) {
|
|
552
552
|
return this.userRepo.findOne({ where: { id } });
|
|
553
553
|
}
|
|
554
|
-
async loadPermissions(userId) {
|
|
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
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
return {
|
|
611
|
-
features: featurePermissions,
|
|
612
|
-
modules: moduleIds,
|
|
613
|
-
routes: routePermissions,
|
|
614
|
-
};
|
|
615
|
-
}
|
|
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
|
+
// }
|
|
616
608
|
async loadModulePermissions(userId, moduleId) {
|
|
617
609
|
if (!Number.isFinite(moduleId)) {
|
|
618
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);
|