feat: add DCB User Service API - Authentication system with KEYCLOAK - Modular architecture with services for each feature
This commit is contained in:
parent
cbdfdfa297
commit
403baaa0ef
@ -154,6 +154,23 @@ export class HubUsersService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifie si un utilisateur est Hub Admin ou Support
|
||||
*/
|
||||
async isUserMerchantPartner(userId: string): Promise<boolean> {
|
||||
try {
|
||||
const userRoles = await this.keycloakApi.getUserClientRoles(userId);
|
||||
const hubMerchantPartnerRoles = [UserRole.DCB_PARTNER];
|
||||
|
||||
return userRoles.some(role =>
|
||||
hubMerchantPartnerRoles.includes(role.name as UserRole)
|
||||
);
|
||||
} catch (error) {
|
||||
this.logger.error(`Error checking Merchant Partner status for user ${userId}:`, error);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Récupère les utilisateurs marchands selon les permissions de l'utilisateur
|
||||
* - Hub Admin/Support: tous les utilisateurs marchands de tous les merchants
|
||||
@ -170,7 +187,7 @@ export class HubUsersService {
|
||||
}
|
||||
|
||||
// Pour les autres utilisateurs (DCB_PARTNER, DCB_PARTNER_ADMIN, etc.)
|
||||
return await this.getMerchantUsersForRegularUser(userId);
|
||||
return await this.getUsersForMerchants(userId);
|
||||
|
||||
} catch (error) {
|
||||
this.logger.error(`Error in getMyMerchantUsers for user ${userId}:`, error);
|
||||
@ -221,21 +238,29 @@ export class HubUsersService {
|
||||
/**
|
||||
* Récupère les utilisateurs marchands pour les utilisateurs réguliers (non Hub Admin/Support)
|
||||
*/
|
||||
private async getMerchantUsersForRegularUser(userId: string): Promise<User[]> {
|
||||
private async getUsersForMerchants(userId: string): Promise<User[]> {
|
||||
// Récupérer le merchantPartnerId de l'utilisateur
|
||||
const userMerchantId = await this.getUserMerchantPartnerId(userId);
|
||||
|
||||
let userMerchantId = await this.getUserMerchantPartnerId(userId);
|
||||
|
||||
// Vérifier si l'utilisateur est un admin ou support Hub
|
||||
const isUserMerchantPartner = await this.isUserMerchantPartner(userId);
|
||||
|
||||
if(isUserMerchantPartner){
|
||||
userMerchantId = userId;
|
||||
}
|
||||
|
||||
if (!userMerchantId) {
|
||||
throw new BadRequestException('Current user is not associated with a merchant partner');
|
||||
}
|
||||
|
||||
this.logger.log(`User ${userId} accessing merchant users for partner ${userMerchantId}`);
|
||||
|
||||
|
||||
// Utiliser la méthode existante pour récupérer les utilisateurs du merchant spécifique
|
||||
const users = await this.getMerchantUsersByPartner(userMerchantId, userId);
|
||||
|
||||
this.logger.log(`User ${userId} retrieved ${users.length} merchant users for partner ${userMerchantId}`);
|
||||
return users;
|
||||
|
||||
}
|
||||
|
||||
async getMerchantUsersByPartner(merchantPartnerId: string, requesterId: string): Promise<User[]> {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user