diff --git a/server/contrib.py b/server/contrib.py index b520cdc..3d2e588 100644 --- a/server/contrib.py +++ b/server/contrib.py @@ -30,8 +30,9 @@ subject_infobox_queue, ) from server.config import TURNSTILE_SECRET_KEY, UTC +from server.db import new_edit_suggestion from server.errors import BadRequestException -from server.model import PatchAction, PatchState, SubjectPatch, SubjectType +from server.model import PatchAction, PatchState, PatchType, SubjectPatch, SubjectType from server.router import Router from server.strings import check_invalid_input_str, contains_invalid_input_str @@ -409,6 +410,10 @@ async def _( patch_id, ) + await new_edit_suggestion( + conn, patch_id, PatchType.Subject, text="提交者进行了修改", from_user=0 + ) + return Redirect(f"/subject/{patch_id}") diff --git a/server/db.py b/server/db.py index 8e03bce..6821e9a 100644 --- a/server/db.py +++ b/server/db.py @@ -1,6 +1,13 @@ +from __future__ import annotations + +from typing import Any +from uuid import UUID + import asyncpg +from asyncpg.pool import PoolConnectionProxy from server.base import pg +from server.model import PatchType async def fetch_users(rows: list[asyncpg.Record]) -> dict[int, asyncpg.Record]: @@ -14,3 +21,22 @@ async def fetch_users(rows: list[asyncpg.Record]) -> dict[int, asyncpg.Record]: } return users + + +async def new_edit_suggestion( + conn: asyncpg.Connection[Any] | PoolConnectionProxy[Any] | asyncpg.Pool[Any], + patch_id: UUID, + type: PatchType, + text: str, + from_user: int, +) -> None: + await conn.execute( + """ + insert into edit_suggestion (id, patch_id, patch_type, text, from_user) + VALUES (uuid_generate_v7(), $1, $2, $3, $4) + """, + patch_id, + type, + text, + from_user, + ) diff --git a/server/patch.py b/server/patch.py index d619340..c736c29 100644 --- a/server/patch.py +++ b/server/patch.py @@ -69,7 +69,7 @@ async def get_patch(patch_id: UUID, request: Request) -> Template: suggestions = await pg.fetch( """ select * from edit_suggestion - inner join patch_users on patch_users.user_id = edit_suggestion.from_user + left join patch_users on patch_users.user_id = edit_suggestion.from_user where deleted_at IS NULL AND patch_id = $1 AND patch_type = $2 diff --git a/server/templates/patch.html.jinja2 b/server/templates/patch.html.jinja2 index 75dd561..079a782 100644 --- a/server/templates/patch.html.jinja2 +++ b/server/templates/patch.html.jinja2 @@ -65,18 +65,27 @@ {% if suggestions %}
- {{- s.text | auto_url -}} -
-+ {{- s.text | auto_url -}} +
+