Verified Commit 37f0c352 authored by Kevin Morris's avatar Kevin Morris
Browse files

feat(FastAPI): add /pkgbase/{name}/flag-comment (get)


Signed-off-by: Kevin Morris's avatarKevin Morris <kevr@0cost.org>
parent 210d92e3
......@@ -812,6 +812,19 @@ async def pkgbase_flag_post(request: Request, name: str,
status_code=HTTPStatus.SEE_OTHER)
@router.get("/pkgbase/{name}/flag-comment")
async def pkgbase_flag_comment(request: Request, name: str):
pkgbase = get_pkg_or_base(name, models.PackageBase)
if pkgbase.Flagger is None:
return RedirectResponse(f"/pkgbase/{name}",
status_code=HTTPStatus.SEE_OTHER)
context = make_context(request, "Flag Comment")
context["pkgbase"] = pkgbase
return render_template(request, "packages/flag-comment.html", context)
@router.post("/pkgbase/{name}/unflag")
@auth_required(True, redirect="/pkgbase/{name}")
async def pkgbase_unflag(request: Request, name: str):
......
{% extends "partials/layout.html" %}
{% block pageContent %}
<div class="box">
<h2>{{ "Flagged Out-of-Date Comment: %s" | tr | format(pkgbase.Name) }}</h2>
{# Prepare wrapping for the username. #}
{% set wrap = ["", ""] %}
{% if request.user.is_authenticated() %}
{# When logged in, we wrap it with a link to the account. #}
{% set wrap = ['<a href="/account/%s">' | format(pkgbase.Flagger.Username), "</a>"] %}
{% endif %}
{# Prepare OutOfDateTS as a datetime object in the request user's timezone. #}
{% set flagged_at = pkgbase.OutOfDateTS | dt | as_timezone(timezone) %}
{% set username = "%s%s%s" | format(wrap[0], pkgbase.Flagger.Username, wrap[1]) %}
<p>
{{
"%s%s%s flagged %s%s%s out-of-date on %s%s%s for the "
"following reason:"
| tr | format("<strong>", username, "</strong>",
"<strong>", pkgbase.Name, "</strong>",
"<strong>", flagged_at.strftime("%Y-%m-%d"), "</strong>")
| safe
}}
</p>
{# Padding #}
<p></p>
<div class="article-content">
<blockquote>
<p>{{ pkgbase.FlaggerComment }}</p>
</blockquote>
</div>
<form action="/pkgbase/{{ pkgbase.Name }}">
<input type="submit" value="{{ 'Return to Details' | tr }}" />
</form>
{# Padding #}
<p></p>
</div>
{% endblock %}
......@@ -33,11 +33,13 @@
{% else %}
<li>
<span class="flagged">
{% set ood_ts = pkgbase.OutOfDateTS | dt | as_timezone(timezone) %}
{{
"Flagged out-of-date (%s)"
| tr | format(ood_ts.strftime("%Y-%m-%d"))
}}
<a href="/pkgbase/{{ pkgbase.Name }}/flag-comment">
{% set ood_ts = pkgbase.OutOfDateTS | dt | as_timezone(timezone) %}
{{
"Flagged out-of-date (%s)"
| tr | format(ood_ts.strftime("%Y-%m-%d"))
}}
</a>
</span>
</li>
<li>
......
......@@ -1707,6 +1707,14 @@ def test_pkgbase_flag(client: TestClient, user: User, maintainer: User,
resp = request.get(endpoint, cookies=cookies)
assert resp.status_code == int(HTTPStatus.OK)
# Now, let's check the /pkgbase/{name}/flag-comment route.
flag_comment_endpoint = f"/pkgbase/{pkgbase.Name}/flag-comment"
with client as request:
resp = request.get(flag_comment_endpoint, cookies=cookies,
allow_redirects=False)
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
assert resp.headers.get("location") == f"/pkgbase/{pkgbase.Name}"
# Try to flag it without a comment.
with client as request:
resp = request.post(endpoint, cookies=cookies)
......@@ -1721,6 +1729,13 @@ def test_pkgbase_flag(client: TestClient, user: User, maintainer: User,
assert pkgbase.Flagger == user
assert pkgbase.FlaggerComment == "Test"
# Now, let's check the /pkgbase/{name}/flag-comment route.
flag_comment_endpoint = f"/pkgbase/{pkgbase.Name}/flag-comment"
with client as request:
resp = request.get(flag_comment_endpoint, cookies=cookies,
allow_redirects=False)
assert resp.status_code == int(HTTPStatus.OK)
# Now try to perform a get; we should be redirected because
# it's already flagged.
with client as request:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment