fix and update

This commit is contained in:
lendry
2026-07-01 19:19:27 +03:00
parent f423f512f8
commit 7e54cec361
16 changed files with 1093 additions and 150 deletions

View File

@@ -251,7 +251,7 @@ export class MediaService {
}
async getChatMediaAccessUrl(requesterId: string, roomId: string, storageKey: string, fileName?: string) {
await this.assertChatMember(roomId, requesterId);
await this.assertChatMemberOrModerator(roomId, requesterId);
if (!storageKey.startsWith(`chat/${roomId}/`)) {
throw new BadRequestException('Некорректный ключ медиафайла');
}
@@ -379,6 +379,27 @@ export class MediaService {
}
}
private async assertChatMemberOrModerator(roomId: string, userId: string) {
const member = await this.prisma.chatRoomMember.findFirst({ where: { roomId, userId } });
if (member) {
return;
}
const user = await this.prisma.user.findUnique({ where: { id: userId } });
if (!user) {
throw new ForbiddenException('Нет доступа к чату');
}
const access = await this.access.getUserAccess(userId, user.isSuperAdmin);
if (!access.canModerateChats) {
throw new ForbiddenException('Нет доступа к чату');
}
const room = await this.prisma.chatRoom.findUnique({ where: { id: roomId } });
if (!room || room.isE2E || room.type === 'E2E' || room.type === 'BOT') {
throw new ForbiddenException('Этот чат недоступен для модерации');
}
}
private async publishUserAvatarUpdated(userId: string) {
const memberships = await this.prisma.familyMember.findMany({
where: { userId },