mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix(FastAPI): add /pkgbase/{name}/flag (get)
This was missed in the [un]flag (post) commit. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
305d077973
commit
5bbc94f2ef
3 changed files with 103 additions and 2 deletions
|
@ -773,17 +773,42 @@ async def requests_close_post(request: Request, id: int,
|
||||||
return RedirectResponse("/requests", status_code=int(HTTPStatus.SEE_OTHER))
|
return RedirectResponse("/requests", status_code=int(HTTPStatus.SEE_OTHER))
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/pkgbase/{name}/flag")
|
||||||
|
@auth_required(True, redirect="/pkgbase/{name}")
|
||||||
|
async def pkgbase_flag_get(request: Request, name: str):
|
||||||
|
pkgbase = get_pkg_or_base(name, PackageBase)
|
||||||
|
|
||||||
|
has_cred = request.user.has_credential("CRED_PKGBASE_FLAG")
|
||||||
|
if not has_cred or pkgbase.Flagger is not None:
|
||||||
|
return RedirectResponse(f"/pkgbase/{name}",
|
||||||
|
status_code=int(HTTPStatus.SEE_OTHER))
|
||||||
|
|
||||||
|
context = make_context(request, "Flag Package Out-Of-Date")
|
||||||
|
context["pkgbase"] = pkgbase
|
||||||
|
return render_template(request, "packages/flag.html", context)
|
||||||
|
|
||||||
|
|
||||||
@router.post("/pkgbase/{name}/flag")
|
@router.post("/pkgbase/{name}/flag")
|
||||||
@auth_required(True, redirect="/pkgbase/{name}")
|
@auth_required(True, redirect="/pkgbase/{name}")
|
||||||
async def pkgbase_flag(request: Request, name: str):
|
async def pkgbase_flag_post(request: Request, name: str,
|
||||||
|
comments: str = Form(default=str())):
|
||||||
pkgbase = get_pkg_or_base(name, PackageBase)
|
pkgbase = get_pkg_or_base(name, PackageBase)
|
||||||
|
|
||||||
|
if not comments:
|
||||||
|
context = make_context(request, "Flag Package Out-Of-Date")
|
||||||
|
context["pkgbase"] = pkgbase
|
||||||
|
context["errors"] = ["The selected packages have not been flagged, "
|
||||||
|
"please enter a comment."]
|
||||||
|
return render_template(request, "packages/flag.html", context,
|
||||||
|
status_code=int(HTTPStatus.BAD_REQUEST))
|
||||||
|
|
||||||
has_cred = request.user.has_credential("CRED_PKGBASE_FLAG")
|
has_cred = request.user.has_credential("CRED_PKGBASE_FLAG")
|
||||||
if has_cred and not pkgbase.Flagger:
|
if has_cred and not pkgbase.Flagger:
|
||||||
now = int(datetime.utcnow().timestamp())
|
now = int(datetime.utcnow().timestamp())
|
||||||
with db.begin():
|
with db.begin():
|
||||||
pkgbase.OutOfDateTS = now
|
pkgbase.OutOfDateTS = now
|
||||||
pkgbase.Flagger = request.user
|
pkgbase.Flagger = request.user
|
||||||
|
pkgbase.FlaggerComment = comments
|
||||||
|
|
||||||
return RedirectResponse(f"/pkgbase/{name}",
|
return RedirectResponse(f"/pkgbase/{name}",
|
||||||
status_code=int(HTTPStatus.SEE_OTHER))
|
status_code=int(HTTPStatus.SEE_OTHER))
|
||||||
|
@ -800,6 +825,7 @@ async def pkgbase_unflag(request: Request, name: str):
|
||||||
with db.begin():
|
with db.begin():
|
||||||
pkgbase.OutOfDateTS = None
|
pkgbase.OutOfDateTS = None
|
||||||
pkgbase.Flagger = None
|
pkgbase.Flagger = None
|
||||||
|
pkgbase.FlaggerComment = str()
|
||||||
|
|
||||||
return RedirectResponse(f"/pkgbase/{name}",
|
return RedirectResponse(f"/pkgbase/{name}",
|
||||||
status_code=int(HTTPStatus.SEE_OTHER))
|
status_code=int(HTTPStatus.SEE_OTHER))
|
||||||
|
|
57
templates/packages/flag.html
Normal file
57
templates/packages/flag.html
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
{% extends "partials/layout.html" %}
|
||||||
|
|
||||||
|
{% block pageContent %}
|
||||||
|
<div class="box">
|
||||||
|
<h2>{{ "Flag Package Out-Of-Date" | tr }}: {{ pkgbase.Name }}</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
{{
|
||||||
|
"Use this form to flag the package base %s%s%s and "
|
||||||
|
"the following packages out-of-date: "
|
||||||
|
| tr | format("<strong>", pkgbase.Name, "</strong>") | safe
|
||||||
|
}}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
{% for package in pkgbase.packages.all() %}
|
||||||
|
<li>{{ package.Name }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
{{
|
||||||
|
"Please do %snot%s use this form to report bugs. "
|
||||||
|
"Use the package comments instead."
|
||||||
|
| tr | format("<strong>", "</strong>") | safe
|
||||||
|
}}
|
||||||
|
{{
|
||||||
|
"Enter details on why the package is out-of-date below, "
|
||||||
|
"preferably including links to the release announcement "
|
||||||
|
"or the new release tarball." | tr
|
||||||
|
}}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
{% if errors %}
|
||||||
|
<ul class="errorlist">
|
||||||
|
{% for error in errors %}
|
||||||
|
<li>{{ error | tr }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<form action="/pkgbase/{{ pkgbase.Name }}/flag" method="post">
|
||||||
|
<fieldset>
|
||||||
|
<p>
|
||||||
|
<label for="id_comments">{{ "Comments" | tr }}:</label>
|
||||||
|
<textarea id="id_comments"
|
||||||
|
name="comments"
|
||||||
|
rows="5"
|
||||||
|
cols="50"></textarea>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<input class="button" type="submit" value="{{ 'Flag' | tr }}" />
|
||||||
|
</p>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -1698,13 +1698,31 @@ def test_pkgbase_flag(client: TestClient, user: User, maintainer: User,
|
||||||
# We shouldn't have flagged the package yet; assert so.
|
# We shouldn't have flagged the package yet; assert so.
|
||||||
assert pkgbase.Flagger is None
|
assert pkgbase.Flagger is None
|
||||||
|
|
||||||
# Flag it.
|
|
||||||
cookies = {"AURSID": user.login(Request(), "testPassword")}
|
cookies = {"AURSID": user.login(Request(), "testPassword")}
|
||||||
endpoint = f"/pkgbase/{pkgbase.Name}/flag"
|
endpoint = f"/pkgbase/{pkgbase.Name}/flag"
|
||||||
|
|
||||||
|
# Get the flag page.
|
||||||
|
with client as request:
|
||||||
|
resp = request.get(endpoint, cookies=cookies)
|
||||||
|
assert resp.status_code == int(HTTPStatus.OK)
|
||||||
|
|
||||||
|
# Try to flag it without a comment.
|
||||||
with client as request:
|
with client as request:
|
||||||
resp = request.post(endpoint, cookies=cookies)
|
resp = request.post(endpoint, cookies=cookies)
|
||||||
|
assert resp.status_code == int(HTTPStatus.BAD_REQUEST)
|
||||||
|
|
||||||
|
# Flag it with a valid comment.
|
||||||
|
with client as request:
|
||||||
|
resp = request.post(endpoint, {"comments": "Test"}, cookies=cookies)
|
||||||
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
|
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
|
||||||
assert pkgbase.Flagger == user
|
assert pkgbase.Flagger == user
|
||||||
|
assert pkgbase.FlaggerComment == "Test"
|
||||||
|
|
||||||
|
# Now try to perform a get; we should be redirected because
|
||||||
|
# it's already flagged.
|
||||||
|
with client as request:
|
||||||
|
resp = request.get(endpoint, cookies=cookies, allow_redirects=False)
|
||||||
|
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
|
||||||
|
|
||||||
# Now, test that the 'maintainer' user can't unflag it, because they
|
# Now, test that the 'maintainer' user can't unflag it, because they
|
||||||
# didn't flag it to begin with.
|
# didn't flag it to begin with.
|
||||||
|
|
Loading…
Add table
Reference in a new issue