feat: Add connection validation before sending messages and extend support chat admin access to include SUPER_ADMIN role.
This commit is contained in:
@@ -191,6 +191,17 @@ export class MessagesService {
|
|||||||
throw new ForbiddenException('You are not part of this conversation');
|
throw new ForbiddenException('You are not part of this conversation');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify connection is still active before allowing message
|
||||||
|
const canMessage = await this.validateCanMessage(
|
||||||
|
conversation.userId,
|
||||||
|
conversation.agentProfileId,
|
||||||
|
);
|
||||||
|
if (!canMessage) {
|
||||||
|
throw new ForbiddenException(
|
||||||
|
'You can only message users with accepted connection requests',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Create the message
|
// Create the message
|
||||||
const message = await this.prisma.message.create({
|
const message = await this.prisma.message.create({
|
||||||
data: {
|
data: {
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ export class SupportChatController {
|
|||||||
@Query('limit') limit?: string,
|
@Query('limit') limit?: string,
|
||||||
) {
|
) {
|
||||||
// Validate access
|
// Validate access
|
||||||
const isAdmin = role === UserRole.ADMIN;
|
const isAdmin = role === UserRole.ADMIN || role === UserRole.SUPER_ADMIN;
|
||||||
await this.supportChatService.getChat(chatId, userId, isAdmin);
|
await this.supportChatService.getChat(chatId, userId, isAdmin);
|
||||||
|
|
||||||
return this.supportChatService.getMessages(
|
return this.supportChatService.getMessages(
|
||||||
@@ -98,10 +98,10 @@ export class SupportChatController {
|
|||||||
@Body() dto: SendSupportMessageDto,
|
@Body() dto: SendSupportMessageDto,
|
||||||
) {
|
) {
|
||||||
// Validate access
|
// Validate access
|
||||||
const isAdmin = role === UserRole.ADMIN;
|
const isAdmin = role === UserRole.ADMIN || role === UserRole.SUPER_ADMIN;
|
||||||
await this.supportChatService.getChat(chatId, userId, isAdmin);
|
await this.supportChatService.getChat(chatId, userId, isAdmin);
|
||||||
|
|
||||||
const senderRole = role === UserRole.ADMIN ? 'ADMIN' : 'USER';
|
const senderRole = (role === UserRole.ADMIN || role === UserRole.SUPER_ADMIN) ? 'ADMIN' : 'USER';
|
||||||
const message = await this.supportChatService.sendMessage(chatId, userId, senderRole, dto.content);
|
const message = await this.supportChatService.sendMessage(chatId, userId, senderRole, dto.content);
|
||||||
|
|
||||||
// Emit WebSocket events for real-time updates
|
// Emit WebSocket events for real-time updates
|
||||||
@@ -136,7 +136,7 @@ export class SupportChatController {
|
|||||||
const result = await this.supportChatService.markAsRead(chatId, role);
|
const result = await this.supportChatService.markAsRead(chatId, role);
|
||||||
|
|
||||||
// If admin marked as read, update sidebar badge for all admins
|
// If admin marked as read, update sidebar badge for all admins
|
||||||
if (role === UserRole.ADMIN) {
|
if (role === UserRole.ADMIN || role === UserRole.SUPER_ADMIN) {
|
||||||
const unreadTotal = await this.supportChatService.getAdminUnreadTotal();
|
const unreadTotal = await this.supportChatService.getAdminUnreadTotal();
|
||||||
this.messagesGateway.server.to('admin_room').emit('support_unread_update', { unreadTotal });
|
this.messagesGateway.server.to('admin_room').emit('support_unread_update', { unreadTotal });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user