@@ -2,6 +2,8 @@ import { Inject, Injectable, NotFoundException, Scope } from '@nestjs/common';
22import AbstractUseCase from '../../../../common/abstract-use.case.js' ;
33import { IGlobalDatabaseContext } from '../../../../common/application/global-database-context.interface.js' ;
44import { BaseType } from '../../../../common/data-injection.tokens.js' ;
5+ import { CedarAction } from '../../../cedar-authorization/cedar-action-map.js' ;
6+ import { CedarAuthorizationService } from '../../../cedar-authorization/cedar-authorization.service.js' ;
57import { Messages } from '../../../../exceptions/text/messages.js' ;
68import { FindAllDashboardsDs } from '../data-structures/find-all-dashboards.ds.js' ;
79import { FoundDashboardDto } from '../dto/found-dashboard.dto.js' ;
@@ -16,12 +18,13 @@ export class FindAllDashboardsUseCase
1618 constructor (
1719 @Inject ( BaseType . GLOBAL_DB_CONTEXT )
1820 protected _dbContext : IGlobalDatabaseContext ,
21+ private readonly cedarAuthService : CedarAuthorizationService ,
1922 ) {
2023 super ( ) ;
2124 }
2225
2326 public async implementation ( inputData : FindAllDashboardsDs ) : Promise < FoundDashboardDto [ ] > {
24- const { connectionId, masterPassword } = inputData ;
27+ const { connectionId, masterPassword, userId } = inputData ;
2528
2629 const foundConnection = await this . _dbContext . connectionRepository . findAndDecryptConnection (
2730 connectionId ,
@@ -35,6 +38,17 @@ export class FindAllDashboardsUseCase
3538 const dashboards =
3639 await this . _dbContext . dashboardRepository . findAllDashboardsWithWidgetsByConnectionId ( connectionId ) ;
3740
38- return dashboards . map ( buildFoundDashboardDto ) ;
41+ const accessChecks = await Promise . all (
42+ dashboards . map ( ( dashboard ) =>
43+ this . cedarAuthService . validate ( {
44+ userId,
45+ action : CedarAction . DashboardRead ,
46+ connectionId,
47+ dashboardId : dashboard . id ,
48+ } ) ,
49+ ) ,
50+ ) ;
51+
52+ return dashboards . filter ( ( _ , index ) => accessChecks [ index ] ) . map ( buildFoundDashboardDto ) ;
3953 }
4054}
0 commit comments