make admin ok
This commit is contained in:
@@ -87,21 +87,18 @@ export class ChatController {
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Get('isadmin')
|
||||
async isAdmin(@Req() req, @Res() res): Promise<void>
|
||||
@Post('setadmin')
|
||||
async setAdmin(@Body('username') username: string, @Req() req, @Res() res): Promise<void>
|
||||
{
|
||||
printCaller("- in ");
|
||||
|
||||
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||
const fields = ["admins"];
|
||||
const room_db = await this.chatService.getRoomByName(room_name, fields);
|
||||
const is_admin = room_db.admins.includes(req.user.username);
|
||||
const current_room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
||||
await this.chatService.setAdmin(req.user.username, username, current_room_name);
|
||||
|
||||
res.status(HttpStatus.OK).json({ is_admin: is_admin });
|
||||
res.status(HttpStatus.OK).json({ message: `${username} is now admin in room ${current_room_name}` });
|
||||
printCaller("- out ");
|
||||
}
|
||||
|
||||
/*
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Get('isadmin')
|
||||
@@ -117,7 +114,6 @@ export class ChatController {
|
||||
res.status(HttpStatus.OK).json({ is_admin: is_admin });
|
||||
printCaller("- out ");
|
||||
}
|
||||
*/
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
|
||||
@@ -204,8 +204,9 @@ export class ChatService {
|
||||
}
|
||||
|
||||
room_db.allowed_users.push(username);
|
||||
printCaller("-- out ");
|
||||
await this.chatroomRepository.save(room_db);
|
||||
|
||||
printCaller("-- out ");
|
||||
}
|
||||
|
||||
async setPassword(username: string, message: string, room: roomDto, old_password?: string): Promise<void>
|
||||
@@ -274,6 +275,22 @@ export class ChatService {
|
||||
printCaller("-- out ");
|
||||
}
|
||||
|
||||
async setAdmin(current_username: string, user_username: string, room_name: string): Promise<void>
|
||||
{
|
||||
printCaller("-- in ");
|
||||
|
||||
const room_db = await this.getRoomByName(room_name);
|
||||
if (!room_db.admins.includes(current_username))
|
||||
{
|
||||
printCaller(`throw error: error: true, code: 'NOT_ADMIN', message: 'you cannot set someone else as admin, since you are not admin yourself'`);
|
||||
throw new HttpException({ error: true, code: 'NOT_ADMIN', message: `you cannot set someone else as admin, since you are not admin yourself` }, HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
||||
room_db.admins.push(user_username);
|
||||
await this.chatroomRepository.save(room_db);
|
||||
|
||||
printCaller("-- out ");
|
||||
}
|
||||
|
||||
/* ADDERS *************************************************
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user