Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/shared/auth/role.guard.ts

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add [UserRole.MONITORING]: [UserRole.ADMIN, UserRole.SUPER_ADMIN], to additionalRoles -> can remove admin on dashboard controller endpoints

Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,16 @@ class RoleGuardClass implements CanActivate {
[UserRole.CLIENT_COMPANY]: [UserRole.KYC_CLIENT_COMPANY],
};

constructor(private readonly entryRole: UserRole) {}
constructor(private readonly entryRoles: UserRole[]) {}

canActivate(context: ExecutionContext): boolean {
const userRole = context.switchToHttp().getRequest().user?.role;
return this.entryRole === userRole || this.additionalRoles[this.entryRole]?.includes(userRole);
return this.entryRoles.some(
(entryRole) => entryRole === userRole || this.additionalRoles[entryRole]?.includes(userRole),
);
}
}

export function RoleGuard(entryRole: UserRole): RoleGuardClass {
return new RoleGuardClass(entryRole);
export function RoleGuard(...entryRoles: UserRole[]): RoleGuardClass {
return new RoleGuardClass(entryRoles);
}
1 change: 1 addition & 0 deletions src/shared/auth/user-role.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum UserRole {
CUSTODY = 'Custody',
REALUNIT = 'RealUnit',
MARKETING = 'Marketing',
MONITORING = 'Monitoring',
DEBUG = 'Debug',

// service roles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class DashboardFinancialController {
@Get('log')
@ApiBearerAuth()
@ApiExcludeEndpoint()
@UseGuards(AuthGuard(), RoleGuard(UserRole.ADMIN), UserActiveGuard())
@UseGuards(AuthGuard(), RoleGuard(UserRole.ADMIN, UserRole.COMPLIANCE, UserRole.MONITORING), UserActiveGuard())
async getFinancialLog(
@Query('from') from?: string,
@Query('dailySample') dailySample?: string,
Expand All @@ -35,7 +35,7 @@ export class DashboardFinancialController {
@Get('latest')
@ApiBearerAuth()
@ApiExcludeEndpoint()
@UseGuards(AuthGuard(), RoleGuard(UserRole.ADMIN), UserActiveGuard())
@UseGuards(AuthGuard(), RoleGuard(UserRole.ADMIN, UserRole.COMPLIANCE, UserRole.MONITORING), UserActiveGuard())
async getLatestBalance(): Promise<LatestBalanceResponseDto> {
const result = await this.dashboardFinancialService.getLatestBalance();
if (!result) throw new NotFoundException('No financial data available');
Expand All @@ -45,7 +45,7 @@ export class DashboardFinancialController {
@Get('changes/latest')
@ApiBearerAuth()
@ApiExcludeEndpoint()
@UseGuards(AuthGuard(), RoleGuard(UserRole.ADMIN), UserActiveGuard())
@UseGuards(AuthGuard(), RoleGuard(UserRole.ADMIN, UserRole.COMPLIANCE, UserRole.MONITORING), UserActiveGuard())
async getLatestChanges(): Promise<FinancialChangesEntryDto> {
const result = await this.dashboardFinancialService.getLatestFinancialChanges();
if (!result) throw new NotFoundException('No financial changes available');
Expand All @@ -55,15 +55,15 @@ export class DashboardFinancialController {
@Get('ref-recipients')
@ApiBearerAuth()
@ApiExcludeEndpoint()
@UseGuards(AuthGuard(), RoleGuard(UserRole.ADMIN), UserActiveGuard())
@UseGuards(AuthGuard(), RoleGuard(UserRole.ADMIN, UserRole.COMPLIANCE, UserRole.MONITORING), UserActiveGuard())
async getRefRewardRecipients(@Query('from') from?: string): Promise<RefRewardRecipientDto[]> {
return this.dashboardFinancialService.getRefRewardRecipients(this.parseDate(from));
}

@Get('changes')
@ApiBearerAuth()
@ApiExcludeEndpoint()
@UseGuards(AuthGuard(), RoleGuard(UserRole.ADMIN), UserActiveGuard())
@UseGuards(AuthGuard(), RoleGuard(UserRole.ADMIN, UserRole.COMPLIANCE, UserRole.MONITORING), UserActiveGuard())
async getFinancialChanges(
@Query('from') from?: string,
@Query('dailySample') dailySample?: string,
Expand Down