Skip to content

Commit

Permalink
fix: show all patches of user
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Aug 20, 2024
1 parent 89bceb7 commit f5397aa
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
13 changes: 12 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ types-tqdm = "^4.66.0.20240417"
types-python-dateutil = "^2.9.0.20240316"
types-regex = "^2024.7.24.20240726"
asyncpg-stubs = "^0.29.1"
types-pyyaml = "^6.0.12.20240808"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
12 changes: 11 additions & 1 deletion server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
UTC,
)
from server import tmpl
from server.auth import callback, login, session_auth_config
from server.auth import callback, login, require_user_login, session_auth_config
from server.base import Request, pg, pg_pool_startup
from server.contrib import delete_patch, suggest_api, suggest_ui
from server.model import Patch, PatchState
Expand Down Expand Up @@ -96,6 +96,15 @@ async def index(request: Request) -> Template:
)


@litestar.get("/user/{user_id:int}", guards=[require_user_login])
async def show_user(user_id: int, request: Request) -> Template:
rows = await pg.fetch(
"select * from patch where from_user_id = $1 and deleted_at is NULL order by created_at desc",
user_id,
)
return Template("index.html.jinja2", context={"rows": rows, "auth": request.auth})


def __index_row_sorter(r: asyncpg.Record) -> tuple[int, datetime]:
if r["state"] == PatchState.Pending:
return 1, r["created_at"]
Expand Down Expand Up @@ -187,6 +196,7 @@ def internal_error_handler(_: Request, exc: Exception) -> Response[Any]:
app = litestar.Litestar(
[
index,
show_user,
login,
callback,
suggest_ui,
Expand Down
5 changes: 5 additions & 0 deletions server/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ async def callback(code: str, request: Request) -> Redirect:
return Redirect(back_to)


def require_user_login(connection: ASGIConnection[Any, Any, Any, Any], _: Any) -> None:
if not connection.auth:
raise NotAuthorizedException


def require_user_editor(connection: ASGIConnection[Any, Any, Any, Any], _: Any) -> None:
if not connection.auth:
raise NotAuthorizedException
Expand Down
4 changes: 0 additions & 4 deletions server/templates/index.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
{% endif %}
</div>


<div>
<p class="oneline-hide-overflow m-0 p-0">
修改原因:{{ patch.description }}
Expand All @@ -73,9 +72,6 @@
</p>
</div>

<small>subject:
<span class="badge bg-light text-dark"> {{ patch.subject_id }}</span>
</small>
<small>from:
<span class="badge bg-light text-dark">{{ patch.from_user_id }}</span>
</small>
Expand Down
2 changes: 1 addition & 1 deletion server/templates/patch.html.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</a>
</div>
<div class="col">
<a href="https://bgm.tv/user/{{ patch.from_user_id }}" target="_blank"
<a href="/user/{{ patch.from_user_id }}" target="_blank"
rel="noopener">
<h3>提交者: {{ patch.from_user_id }}</h3>
</a>
Expand Down

0 comments on commit f5397aa

Please sign in to comment.