diff --git a/src/authentication/permissions.enum.ts b/src/authentication/permissions.enum.ts index 4e23457..1e01531 100644 --- a/src/authentication/permissions.enum.ts +++ b/src/authentication/permissions.enum.ts @@ -611,7 +611,8 @@ export interface DadosferaModule { } export const DADOSFERA_MODULES_KEYS = { - LOG_DASHBOARD: 'logs-dashboard' + LOG_DASHBOARD: 'logs-dashboard', + ACCESS_DASHBOARD: 'access-dashboard' } export const DADOSFERA_MODULES: Array = [ diff --git a/src/modules/customers/customers.controller.ts b/src/modules/customers/customers.controller.ts index c4980d0..280dce3 100644 --- a/src/modules/customers/customers.controller.ts +++ b/src/modules/customers/customers.controller.ts @@ -108,4 +108,20 @@ export class CustomersController { const result = await this.customersService.getLogsDashboardUrl(metadata); return result; } + + @Get('access-dashboard') + @Authenticated() + @RequireAllPermissions( + PERMISSIONS_GROUPS.USERS.permissions.ADMIN, + ) + @RequireModule(DADOSFERA_MODULES_KEYS.ACCESS_DASHBOARD) + async getAccessDashboard( + @User() user: RequestUser, + ): Promise<{ url: string }> { + this.logger.info('getAccessDashboard'); + const metadata = PackTheMetadata(user); + + const result = await this.customersService.getAccessDashboardUrl(user.customer_name, metadata); + return result; + } } diff --git a/src/modules/customers/customers.service.ts b/src/modules/customers/customers.service.ts index 36df7c3..ed302fd 100644 --- a/src/modules/customers/customers.service.ts +++ b/src/modules/customers/customers.service.ts @@ -5,6 +5,7 @@ import { HttpException, HttpStatus, InternalServerErrorException, + ForbiddenException, } from '@nestjs/common'; import { firstValueFrom, lastValueFrom } from 'rxjs'; @@ -173,4 +174,33 @@ export class CustomersService implements OnModuleInit { return res; } + + async getAccessDashboardUrl(customerName: string, metadata: Metadata) { + /* + * TODO(Refactor): dar um jeito de exibir o dash da sbm diferente dos outros customer + * pois o signicado de department para sbm significa as instituições do usuários + */ + if (customerName !== 'sbmoffshorecom') { + throw new ForbiddenException(); + } + logger.info('CustomersService - getAccessDashboardUrl'); + + const res = await this.getDashboardUrl('105', metadata); + logger.info('Done'); + + return res; + } + + private async getDashboardUrl(dashboardId: string, metadata: Metadata) { + return await lastValueFrom( + this.pipelineReadService.PipelineV2GetDashboardUrl( + { + dashboard_id: dashboardId, + exp: '15m', + metabase_customer_name: 'dadosferatech', + }, + metadata + ) + ); + } }