mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat(FastAPI): add /pkgbase/{name}/adopt (post)
Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
72d6016da4
commit
305d077973
3 changed files with 65 additions and 4 deletions
|
@ -950,6 +950,23 @@ async def pkgbase_disown_post(request: Request, name: str,
|
|||
status_code=int(HTTPStatus.SEE_OTHER))
|
||||
|
||||
|
||||
@router.post("/pkgbase/{name}/adopt")
|
||||
@auth_required(True)
|
||||
async def pkgbase_adopt_post(request: Request, name: str):
|
||||
pkgbase = get_pkg_or_base(name, PackageBase)
|
||||
|
||||
has_cred = request.user.has_credential("CRED_PKGBASE_ADOPT")
|
||||
if has_cred or not pkgbase.Maintainer:
|
||||
# If the user has credentials, they'll adopt the package regardless
|
||||
# of maintainership. Otherwise, we'll promote the user to maintainer
|
||||
# if no maintainer currently exists.
|
||||
with db.begin():
|
||||
pkgbase.Maintainer = request.user
|
||||
|
||||
return RedirectResponse(f"/pkgbase/{name}",
|
||||
status_code=int(HTTPStatus.SEE_OTHER))
|
||||
|
||||
|
||||
@router.get("/pkgbase/{name}/delete")
|
||||
@auth_required(True)
|
||||
async def pkgbase_delete_get(request: Request, name: str):
|
||||
|
|
|
@ -119,6 +119,16 @@
|
|||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if not result.Maintainer %}
|
||||
<li>
|
||||
<form action="/pkgbase/{{ result.Name }}/adopt" method="post">
|
||||
<input type="submit"
|
||||
class="button text-button"
|
||||
value="{{ 'Adopt Package' | tr }}"
|
||||
/>
|
||||
</form>
|
||||
</li>
|
||||
{% else %}
|
||||
{% if request.user.has_credential("CRED_PKGBASE_DISOWN", approved=[pkgbase.Maintainer]) %}
|
||||
<li>
|
||||
<a href="/pkgbase/{{ result.Name }}/disown/">
|
||||
|
@ -126,6 +136,7 @@
|
|||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1849,6 +1849,39 @@ def test_pkgbase_disown(client: TestClient, user: User, maintainer: User,
|
|||
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
|
||||
|
||||
|
||||
def test_pkgbase_adopt(client: TestClient, user: User, tu_user: User,
|
||||
maintainer: User, package: Package):
|
||||
# Unset the maintainer as if package is orphaned.
|
||||
with db.begin():
|
||||
package.PackageBase.Maintainer = None
|
||||
|
||||
pkgbasename = package.PackageBase.Name
|
||||
cookies = {"AURSID": maintainer.login(Request(), "testPassword")}
|
||||
endpoint = f"/pkgbase/{pkgbasename}/adopt"
|
||||
|
||||
# Adopt the package base.
|
||||
with client as request:
|
||||
resp = request.post(endpoint, cookies=cookies, allow_redirects=False)
|
||||
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
|
||||
assert package.PackageBase.Maintainer == maintainer
|
||||
|
||||
# Try to adopt it when it already has a maintainer; nothing changes.
|
||||
user_cookies = {"AURSID": user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
resp = request.post(endpoint, cookies=user_cookies,
|
||||
allow_redirects=False)
|
||||
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
|
||||
assert package.PackageBase.Maintainer == maintainer
|
||||
|
||||
# Steal the package as a TU.
|
||||
tu_cookies = {"AURSID": tu_user.login(Request(), "testPassword")}
|
||||
with client as request:
|
||||
resp = request.post(endpoint, cookies=tu_cookies,
|
||||
allow_redirects=False)
|
||||
assert resp.status_code == int(HTTPStatus.SEE_OTHER)
|
||||
assert package.PackageBase.Maintainer == tu_user
|
||||
|
||||
|
||||
def test_pkgbase_delete_unauthorized(client: TestClient, user: User,
|
||||
package: Package):
|
||||
pkgbase = package.PackageBase
|
||||
|
|
Loading…
Add table
Reference in a new issue