исправила замечания

This commit is contained in:
2026-10-31 11:02:37 +03:00
parent e135f1c5d4
commit e3d441c629
6 changed files with 127 additions and 77 deletions
+3 -3
View File
@@ -2,8 +2,8 @@
import uuid
from . import cursor, security
from .errors import bad_request
from .sessions import fmt_ts
from .errors import bad_request, not_found
def username_exists(conn, username):
@@ -90,14 +90,14 @@ def insert_message(conn, chat_id, sender_id, text, attachment_ids=None):
"""Создаёт сообщение и связывает вложения в одной транзакции."""
attachment_ids = attachment_ids or []
if attachment_ids:
# Все вложения должны принадлежать этому чату и быть ready.
rows = conn.execute(
"""SELECT id, status FROM attachments
WHERE id = ANY(%s) AND chat_id = %s""",
(attachment_ids, chat_id)).fetchall()
by_id = {r["id"]: r for r in rows}
if len(by_id) != len(attachment_ids):
raise bad_request("Неизвестное вложение")
# Чужое или неизвестное вложение — 404 (не раскрывать существование).
raise not_found()
for att_id in attachment_ids:
if by_id[att_id]["status"] == "failed":
raise bad_request("Нельзя прикрепить failed-вложение")