@@ -24,6 +24,7 @@ import {
2424 AbacInvalidAttributeValuesError ,
2525 AbacUnsupportedObjectTypeError ,
2626 AbacUnsupportedOperationError ,
27+ PdpUnavailableError ,
2728} from './errors' ;
2829import {
2930 getAbacRoom ,
@@ -416,6 +417,7 @@ export class AbacService extends ServiceClass implements IAbacService {
416417 }
417418
418419 async setRoomAbacAttributes ( rid : string , attributes : Record < string , string [ ] > , actor : AbacActor ) : Promise < void > {
420+ await this . ensurePdpAvailable ( ) ;
419421 const room = await getAbacRoom ( rid ) ;
420422
421423 if ( ! Object . keys ( attributes ) . length && room . abacAttributes ?. length ) {
@@ -438,6 +440,7 @@ export class AbacService extends ServiceClass implements IAbacService {
438440 }
439441
440442 async updateRoomAbacAttributeValues ( rid : string , key : string , values : string [ ] , actor : AbacActor ) : Promise < void > {
443+ await this . ensurePdpAvailable ( ) ;
441444 const room = await getAbacRoom ( rid ) ;
442445
443446 const previous : IAbacAttributeDefinition [ ] = room . abacAttributes || [ ] ;
@@ -514,6 +517,7 @@ export class AbacService extends ServiceClass implements IAbacService {
514517 }
515518
516519 async addRoomAbacAttributeByKey ( rid : string , key : string , values : string [ ] , actor : AbacActor ) : Promise < void > {
520+ await this . ensurePdpAvailable ( ) ;
517521 await ensureAttributeDefinitionsExist ( [ { key, values } ] ) ;
518522
519523 const room = await getAbacRoom ( rid ) ;
@@ -536,6 +540,7 @@ export class AbacService extends ServiceClass implements IAbacService {
536540 }
537541
538542 async replaceRoomAbacAttributeByKey ( rid : string , key : string , values : string [ ] , actor : AbacActor ) : Promise < void > {
543+ await this . ensurePdpAvailable ( ) ;
539544 await ensureAttributeDefinitionsExist ( [ { key, values } ] ) ;
540545
541546 const room = await getAbacRoom ( rid ) ;
@@ -649,6 +654,12 @@ export class AbacService extends ServiceClass implements IAbacService {
649654
650655 private pdpType : 'local' | 'virtru' = 'local' ;
651656
657+ private async ensurePdpAvailable ( ) : Promise < void > {
658+ if ( ! ( await this . pdp ?. isAvailable ( ) ) ) {
659+ throw new PdpUnavailableError ( ) ;
660+ }
661+ }
662+
652663 private async removeUserFromRoom ( room : AtLeast < IRoom , '_id' > , user : IUser , reason : AbacAuditReason ) : Promise < void > {
653664 return Room . removeUserFromRoom ( room . _id , user , {
654665 skipAppPreEvents : true ,
0 commit comments