Skip to content

Commit

Permalink
allow extra patch desc
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Sep 5, 2024
1 parent b88e394 commit 6a6cb38
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
8 changes: 5 additions & 3 deletions server/contrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class CreateSubjectPatch:
infobox: str
summary: str
reason: str
patch_desc: str
cf_turnstile_response: str
# HTML form will only include checkbox when it's checked,
# so any input is true, default value is false.
Expand All @@ -96,7 +97,7 @@ async def suggest_api(
if not data.reason:
raise ValidationException("missing suggestion description")

check_invalid_input_str(data.reason)
check_invalid_input_str(data.reason, data.patch_desc)

if not request.auth.allow_bypass_captcha():
await _validate_captcha(data.cf_turnstile_response)
Expand Down Expand Up @@ -133,8 +134,8 @@ async def suggest_api(
await pg.execute(
"""
insert into subject_patch (id, subject_id, from_user_id, reason, name, infobox, summary, nsfw,
original_name, original_infobox, original_summary, subject_type)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
original_name, original_infobox, original_summary, subject_type, patch_desc)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12. $13)
""",
pk,
subject_id,
Expand All @@ -148,6 +149,7 @@ async def suggest_api(
original.get("infobox"),
original.get("summary"),
original_wiki["typeID"],
data.patch_desc,
)

if "infobox" in changed:
Expand Down
13 changes: 9 additions & 4 deletions server/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,23 @@ async def run_migration() -> None:

refresh_view_sql = sql_dir.joinpath("004-deleted-view.sql").read_text(encoding="utf-8")

def load_sql(fn: str) -> str:
return sql_dir.joinpath("001-init.sql").read_text(encoding="utf8")

migrations: list[Migrate] = [
Migrate(1, sql_dir.joinpath("001-init.sql").read_text(encoding="utf8")),
Migrate(1, load_sql("001-init.sql")),
Migrate(4, refresh_view_sql),
Migrate(5, sql_dir.joinpath("005-edit-suggestion.sql").read_text(encoding="utf-8")),
Migrate(5, load_sql("005-edit-suggestion.sql")),
Migrate(
6,
"alter table episode_patch add column subject_id int not null default 0;",
),
Migrate(7, refresh_view_sql),
Migrate(8, sql_dir.joinpath("008-create-index.sql").read_bytes().decode()),
Migrate(9, sql_dir.joinpath("009-show-suggestion-count.sql").read_bytes().decode()),
Migrate(8, load_sql("008-create-index.sql")),
Migrate(9, load_sql("009-show-suggestion-count.sql")),
Migrate(10, refresh_view_sql),
Migrate(11, load_sql("010-extra-description.sql")),
Migrate(12, refresh_view_sql),
]

if not all(x <= y for x, y in itertools.pairwise(migrations)):
Expand Down
1 change: 1 addition & 0 deletions server/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class PatchBase:
updated_at: datetime
deleted_at: datetime | None
reject_reason: str
patch_desc: str # extra description from user will not be included in commit message

@classmethod
def from_dict(cls: type[T], d: Any) -> T:
Expand Down
2 changes: 2 additions & 0 deletions server/sql/010-extra-description.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table subject_patch add column patch_desc text not null default '';
alter table episode_patch add column patch_desc text not null default '';
12 changes: 12 additions & 0 deletions server/templates/patch.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@
</blockquote>
</div>

{% if patch.patch_desc %}
<div class="row mb-2">
<h2>说明</h2>
<blockquote class="blockquote" style="background-color: #f7f7f9">
<p class="mb-0"
style="overflow: visible; overflow-wrap: anywhere; white-space: pre-wrap">
{{- patch.patch_desc | auto_url -}}
</p>
</blockquote>
</div>
{% endif %}

<h2>具体变动</h2>

{% if name_patch %}
Expand Down

0 comments on commit 6a6cb38

Please sign in to comment.