diff --git a/backend/api/v1/requests_app/views.py b/backend/api/v1/requests_app/views.py index 21fc4ba6..c30e7928 100644 --- a/backend/api/v1/requests_app/views.py +++ b/backend/api/v1/requests_app/views.py @@ -514,7 +514,7 @@ class RequestViewSet(viewsets.ModelViewSet): req_obj = self.get_object() # Получаем чат для этой заявки - chat = comments_helpers.get_or_create_comments_chat(req_obj)[0] + chat = comments_helpers.get_or_create_comments_chat(req_obj) # Находим комментарий try: diff --git a/backend/tests/api/v1/requests_app/test_requests_api.py b/backend/tests/api/v1/requests_app/test_requests_api.py index 32213290..88f67ce2 100644 --- a/backend/tests/api/v1/requests_app/test_requests_api.py +++ b/backend/tests/api/v1/requests_app/test_requests_api.py @@ -386,6 +386,32 @@ def test_comments_allowed_for_admin_and_manager( assert post_r.status_code == 201, "Получатель должен уметь создавать комментарий" +def test_comment_author_can_delete_own_comment( + auth_client, + regular_user: models.Model, + make_request, +) -> None: + """Автор комментария может удалить свой комментарий без 500.""" + req = make_request(employee=regular_user) + client = auth_client(regular_user) + + post_resp = client.post( + f"{API_BASE}{req.id}/comments/", + data={"text": "удаляемый комментарий"}, + format="json", + ) + assert post_resp.status_code == 201 + comment_id = post_resp.json()["id"] + + delete_resp = client.delete(f"{API_BASE}{req.id}/comments/{comment_id}/") + assert delete_resp.status_code == 204 + + list_resp = client.get(f"{API_BASE}{req.id}/comments/") + assert list_resp.status_code == 200 + ids = {item["id"] for item in _results(list_resp.json())} + assert comment_id not in ids + + # ------------------------------------------------------------------------------ # 8) ФИЛЬТРЫ # ------------------------------------------------------------------------------ @@ -434,4 +460,4 @@ def test_invalid_filter_does_not_crash(auth_client, admin_user: models.Model) -> """Странные значения фильтров не приводят к 500.""" client = auth_client(admin_user) resp = client.get(f"{API_BASE}?type=__sql__' OR 1=1 --&status=") - assert resp.status_code == 200 \ No newline at end of file + assert resp.status_code == 200 diff --git a/frontend/src/app/requests/page.tsx b/frontend/src/app/requests/page.tsx index f509b606..0ca80bf6 100644 --- a/frontend/src/app/requests/page.tsx +++ b/frontend/src/app/requests/page.tsx @@ -235,7 +235,7 @@ function RequestsPageContent() { const summary = item.comment || item.description; return ( -
+
@@ -271,7 +271,7 @@ function RequestsPageContent() {
{(rowOpen || commentsOpen) && ( -
+
{rowOpen && (
diff --git a/frontend/src/hooks/useRequestsPage.ts b/frontend/src/hooks/useRequestsPage.ts index 53ba593c..698c5217 100644 --- a/frontend/src/hooks/useRequestsPage.ts +++ b/frontend/src/hooks/useRequestsPage.ts @@ -320,6 +320,9 @@ export function useRequestsPage(_userId: number | null | undefined) { }; const handleDelete = async (id: number) => { + if (!window.confirm("Удалить заявление? Это действие нельзя отменить.")) { + return; + } try { setBusyKey(`delete-${id}`); setActionError(null); await apiClient.deleteRequest(id); setRequests((p) => p.filter((r) => r.id !== id)); } catch (e: unknown) { setActionError(String((e as Error)?.message || "Не удалось удалить")); } finally { setBusyKey(null); }