diff --git a/schema.sql b/schema.sql index c464e50..9cc4789 100644 --- a/schema.sql +++ b/schema.sql @@ -1,3 +1,8 @@ +create table if not exists patch_scheme_rev +( + version text primary key +); + create table if not exists patch ( id uuid PRIMARY KEY DEFAULT gen_random_uuid(), @@ -26,3 +31,6 @@ create table if not exists patch create index idx_subject_id on patch (subject_id); create index idx_deleted_at on patch (deleted_at); + +alter table patch + add column reject_reason varchar(255) not null default ''; diff --git a/server/model.py b/server/model.py index 05269db..1cc9302 100644 --- a/server/model.py +++ b/server/model.py @@ -54,6 +54,7 @@ class Patch: created_at: datetime updated_at: datetime deleted_at: datetime | None + reject_reason: str @dataclass(frozen=True, slots=True, kw_only=True) diff --git a/server/review.py b/server/review.py index 62b4a8c..ae62986 100644 --- a/server/review.py +++ b/server/review.py @@ -30,6 +30,7 @@ class React(str, enum.Enum): @dataclass class ReviewPatch: react: React + reject_reason: str = "" def __strip_none(d: dict[str, Any]) -> dict[str, Any]: @@ -56,7 +57,7 @@ async def review_patch( raise BadRequestException("patch already reviewed") if data.react == React.Reject: - return await __reject_patch(patch, conn, request.auth) + return await __reject_patch(patch, conn, request.auth, data.reject_reason) if data.react == React.Accept: return await __accept_patch(patch, conn, request.auth) @@ -64,19 +65,23 @@ async def review_patch( raise NotAuthorizedException("暂不支持") -async def __reject_patch(patch: Patch, conn: PoolConnectionProxy[Record], auth: User) -> Redirect: +async def __reject_patch( + patch: Patch, conn: PoolConnectionProxy[Record], auth: User, reason: str +) -> Redirect: await conn.execute( """ update patch set state = $1, wiki_user_id = $2, - updated_at = $3 + updated_at = $3, + reject_reason = $4 where id = $4 and deleted_at is NULL """, PatchState.Rejected, auth.user_id, datetime.now(tz=UTC), patch.id, + reason, ) return Redirect("/") diff --git a/server/templates/patch.html.jinja2 b/server/templates/patch.html.jinja2 index 8dc5bac..8ba9d2e 100644 --- a/server/templates/patch.html.jinja2 +++ b/server/templates/patch.html.jinja2 @@ -85,6 +85,9 @@ enctype="application/x-www-form-urlencoded"> {{ csrf_input | safe }} + @@ -107,8 +110,13 @@ {% elif patch.state == 2 %}
-

已被 {{ patch.wiki_user_id }} 拒绝

+ +

已被 {{ patch.wiki_user_id }} 拒绝

+ + {% if patch.reject_reason %} +

原因:{{ patch.reject_reason }}

+ {% endif %}
{% elif patch.state == 3 %}