326 lines
9.5 KiB
TypeScript
326 lines
9.5 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
|
|
export enum UserRole {
|
|
// Rôles Hub
|
|
DCB_ADMIN = 'dcb-admin',
|
|
DCB_SUPPORT = 'dcb-support',
|
|
|
|
// Rôles Merchant User
|
|
// Rôles Partenaires (Business)
|
|
DCB_PARTNER_ADMIN = 'dcb-partner-admin',
|
|
DCB_PARTNER_MANAGER = 'dcb-partner-manager',
|
|
DCB_PARTNER_SUPPORT = 'dcb-partner-support',
|
|
|
|
// Rôles Configuration Marchands (Technique)
|
|
MERCHANT_CONFIG_ADMIN = 'ADMIN',
|
|
MERCHANT_CONFIG_MANAGER = 'MANAGER',
|
|
MERCHANT_CONFIG_TECHNICAL = 'TECHNICAL',
|
|
MERCHANT_CONFIG_VIEWER = 'VIEWER',
|
|
}
|
|
|
|
type RoleCategory = 'hub' | 'partner' | 'config';
|
|
|
|
interface RoleConfig {
|
|
label: string;
|
|
description: string;
|
|
badgeClass: string;
|
|
icon: string;
|
|
}
|
|
|
|
// Configuration des rôles
|
|
const ROLE_CONFIG: Record<UserRole, RoleConfig> = {
|
|
[UserRole.DCB_ADMIN]: {
|
|
label: 'Administrateur DCB',
|
|
description: 'Administrateur système avec tous les accès',
|
|
badgeClass: 'bg-danger',
|
|
icon: 'lucideShield'
|
|
},
|
|
[UserRole.DCB_SUPPORT]: {
|
|
label: 'Support DCB',
|
|
description: 'Support technique avec accès étendus',
|
|
badgeClass: 'bg-info',
|
|
icon: 'lucideHeadphones'
|
|
},
|
|
[UserRole.DCB_PARTNER_ADMIN]: {
|
|
label: 'Admin Partenaire',
|
|
description: 'Administrateur de partenaire marchand',
|
|
badgeClass: 'bg-warning',
|
|
icon: 'lucideShieldCheck'
|
|
},
|
|
[UserRole.DCB_PARTNER_MANAGER]: {
|
|
label: 'Manager Partenaire',
|
|
description: 'Manager opérationnel partenaire',
|
|
badgeClass: 'bg-success',
|
|
icon: 'lucideUserCog'
|
|
},
|
|
[UserRole.DCB_PARTNER_SUPPORT]: {
|
|
label: 'Support Partenaire',
|
|
description: 'Support technique partenaire',
|
|
badgeClass: 'bg-secondary',
|
|
icon: 'lucideHeadphones'
|
|
},
|
|
[UserRole.MERCHANT_CONFIG_ADMIN]: {
|
|
label: 'Admin Marchand',
|
|
description: 'Administrateur de configuration marchand',
|
|
badgeClass: 'bg-warning',
|
|
icon: 'lucideSettings'
|
|
},
|
|
[UserRole.MERCHANT_CONFIG_MANAGER]: {
|
|
label: 'Manager Marchand',
|
|
description: 'Manager de configuration marchand',
|
|
badgeClass: 'bg-success',
|
|
icon: 'lucideUserCog'
|
|
},
|
|
[UserRole.MERCHANT_CONFIG_TECHNICAL]: {
|
|
label: 'Technique Marchand',
|
|
description: 'Support technique configuration marchand',
|
|
badgeClass: 'bg-secondary',
|
|
icon: 'lucideWrench'
|
|
},
|
|
[UserRole.MERCHANT_CONFIG_VIEWER]: {
|
|
label: 'Visualiseur Marchand',
|
|
description: 'Visualiseur de configuration marchand',
|
|
badgeClass: 'bg-light',
|
|
icon: 'lucideEye'
|
|
}
|
|
} as const;
|
|
|
|
// Rôles Hub (pour les filtres)
|
|
const HUB_ROLES = [
|
|
UserRole.DCB_ADMIN,
|
|
UserRole.DCB_SUPPORT,
|
|
] as const;
|
|
|
|
// Rôles Marchands (pour les filtres)
|
|
const MERCHANT_ROLES = [
|
|
UserRole.DCB_PARTNER_ADMIN,
|
|
UserRole.DCB_PARTNER_MANAGER,
|
|
UserRole.DCB_PARTNER_SUPPORT,
|
|
UserRole.MERCHANT_CONFIG_ADMIN,
|
|
UserRole.MERCHANT_CONFIG_MANAGER,
|
|
UserRole.MERCHANT_CONFIG_TECHNICAL,
|
|
UserRole.MERCHANT_CONFIG_VIEWER
|
|
] as const;
|
|
|
|
@Injectable({ providedIn: 'root' })
|
|
export class RoleManagementService {
|
|
private currentRole: UserRole | null = null;
|
|
|
|
// Mapping des rôles équivalents
|
|
private readonly roleEquivalents = new Map<UserRole, UserRole[]>([
|
|
[UserRole.DCB_PARTNER_ADMIN, [UserRole.MERCHANT_CONFIG_ADMIN]],
|
|
[UserRole.DCB_PARTNER_MANAGER, [UserRole.MERCHANT_CONFIG_MANAGER]],
|
|
[UserRole.DCB_PARTNER_SUPPORT, [UserRole.MERCHANT_CONFIG_TECHNICAL, UserRole.MERCHANT_CONFIG_VIEWER]],
|
|
[UserRole.MERCHANT_CONFIG_ADMIN, [UserRole.DCB_PARTNER_ADMIN]],
|
|
[UserRole.MERCHANT_CONFIG_MANAGER, [UserRole.DCB_PARTNER_MANAGER]],
|
|
[UserRole.MERCHANT_CONFIG_TECHNICAL, [UserRole.DCB_PARTNER_SUPPORT]],
|
|
[UserRole.MERCHANT_CONFIG_VIEWER, [UserRole.DCB_PARTNER_SUPPORT]]
|
|
]);
|
|
|
|
// Catégories des rôles
|
|
private readonly roleCategories: Record<UserRole, RoleCategory> = {
|
|
[UserRole.DCB_ADMIN]: 'hub',
|
|
[UserRole.DCB_SUPPORT]: 'hub',
|
|
[UserRole.DCB_PARTNER_ADMIN]: 'partner',
|
|
[UserRole.DCB_PARTNER_MANAGER]: 'partner',
|
|
[UserRole.DCB_PARTNER_SUPPORT]: 'partner',
|
|
[UserRole.MERCHANT_CONFIG_ADMIN]: 'config',
|
|
[UserRole.MERCHANT_CONFIG_MANAGER]: 'config',
|
|
[UserRole.MERCHANT_CONFIG_TECHNICAL]: 'config',
|
|
[UserRole.MERCHANT_CONFIG_VIEWER]: 'config'
|
|
};
|
|
|
|
// Labels des rôles
|
|
private readonly roleLabels: Record<UserRole, string> = {
|
|
[UserRole.DCB_ADMIN]: 'Administrateur DCB',
|
|
[UserRole.DCB_SUPPORT]: 'Support DCB',
|
|
[UserRole.DCB_PARTNER_ADMIN]: 'Admin Partenaire',
|
|
[UserRole.DCB_PARTNER_MANAGER]: 'Manager Partenaire',
|
|
[UserRole.DCB_PARTNER_SUPPORT]: 'Support Partenaire',
|
|
[UserRole.MERCHANT_CONFIG_ADMIN]: 'Admin Configuration',
|
|
[UserRole.MERCHANT_CONFIG_MANAGER]: 'Manager Configuration',
|
|
[UserRole.MERCHANT_CONFIG_TECHNICAL]: 'Technique Configuration',
|
|
[UserRole.MERCHANT_CONFIG_VIEWER]: 'Visualiseur Configuration'
|
|
};
|
|
|
|
// Icônes des rôles
|
|
private readonly roleIcons: Record<UserRole, string> = {
|
|
[UserRole.DCB_ADMIN]: 'lucideShield',
|
|
[UserRole.DCB_SUPPORT]: 'lucideHeadphones',
|
|
[UserRole.DCB_PARTNER_ADMIN]: 'lucideShieldCheck',
|
|
[UserRole.DCB_PARTNER_MANAGER]: 'lucideUserCog',
|
|
[UserRole.DCB_PARTNER_SUPPORT]: 'user-headset',
|
|
[UserRole.MERCHANT_CONFIG_ADMIN]: 'lucideSettings',
|
|
[UserRole.MERCHANT_CONFIG_MANAGER]: 'lucideSliders',
|
|
[UserRole.MERCHANT_CONFIG_TECHNICAL]: 'lucideWrench',
|
|
[UserRole.MERCHANT_CONFIG_VIEWER]: 'lucideEye'
|
|
};
|
|
|
|
// === GESTION DU RÔLE COURANT ===
|
|
setCurrentRole(role: UserRole | null): void {
|
|
this.currentRole = role;
|
|
}
|
|
|
|
getCurrentRole(): UserRole | null {
|
|
return this.currentRole;
|
|
}
|
|
|
|
// === VÉRIFICATIONS DE RÔLES INDIVIDUELS ===
|
|
|
|
isAdmin(): boolean {
|
|
return this.currentRole === UserRole.DCB_ADMIN;
|
|
}
|
|
|
|
isSupport(): boolean {
|
|
return this.currentRole === UserRole.DCB_SUPPORT;
|
|
}
|
|
|
|
isPartnerAdmin(): boolean {
|
|
return this.currentRole === UserRole.DCB_PARTNER_ADMIN;
|
|
}
|
|
|
|
isPartnerManager(): boolean {
|
|
return this.currentRole === UserRole.DCB_PARTNER_MANAGER;
|
|
}
|
|
|
|
isPartnerSupport(): boolean {
|
|
return this.currentRole === UserRole.DCB_PARTNER_SUPPORT;
|
|
}
|
|
|
|
isConfigAdmin(): boolean {
|
|
return this.currentRole === UserRole.MERCHANT_CONFIG_ADMIN;
|
|
}
|
|
|
|
isConfigManager(): boolean {
|
|
return this.currentRole === UserRole.MERCHANT_CONFIG_MANAGER;
|
|
}
|
|
|
|
isConfigTechnical(): boolean {
|
|
return this.currentRole === UserRole.MERCHANT_CONFIG_TECHNICAL;
|
|
}
|
|
|
|
isConfigViewer(): boolean {
|
|
return this.currentRole === UserRole.MERCHANT_CONFIG_VIEWER;
|
|
}
|
|
|
|
// === VÉRIFICATIONS AVEC MAPPING ===
|
|
|
|
isAnyAdmin(): boolean {
|
|
return this.isAdmin() || this.isPartnerAdmin() || this.isConfigAdmin();
|
|
}
|
|
|
|
isAnyManager(): boolean {
|
|
return this.isPartnerManager() || this.isConfigManager();
|
|
}
|
|
|
|
isAnySupport(): boolean {
|
|
return this.isSupport() || this.isPartnerSupport() || this.isConfigTechnical() || this.isConfigViewer();
|
|
}
|
|
|
|
// === VÉRIFICATIONS DE CATÉGORIES ===
|
|
|
|
isHubUser(): boolean {
|
|
return this.isAdmin() || this.isSupport();
|
|
}
|
|
|
|
isPartnerUser(): boolean {
|
|
return this.isPartnerAdmin() || this.isPartnerManager() || this.isPartnerSupport();
|
|
}
|
|
|
|
isConfigUser(): boolean {
|
|
return this.isConfigAdmin() || this.isConfigManager() || this.isConfigTechnical() || this.isConfigViewer();
|
|
}
|
|
|
|
getRoleCategory(): RoleCategory | null {
|
|
if (!this.currentRole) return null;
|
|
return this.roleCategories[this.currentRole];
|
|
}
|
|
|
|
// === MAPPING ET ÉQUIVALENTS ===
|
|
|
|
getEquivalentRoles(): UserRole[] {
|
|
if (!this.currentRole) return [];
|
|
|
|
const equivalents = [this.currentRole];
|
|
const mappedRoles = this.roleEquivalents.get(this.currentRole);
|
|
|
|
if (mappedRoles) {
|
|
equivalents.push(...mappedRoles);
|
|
}
|
|
|
|
return [...new Set(equivalents)];
|
|
}
|
|
|
|
hasEquivalentRole(targetRole: UserRole): boolean {
|
|
if (!this.currentRole) return false;
|
|
|
|
if (this.currentRole === targetRole) return true;
|
|
|
|
const equivalents = this.roleEquivalents.get(this.currentRole);
|
|
return equivalents ? equivalents.includes(targetRole) : false;
|
|
}
|
|
|
|
getMappedRole(): UserRole | null {
|
|
if (!this.currentRole) return null;
|
|
|
|
const equivalents = this.roleEquivalents.get(this.currentRole);
|
|
return equivalents && equivalents.length > 0 ? equivalents[0] : this.currentRole;
|
|
}
|
|
|
|
// === VÉRIFICATIONS GÉNÉRIQUES ===
|
|
|
|
hasRole(role: UserRole): boolean {
|
|
return this.currentRole === role;
|
|
}
|
|
|
|
hasAnyRole(...roles: UserRole[]): boolean {
|
|
if (!this.currentRole) return false;
|
|
return roles.includes(this.currentRole);
|
|
}
|
|
|
|
// === UTILITAIRES ===
|
|
|
|
/**
|
|
* Méthodes d'utilité pour les rôles
|
|
*/
|
|
getRoleLabel(role: string): string {
|
|
const userRole = role as UserRole;
|
|
return ROLE_CONFIG[userRole]?.label || role;
|
|
}
|
|
|
|
getRoleDescription(role: string | UserRole): string {
|
|
const userRole = role as UserRole;
|
|
return ROLE_CONFIG[userRole]?.description || 'Description non disponible';
|
|
}
|
|
|
|
getRoleBadgeClass(role: string): string {
|
|
const userRole = role as UserRole;
|
|
return ROLE_CONFIG[userRole]?.badgeClass || 'bg-secondary';
|
|
}
|
|
|
|
getRoleIcon(role: string): string {
|
|
const userRole = role as UserRole;
|
|
return ROLE_CONFIG[userRole]?.icon || 'lucideUser';
|
|
}
|
|
|
|
getAllRoles(): UserRole[] {
|
|
return Object.values(UserRole);
|
|
}
|
|
|
|
getHubRoles(): UserRole[] {
|
|
return [UserRole.DCB_ADMIN, UserRole.DCB_SUPPORT];
|
|
}
|
|
|
|
getPartnerRoles(): UserRole[] {
|
|
return [UserRole.DCB_PARTNER_ADMIN, UserRole.DCB_PARTNER_MANAGER, UserRole.DCB_PARTNER_SUPPORT];
|
|
}
|
|
|
|
getConfigRoles(): UserRole[] {
|
|
return [
|
|
UserRole.MERCHANT_CONFIG_ADMIN,
|
|
UserRole.MERCHANT_CONFIG_MANAGER,
|
|
UserRole.MERCHANT_CONFIG_TECHNICAL,
|
|
UserRole.MERCHANT_CONFIG_VIEWER
|
|
];
|
|
}
|
|
} |