added is admin

This commit is contained in:
simplonco
2023-01-15 16:26:53 +01:00
parent ffdc3839b9
commit 83c07451f9
7 changed files with 86 additions and 26 deletions

View File

@@ -32,6 +32,7 @@ export class ChatController {
new_room.users = room.users;
if (room.allowed)
new_room.allowed = room.allowed;
return new_room;
}
@@ -84,6 +85,40 @@ export class ChatController {
printCaller("- out ");
}
@UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard)
@Get('isadmin')
async isAdmin(@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);
res.status(HttpStatus.OK).json({ is_admin: is_admin });
printCaller("- out ");
}
/*
@UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard)
@Get('isadmin')
async isAdmin(@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);
res.status(HttpStatus.OK).json({ is_admin: is_admin });
printCaller("- out ");
}
*/
@UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard)
@Get('current')

View File

@@ -432,6 +432,8 @@ export class ChatService {
printCaller("-- in ");
let room_name = await this.getCurrentRoomName(socket.username);
/*
const current_room = await this.getRoomByName(room_name);
if (current_room.protection)
@@ -442,6 +444,7 @@ export class ChatService {
return;
}
}
*/
socket.to(socket.room).emit('message', socket.username, message);
await this.addMessageToRoom(room_name, socket.username, message);