-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* endpoint to change the role of a roommember * can not be used to change the role of the owner * can not be used to assign the owner role * add ROOM_MEMBERS_CHANGE_ROLE to room admin and owner
- Loading branch information
Showing
13 changed files
with
565 additions
and
12 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
apps/server/src/migrations/mikro-orm/Migration20250120131625.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* eslint-disable no-console */ | ||
/* eslint-disable filename-rules/match */ | ||
import { Migration } from '@mikro-orm/migrations-mongodb'; | ||
|
||
export class Migration20250120131625 extends Migration { | ||
public async up(): Promise<void> { | ||
const roomOwnerRoleUpdate = await this.getCollection('roles').updateOne( | ||
{ name: 'roomowner' }, | ||
{ | ||
$addToSet: { | ||
permissions: { | ||
$each: ['ROOM_MEMBERS_CHANGE_ROLE'], | ||
}, | ||
}, | ||
} | ||
); | ||
|
||
if (roomOwnerRoleUpdate.modifiedCount > 0) { | ||
console.info('Permissions ROOM_MEMBERS_CHANGE_ROLE added to role roomowner.'); | ||
} | ||
|
||
const roomAdminRoleUpdate = await this.getCollection('roles').updateOne( | ||
{ name: 'roomadmin' }, | ||
{ | ||
$addToSet: { | ||
permissions: { | ||
$each: ['ROOM_MEMBERS_CHANGE_ROLE'], | ||
}, | ||
}, | ||
} | ||
); | ||
|
||
if (roomAdminRoleUpdate.modifiedCount > 0) { | ||
console.info('Permissions ROOM_MEMBERS_CHANGE_ROLE added to role roomadmin.'); | ||
} | ||
} | ||
|
||
public async down(): Promise<void> { | ||
const roomOwnerRoleUpdate = await this.getCollection('roles').updateOne( | ||
{ name: 'roomowner' }, | ||
{ | ||
$pull: { | ||
permissions: { | ||
$in: ['ROOM_MEMBERS_CHANGE_ROLE'], | ||
}, | ||
}, | ||
} | ||
); | ||
|
||
if (roomOwnerRoleUpdate.modifiedCount > 0) { | ||
console.info('Rollback: Permission ROOM_CREATE removed from role roomowner.'); | ||
} | ||
|
||
const roomAdminRoleUpdate = await this.getCollection('roles').updateOne( | ||
{ name: 'roomadmin' }, | ||
{ | ||
$pull: { | ||
permissions: { | ||
$in: ['ROOM_MEMBERS_CHANGE_ROLE'], | ||
}, | ||
}, | ||
} | ||
); | ||
|
||
if (roomAdminRoleUpdate.modifiedCount > 0) { | ||
console.info('Rollback: Permission ROOM_DELETE removed from role roomadmin.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
apps/server/src/modules/room/api/dto/request/change-room-role.body.params.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { RoleName, RoomRole } from '@shared/domain/interface'; | ||
import { IsArray, IsEnum, IsMongoId } from 'class-validator'; | ||
|
||
export type AssignableRoomRole = Exclude<RoomRole, RoleName.ROOMOWNER>; | ||
export enum AssignableRoomRoleEnum { | ||
ROOMADMIN = RoleName.ROOMADMIN, | ||
ROOMEDITOR = RoleName.ROOMEDITOR, | ||
ROOMVIEWER = RoleName.ROOMVIEWER, | ||
} | ||
|
||
export class ChangeRoomRoleBodyParams { | ||
@ApiProperty({ | ||
description: 'The IDs of the users', | ||
required: true, | ||
}) | ||
@IsArray() | ||
@IsMongoId({ each: true }) | ||
public userIds!: string[]; | ||
|
||
@ApiProperty({ | ||
description: 'The role to assign to the users. Must be a Room Role role other than ROOMOWNER.', | ||
required: true, | ||
enum: AssignableRoomRoleEnum, | ||
}) | ||
@IsEnum(AssignableRoomRoleEnum) | ||
public roleName!: AssignableRoomRole; | ||
} |
24 changes: 24 additions & 0 deletions
24
apps/server/src/modules/room/api/loggables/cant-change-roomowners-role.error.loggable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { BadRequestException } from '@nestjs/common'; | ||
import { ErrorLogMessage } from '@shared/common/error'; | ||
import { Loggable } from '@shared/common/loggable'; | ||
|
||
export class CantChangeOwnersRoleLoggableException extends BadRequestException implements Loggable { | ||
constructor(private readonly currentUserId: string, private readonly roomId: string) { | ||
super(); | ||
} | ||
|
||
public getLogMessage(): ErrorLogMessage { | ||
const message: ErrorLogMessage = { | ||
type: 'CANT_CHANGE_OWNERS_ROLE', | ||
stack: this.stack, | ||
data: { | ||
currentUserId: this.currentUserId, | ||
roomId: this.roomId, | ||
errorMessage: | ||
'You cannot change the role of the room owner. If you want to change the owner, please transfer the ownership to another user instead.', | ||
}, | ||
}; | ||
|
||
return message; | ||
} | ||
} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.