forked from mtusi2026/mtusi2026lab4
исправила замечания
This commit is contained in:
+3
-3
@@ -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-вложение")
|
||||
|
||||
Reference in New Issue
Block a user