@@ -6,7 +6,11 @@ import { syncRoomRolePriorityForUserAndRoom } from './syncRoomRolePriority';
66import { validateRoleList } from './validateRoleList' ;
77import { notifyOnSubscriptionChangedByRoomIdAndUserId } from '../../../app/lib/server/lib/notifyListener' ;
88
9- export const removeUserFromRolesAsync = async ( userId : IUser [ '_id' ] , roles : IRole [ '_id' ] [ ] , scope ?: IRoom [ '_id' ] ) : Promise < boolean > => {
9+ export const removeUserFromRolesAsync = async (
10+ userId : IUser [ '_id' ] ,
11+ roles : IRole [ '_id' ] [ ] | IRole [ 'name' ] [ ] ,
12+ scope ?: IRoom [ '_id' ] ,
13+ ) : Promise < boolean > => {
1014 if ( ! userId || ! roles ) {
1115 return false ;
1216 }
@@ -25,19 +29,19 @@ export const removeUserFromRolesAsync = async (userId: IUser['_id'], roles: IRol
2529 }
2630
2731 for await ( const roleId of roles ) {
28- const role = await Roles . findOneById < Pick < IRole , '_id' | 'scope' > > ( roleId , { projection : { scope : 1 } } ) ;
32+ const role = await Roles . findOneByIdOrName < Pick < IRole , '_id' | 'scope' > > ( roleId , { projection : { scope : 1 } } ) ;
2933 if ( ! role ) {
3034 continue ;
3135 }
3236
3337 if ( role . scope === 'Subscriptions' && scope ) {
34- const removeRolesResponse = await Subscriptions . removeRolesByUserId ( userId , [ roleId ] , scope ) ;
38+ const removeRolesResponse = await Subscriptions . removeRolesByUserId ( userId , [ role . _id ] , scope ) ;
3539 await syncRoomRolePriorityForUserAndRoom ( userId , scope ) ;
3640 if ( removeRolesResponse . modifiedCount ) {
3741 void notifyOnSubscriptionChangedByRoomIdAndUserId ( scope , userId ) ;
3842 }
3943 } else {
40- await Users . removeRolesByUserId ( userId , [ roleId ] ) ;
44+ await Users . removeRolesByUserId ( userId , [ role . _id ] ) ;
4145 }
4246 }
4347
0 commit comments