Verified Commit 3f95ac7d authored by Kevin Morris's avatar Kevin Morris
Browse files

fix: correct redirects for package actions & requests



For requests, we always pass a `next` of /requests, leading us
back to the requests page. For a standard package, we get redirected
to the involved pkgbase, or target pkgbase if a merge action was taken.
Signed-off-by: Kevin Morris's avatarKevin Morris <kevr@0cost.org>
parent c883c710
Pipeline #15742 passed with stages
in 4 minutes and 1 second
......@@ -510,7 +510,8 @@ async def pkgbase_unflag(request: Request, name: str):
@router.get("/pkgbase/{name}/disown")
@requires_auth
async def pkgbase_disown_get(request: Request, name: str):
async def pkgbase_disown_get(request: Request, name: str,
next: str = Query(default=str())):
pkgbase = get_pkg_or_base(name, PackageBase)
has_cred = request.user.has_credential(creds.PKGBASE_DISOWN,
......@@ -521,6 +522,7 @@ async def pkgbase_disown_get(request: Request, name: str):
context = templates.make_context(request, "Disown Package")
context["pkgbase"] = pkgbase
context["next"] = next or "/pkgbase/{name}"
return render_template(request, "pkgbase/disown.html", context)
......@@ -528,7 +530,8 @@ async def pkgbase_disown_get(request: Request, name: str):
@requires_auth
async def pkgbase_disown_post(request: Request, name: str,
comments: str = Form(default=str()),
confirm: bool = Form(default=False)):
confirm: bool = Form(default=False),
next: str = Form(default=str())):
pkgbase = get_pkg_or_base(name, PackageBase)
has_cred = request.user.has_credential(creds.PKGBASE_DISOWN,
......@@ -555,8 +558,10 @@ async def pkgbase_disown_post(request: Request, name: str,
return render_template(request, "pkgbase/disown.html", context,
status_code=HTTPStatus.BAD_REQUEST)
return RedirectResponse(f"/pkgbase/{name}",
status_code=HTTPStatus.SEE_OTHER)
if not next:
next = f"/pkgbase/{name}"
return RedirectResponse(next, status_code=HTTPStatus.SEE_OTHER)
@router.post("/pkgbase/{name}/adopt")
......@@ -645,10 +650,12 @@ async def pkgbase_comaintainers_post(request: Request, name: str,
@router.get("/pkgbase/{name}/request")
@requires_auth
async def pkgbase_request(request: Request, name: str):
async def pkgbase_request(request: Request, name: str,
next: str = Query(default=str())):
pkgbase = get_pkg_or_base(name, PackageBase)
context = await make_variable_context(request, "Submit Request")
context["pkgbase"] = pkgbase
context["next"] = next or f"/pkgbase/{name}"
return render_template(request, "pkgbase/request.html", context)
......@@ -657,7 +664,8 @@ async def pkgbase_request(request: Request, name: str):
async def pkgbase_request_post(request: Request, name: str,
type: str = Form(...),
merge_into: str = Form(default=None),
comments: str = Form(default=str())):
comments: str = Form(default=str()),
next: str = Form(default=str())):
pkgbase = get_pkg_or_base(name, PackageBase)
# Create our render context.
......@@ -734,13 +742,15 @@ async def pkgbase_request_post(request: Request, name: str,
@router.get("/pkgbase/{name}/delete")
@requires_auth
async def pkgbase_delete_get(request: Request, name: str):
async def pkgbase_delete_get(request: Request, name: str,
next: str = Query(default=str())):
if not request.user.has_credential(creds.PKGBASE_DELETE):
return RedirectResponse(f"/pkgbase/{name}",
status_code=HTTPStatus.SEE_OTHER)
context = templates.make_context(request, "Package Deletion")
context["pkgbase"] = get_pkg_or_base(name, PackageBase)
context["next"] = next or "/packages"
return render_template(request, "pkgbase/delete.html", context)
......@@ -748,7 +758,8 @@ async def pkgbase_delete_get(request: Request, name: str):
@requires_auth
async def pkgbase_delete_post(request: Request, name: str,
confirm: bool = Form(default=False),
comments: str = Form(default=str())):
comments: str = Form(default=str()),
next: str = Form(default="/packages")):
pkgbase = get_pkg_or_base(name, PackageBase)
if not request.user.has_credential(creds.PKGBASE_DELETE):
......@@ -776,7 +787,7 @@ async def pkgbase_delete_post(request: Request, name: str,
notifs = actions.pkgbase_delete_instance(
request, pkgbase, comments=comments)
util.apply_all(notifs, lambda n: n.send())
return RedirectResponse("/packages", status_code=HTTPStatus.SEE_OTHER)
return RedirectResponse(next, status_code=HTTPStatus.SEE_OTHER)
@router.get("/pkgbase/{name}/merge")
......
......@@ -102,13 +102,13 @@
</li>
{% endif %}
<li>
<a href="/pkgbase/{{ pkgbase.Name }}/request">
<a href="/pkgbase/{{ pkgbase.Name }}/request?{{ {'next': '/pkgbase/%s' | format(pkgbase.Name)} | urlencode }}">
{{ "Submit Request" | tr }}
</a>
</li>
{% if request.user.has_credential(creds.PKGBASE_DELETE) %}
<li>
<a href="/pkgbase/{{ pkgbase.Name }}/delete">
<a href="/pkgbase/{{ pkgbase.Name }}/delete?next=/packages">
{{ "Delete Package" | tr }}
</a>
</li>
......@@ -131,7 +131,7 @@
</li>
{% elif request.user.has_credential(creds.PKGBASE_DISOWN, approved=[pkgbase.Maintainer]) %}
<li>
<a href="/pkgbase/{{ pkgbase.Name }}/disown">
<a href="/pkgbase/{{ pkgbase.Name }}/disown?{{ {'next': '/pkgbase/%s' | format(pkgbase.Name)} | urlencode }}">
{{ "Disown Package" | tr }}
</a>
</li>
......
......@@ -45,6 +45,7 @@
<form action="/pkgbase/{{ pkgbase.Name }}/delete" method="post">
<fieldset>
<input type="hidden" name="next" value="{{ next }}" />
<p>
<label for="id_comments">{{ "Comments" | tr }}:</label>
......
......@@ -45,6 +45,8 @@
<form action="/pkgbase/{{ pkgbase.Name }}/disown" method="post">
<fieldset>
<input type="hidden" name="next" value="{{ next }}" />
<p>
<label for="id_comments">{{ "Comments" | tr }}:</label>
<textarea id="id_comments"
......
......@@ -27,6 +27,8 @@
<form id="request-form" action="/pkgbase/{{ pkgbase.Name }}/request"
method="post">
<fieldset>
<input type="hidden" name="next" value="{{ next }}" />
<p>
<label for="id_type">{{ "Request type" | tr }}:</label>
<select id="id_type" name="type">
......
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