1- import { Room , ServiceClass , Settings } from '@rocket.chat/core-services' ;
1+ import { api , Room , ServiceClass , Settings } from '@rocket.chat/core-services' ;
22import type { AbacActor , IAbacService } from '@rocket.chat/core-services' ;
33import { AbacAccessOperation , AbacObjectType } from '@rocket.chat/core-typings' ;
44import type {
@@ -428,13 +428,18 @@ export class AbacService extends ServiceClass implements IAbacService {
428428 return Rooms . isAbacAttributeInUse ( key , attribute . values || [ ] ) ;
429429 }
430430
431+ private broadcastRoomUpdate ( room : IRoom ) : void {
432+ void api . broadcast ( 'watch.rooms' , { clientAction : 'updated' , room } ) ;
433+ }
434+
431435 async setRoomAbacAttributes ( rid : string , attributes : Record < string , string [ ] > , actor : AbacActor ) : Promise < void > {
432436 await this . ensurePdpAvailable ( ) ;
433437 const room = await getAbacRoom ( rid ) ;
434438
435439 if ( ! Object . keys ( attributes ) . length && room . abacAttributes ?. length ) {
436440 await Rooms . unsetAbacAttributesById ( rid ) ;
437441 void Audit . objectAttributesRemoved ( { _id : room . _id , name : room . name } , room . abacAttributes , actor ) ;
442+ this . broadcastRoomUpdate ( { ...room , abacAttributes : undefined } ) ;
438443 return ;
439444 }
440445
@@ -445,6 +450,10 @@ export class AbacService extends ServiceClass implements IAbacService {
445450 const updated = await Rooms . setAbacAttributesById ( rid , normalized ) ;
446451 void Audit . objectAttributeChanged ( { _id : room . _id , name : room . name } , room . abacAttributes || [ ] , normalized , 'updated' , actor ) ;
447452
453+ if ( updated ) {
454+ this . broadcastRoomUpdate ( updated ) ;
455+ }
456+
448457 const previous : IAbacAttributeDefinition [ ] = room . abacAttributes || [ ] ;
449458 if ( diffAttributeSets ( previous , normalized ) . added ) {
450459 await this . onRoomAttributesChanged ( room , updated ?. abacAttributes ?? normalized ) ;
@@ -476,6 +485,8 @@ export class AbacService extends ServiceClass implements IAbacService {
476485 ) ;
477486 const next = [ ...previous , { key, values } ] ;
478487
488+ this . broadcastRoomUpdate ( { ...room , abacAttributes : next } ) ;
489+
479490 await this . onRoomAttributesChanged ( room , next ) ;
480491 return ;
481492 }
@@ -486,7 +497,7 @@ export class AbacService extends ServiceClass implements IAbacService {
486497 return ;
487498 }
488499
489- await Rooms . updateAbacAttributeValuesArrayFilteredById ( rid , key , values ) ;
500+ const updated = await Rooms . updateAbacAttributeValuesArrayFilteredById ( rid , key , values ) ;
490501 void Audit . objectAttributeChanged (
491502 { _id : room . _id , name : room . name } ,
492503 room . abacAttributes || [ ] ,
@@ -495,6 +506,10 @@ export class AbacService extends ServiceClass implements IAbacService {
495506 actor ,
496507 ) ;
497508
509+ if ( updated ) {
510+ this . broadcastRoomUpdate ( updated ) ;
511+ }
512+
498513 if ( diffAttributeSets ( [ previous [ existingIndex ] ] , [ { key, values } ] ) . added ) {
499514 const next = previous . map ( ( a , i ) => ( i === existingIndex ? { key, values } : a ) ) ;
500515 await this . onRoomAttributesChanged ( room , next ) ;
@@ -516,17 +531,16 @@ export class AbacService extends ServiceClass implements IAbacService {
516531 await Rooms . unsetAbacAttributesById ( rid ) ;
517532 void Audit . objectAttributesRemoved ( { _id : room . _id } , previous , actor ) ;
518533
534+ this . broadcastRoomUpdate ( { ...room , abacAttributes : undefined } ) ;
535+
519536 return ;
520537 }
521538
522539 await Rooms . removeAbacAttributeByRoomIdAndKey ( rid , key ) ;
523- void Audit . objectAttributeRemoved (
524- { _id : room . _id , name : room . name } ,
525- previous ,
526- previous . filter ( ( a ) => a . key !== key ) ,
527- 'key-removed' ,
528- actor ,
529- ) ;
540+ const next = previous . filter ( ( a ) => a . key !== key ) ;
541+ void Audit . objectAttributeRemoved ( { _id : room . _id , name : room . name } , previous , next , 'key-removed' , actor ) ;
542+
543+ this . broadcastRoomUpdate ( { ...room , abacAttributes : next } ) ;
530544 }
531545
532546 async addRoomAbacAttributeByKey ( rid : string , key : string , values : string [ ] , actor : AbacActor ) : Promise < void > {
@@ -549,6 +563,8 @@ export class AbacService extends ServiceClass implements IAbacService {
549563
550564 void Audit . objectAttributeChanged ( { _id : room . _id , name : room . name } , previous , next , 'key-added' , actor ) ;
551565
566+ this . broadcastRoomUpdate ( { ...room , abacAttributes : next } ) ;
567+
552568 await this . onRoomAttributesChanged ( room , next ) ;
553569 }
554570
@@ -570,6 +586,11 @@ export class AbacService extends ServiceClass implements IAbacService {
570586 'key-updated' ,
571587 actor ,
572588 ) ;
589+
590+ if ( updated ) {
591+ this . broadcastRoomUpdate ( updated ) ;
592+ }
593+
573594 if ( diffAttributeSets ( [ exists ] , [ { key, values } ] ) . added ) {
574595 await this . onRoomAttributesChanged ( room , updated ?. abacAttributes || [ ] ) ;
575596 }
@@ -582,13 +603,10 @@ export class AbacService extends ServiceClass implements IAbacService {
582603 }
583604
584605 const updated = await Rooms . insertAbacAttributeIfNotExistsById ( rid , key , values ) ;
585- void Audit . objectAttributeChanged (
586- { _id : room . _id , name : room . name } ,
587- room . abacAttributes || [ ] ,
588- updated ?. abacAttributes || [ ] ,
589- 'key-added' ,
590- actor ,
591- ) ;
606+ const nextAttributes = updated ?. abacAttributes || [ ...( room . abacAttributes || [ ] ) , { key, values } ] ;
607+ void Audit . objectAttributeChanged ( { _id : room . _id , name : room . name } , room . abacAttributes || [ ] , nextAttributes , 'key-added' , actor ) ;
608+
609+ this . broadcastRoomUpdate ( { ...room , abacAttributes : nextAttributes } ) ;
592610
593611 await this . onRoomAttributesChanged ( room , updated ?. abacAttributes || [ ] ) ;
594612 }
0 commit comments