Skip to content

Commit

Permalink
feat: add reject resson
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Aug 19, 2024
1 parent 4e0eac3 commit eac8045
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
8 changes: 8 additions & 0 deletions schema.sql
Original file line number Diff line number Diff line change
@@ -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(),
Expand Down Expand Up @@ -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 '';
1 change: 1 addition & 0 deletions server/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 8 additions & 3 deletions server/review.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -56,27 +57,31 @@ 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)

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("/")

Expand Down
12 changes: 10 additions & 2 deletions server/templates/patch.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@
enctype="application/x-www-form-urlencoded">
{{ csrf_input | safe }}
<input name="react" value="reject" hidden="hidden"/>
<label>拒绝原因
<input type="text" name="reject_reason"/>
</label>
<button type="submit" class="btn btn-secondary">Reject</button>
</form>
</div>
Expand All @@ -107,8 +110,13 @@
{% elif patch.state == 2 %}
<hr>
<div class="col">
<h2> 已被 {{ patch.wiki_user_id }} <span
class="badge bg-danger"> 拒绝 </span></h2>

<h3> 已被 {{ patch.wiki_user_id }} <span
class="badge bg-danger"> 拒绝 </span></h3>

{% if patch.reject_reason %}
<h4>原因:{{ patch.reject_reason }}</h4>
{% endif %}
</div>
{% elif patch.state == 3 %}
<hr>
Expand Down

0 comments on commit eac8045

Please sign in to comment.