cleanup: remove int(...) casts on HTTPStatus usage

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-10-16 17:33:33 -07:00
parent 56eefabc6d
commit 6ddf888b67
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
7 changed files with 66 additions and 66 deletions

View file

@ -113,11 +113,11 @@ def get_pkg_or_base(name: str, cls: Union[Package, PackageBase] = PackageBase):
provider = db.query(OfficialProvider).filter( provider = db.query(OfficialProvider).filter(
OfficialProvider.Name == name).first() OfficialProvider.Name == name).first()
if provider: if provider:
raise HTTPException(status_code=int(HTTPStatus.NOT_FOUND)) raise HTTPException(status_code=HTTPStatus.NOT_FOUND)
instance = db.query(cls).filter(cls.Name == name).first() instance = db.query(cls).filter(cls.Name == name).first()
if cls == PackageBase and not instance: if cls == PackageBase and not instance:
raise HTTPException(status_code=int(HTTPStatus.NOT_FOUND)) raise HTTPException(status_code=HTTPStatus.NOT_FOUND)
return instance return instance
@ -125,7 +125,7 @@ def get_pkg_or_base(name: str, cls: Union[Package, PackageBase] = PackageBase):
def get_pkgbase_comment(pkgbase: PackageBase, id: int) -> PackageComment: def get_pkgbase_comment(pkgbase: PackageBase, id: int) -> PackageComment:
comment = pkgbase.comments.filter(PackageComment.ID == id).first() comment = pkgbase.comments.filter(PackageComment.ID == id).first()
if not comment: if not comment:
raise HTTPException(status_code=int(HTTPStatus.NOT_FOUND)) raise HTTPException(status_code=HTTPStatus.NOT_FOUND)
return comment return comment

View file

@ -51,7 +51,7 @@ async def passreset_post(request: Request,
if not user: if not user:
context["errors"] = ["Invalid e-mail."] context["errors"] = ["Invalid e-mail."]
return render_template(request, "passreset.html", context, return render_template(request, "passreset.html", context,
status_code=int(HTTPStatus.NOT_FOUND)) status_code=HTTPStatus.NOT_FOUND)
if resetkey: if resetkey:
context["resetkey"] = resetkey context["resetkey"] = resetkey
@ -59,18 +59,18 @@ async def passreset_post(request: Request,
if not user.ResetKey or resetkey != user.ResetKey: if not user.ResetKey or resetkey != user.ResetKey:
context["errors"] = ["Invalid e-mail."] context["errors"] = ["Invalid e-mail."]
return render_template(request, "passreset.html", context, return render_template(request, "passreset.html", context,
status_code=int(HTTPStatus.NOT_FOUND)) status_code=HTTPStatus.NOT_FOUND)
if not user or not password: if not user or not password:
context["errors"] = ["Missing a required field."] context["errors"] = ["Missing a required field."]
return render_template(request, "passreset.html", context, return render_template(request, "passreset.html", context,
status_code=int(HTTPStatus.BAD_REQUEST)) status_code=HTTPStatus.BAD_REQUEST)
if password != confirm: if password != confirm:
# If the provided password does not match the provided confirm. # If the provided password does not match the provided confirm.
context["errors"] = ["Password fields do not match."] context["errors"] = ["Password fields do not match."]
return render_template(request, "passreset.html", context, return render_template(request, "passreset.html", context,
status_code=int(HTTPStatus.BAD_REQUEST)) status_code=HTTPStatus.BAD_REQUEST)
if len(password) < User.minimum_passwd_length(): if len(password) < User.minimum_passwd_length():
# Translate the error here, which simplifies error output # Translate the error here, which simplifies error output
@ -80,7 +80,7 @@ async def passreset_post(request: Request,
"Your password must be at least %s characters.") % ( "Your password must be at least %s characters.") % (
str(User.minimum_passwd_length()))] str(User.minimum_passwd_length()))]
return render_template(request, "passreset.html", context, return render_template(request, "passreset.html", context,
status_code=int(HTTPStatus.BAD_REQUEST)) status_code=HTTPStatus.BAD_REQUEST)
# We got to this point; everything matched up. Update the password # We got to this point; everything matched up. Update the password
# and remove the ResetKey. # and remove the ResetKey.
@ -92,7 +92,7 @@ async def passreset_post(request: Request,
# Render ?step=complete. # Render ?step=complete.
return RedirectResponse(url="/passreset?step=complete", return RedirectResponse(url="/passreset?step=complete",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
# If we got here, we continue with issuing a resetkey for the user. # If we got here, we continue with issuing a resetkey for the user.
resetkey = db.make_random_value(User, User.ResetKey) resetkey = db.make_random_value(User, User.ResetKey)
@ -104,7 +104,7 @@ async def passreset_post(request: Request,
# Render ?step=confirm. # Render ?step=confirm.
return RedirectResponse(url="/passreset?step=confirm", return RedirectResponse(url="/passreset?step=confirm",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
def process_account_form(request: Request, user: User, args: dict): def process_account_form(request: Request, user: User, args: dict):
@ -373,12 +373,12 @@ async def account_register_post(request: Request,
# return HTTP 400 with an error. # return HTTP 400 with an error.
context["errors"] = errors context["errors"] = errors
return render_template(request, "register.html", context, return render_template(request, "register.html", context,
status_code=int(HTTPStatus.BAD_REQUEST)) status_code=HTTPStatus.BAD_REQUEST)
if not captcha: if not captcha:
context["errors"] = ["The CAPTCHA is missing."] context["errors"] = ["The CAPTCHA is missing."]
return render_template(request, "register.html", context, return render_template(request, "register.html", context,
status_code=int(HTTPStatus.BAD_REQUEST)) status_code=HTTPStatus.BAD_REQUEST)
# Create a user with no password with a resetkey, then send # Create a user with no password with a resetkey, then send
# an email off about it. # an email off about it.
@ -427,7 +427,7 @@ def cannot_edit(request, user):
has_dev_cred = request.user.has_credential("CRED_ACCOUNT_EDIT_DEV", has_dev_cred = request.user.has_credential("CRED_ACCOUNT_EDIT_DEV",
approved=[user]) approved=[user])
if not has_dev_cred: if not has_dev_cred:
return HTMLResponse(status_code=int(HTTPStatus.UNAUTHORIZED)) return HTMLResponse(status_code=HTTPStatus.UNAUTHORIZED)
return None return None
@ -488,12 +488,12 @@ async def account_edit_post(request: Request,
if not passwd: if not passwd:
context["errors"] = ["Invalid password."] context["errors"] = ["Invalid password."]
return render_template(request, "account/edit.html", context, return render_template(request, "account/edit.html", context,
status_code=int(HTTPStatus.BAD_REQUEST)) status_code=HTTPStatus.BAD_REQUEST)
if not ok: if not ok:
context["errors"] = errors context["errors"] = errors
return render_template(request, "account/edit.html", context, return render_template(request, "account/edit.html", context,
status_code=int(HTTPStatus.BAD_REQUEST)) status_code=HTTPStatus.BAD_REQUEST)
# Set all updated fields as needed. # Set all updated fields as needed.
with db.begin(): with db.begin():
@ -586,7 +586,7 @@ async def account(request: Request, username: str):
user = db.query(User, User.Username == username).first() user = db.query(User, User.Username == username).first()
if not user: if not user:
raise HTTPException(status_code=int(HTTPStatus.NOT_FOUND)) raise HTTPException(status_code=HTTPStatus.NOT_FOUND)
context["user"] = user context["user"] = user
@ -682,7 +682,7 @@ def render_terms_of_service(request: Request,
context: dict, context: dict,
terms: typing.Iterable): terms: typing.Iterable):
if not terms: if not terms:
return RedirectResponse("/", status_code=int(HTTPStatus.SEE_OTHER)) return RedirectResponse("/", status_code=HTTPStatus.SEE_OTHER)
context["unaccepted_terms"] = terms context["unaccepted_terms"] = terms
return render_template(request, "tos/index.html", context) return render_template(request, "tos/index.html", context)
@ -745,4 +745,4 @@ async def terms_of_service_post(request: Request,
db.create(AcceptedTerm, User=request.user, db.create(AcceptedTerm, User=request.user,
Term=term, Revision=term.Revision) Term=term, Revision=term.Revision)
return RedirectResponse("/", status_code=int(HTTPStatus.SEE_OTHER)) return RedirectResponse("/", status_code=HTTPStatus.SEE_OTHER)

View file

@ -59,7 +59,7 @@ async def login_post(request: Request,
+ max(cookie_timeout, login_timeout)) + max(cookie_timeout, login_timeout))
response = RedirectResponse(url=next, response = RedirectResponse(url=next,
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
secure_cookies = aurweb.config.getboolean("options", "disable_http_login") secure_cookies = aurweb.config.getboolean("options", "disable_http_login")
response.set_cookie("AURSID", sid, expires=expires_at, response.set_cookie("AURSID", sid, expires=expires_at,
@ -85,7 +85,7 @@ async def logout(request: Request, next: str = "/"):
# Use 303 since we may be handling a post request, that'll get it # Use 303 since we may be handling a post request, that'll get it
# to redirect to a get request. # to redirect to a get request.
response = RedirectResponse(url=next, response = RedirectResponse(url=next,
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
response.delete_cookie("AURSID") response.delete_cookie("AURSID")
response.delete_cookie("AURTZ") response.delete_cookie("AURTZ")
return response return response

View file

@ -56,7 +56,7 @@ async def language(request: Request,
# In any case, set the response's AURLANG cookie that never expires. # In any case, set the response's AURLANG cookie that never expires.
response = RedirectResponse(url=f"{next}{query_string}", response = RedirectResponse(url=f"{next}{query_string}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
secure_cookies = aurweb.config.getboolean("options", "disable_http_login") secure_cookies = aurweb.config.getboolean("options", "disable_http_login")
response.set_cookie("AURLANG", set_lang, response.set_cookie("AURLANG", set_lang,
secure=secure_cookies, httponly=True) secure=secure_cookies, httponly=True)

View file

@ -273,7 +273,7 @@ async def package_base(request: Request, name: str) -> Response:
# If this is not a split package, redirect to /packages/{name}. # If this is not a split package, redirect to /packages/{name}.
if pkgbase.packages.count() == 1: if pkgbase.packages.count() == 1:
return RedirectResponse(f"/packages/{name}", return RedirectResponse(f"/packages/{name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
# Add our base information. # Add our base information.
context = await make_single_context(request, pkgbase) context = await make_single_context(request, pkgbase)
@ -301,7 +301,7 @@ async def pkgbase_comments_post(
pkgbase = get_pkg_or_base(name, PackageBase) pkgbase = get_pkg_or_base(name, PackageBase)
if not comment: if not comment:
raise HTTPException(status_code=int(HTTPStatus.EXPECTATION_FAILED)) raise HTTPException(status_code=HTTPStatus.EXPECTATION_FAILED)
# If the provided comment is different than the record's version, # If the provided comment is different than the record's version,
# update the db record. # update the db record.
@ -320,7 +320,7 @@ async def pkgbase_comments_post(
# Redirect to the pkgbase page. # Redirect to the pkgbase page.
return RedirectResponse(f"/pkgbase/{pkgbase.Name}#comment-{comment.ID}", return RedirectResponse(f"/pkgbase/{pkgbase.Name}#comment-{comment.ID}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
@router.get("/pkgbase/{name}/comments/{id}/form") @router.get("/pkgbase/{name}/comments/{id}/form")
@ -330,10 +330,10 @@ async def pkgbase_comment_form(request: Request, name: str, id: int):
pkgbase = get_pkg_or_base(name, PackageBase) pkgbase = get_pkg_or_base(name, PackageBase)
comment = pkgbase.comments.filter(PackageComment.ID == id).first() comment = pkgbase.comments.filter(PackageComment.ID == id).first()
if not comment: if not comment:
return JSONResponse({}, status_code=int(HTTPStatus.NOT_FOUND)) return JSONResponse({}, status_code=HTTPStatus.NOT_FOUND)
if not request.user.is_elevated() and request.user != comment.User: if not request.user.is_elevated() and request.user != comment.User:
return JSONResponse({}, status_code=int(HTTPStatus.UNAUTHORIZED)) return JSONResponse({}, status_code=HTTPStatus.UNAUTHORIZED)
context = await make_single_context(request, pkgbase) context = await make_single_context(request, pkgbase)
context["comment"] = comment context["comment"] = comment
@ -353,7 +353,7 @@ async def pkgbase_comment_post(
db_comment = get_pkgbase_comment(pkgbase, id) db_comment = get_pkgbase_comment(pkgbase, id)
if not comment: if not comment:
raise HTTPException(status_code=int(HTTPStatus.EXPECTATION_FAILED)) raise HTTPException(status_code=HTTPStatus.EXPECTATION_FAILED)
# If the provided comment is different than the record's version, # If the provided comment is different than the record's version,
# update the db record. # update the db record.
@ -375,7 +375,7 @@ async def pkgbase_comment_post(
# Redirect to the pkgbase page anchored to the updated comment. # Redirect to the pkgbase page anchored to the updated comment.
return RedirectResponse(f"/pkgbase/{pkgbase.Name}#comment-{db_comment.ID}", return RedirectResponse(f"/pkgbase/{pkgbase.Name}#comment-{db_comment.ID}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
@router.post("/pkgbase/{name}/comments/{id}/delete") @router.post("/pkgbase/{name}/comments/{id}/delete")
@ -389,7 +389,7 @@ async def pkgbase_comment_delete(request: Request, name: str, id: int):
if not authorized: if not authorized:
_ = l10n.get_translator_for_request(request) _ = l10n.get_translator_for_request(request)
raise HTTPException( raise HTTPException(
status_code=int(HTTPStatus.UNAUTHORIZED), status_code=HTTPStatus.UNAUTHORIZED,
detail=_("You are not allowed to delete this comment.")) detail=_("You are not allowed to delete this comment."))
now = int(datetime.utcnow().timestamp()) now = int(datetime.utcnow().timestamp())
@ -398,7 +398,7 @@ async def pkgbase_comment_delete(request: Request, name: str, id: int):
comment.DelTS = now comment.DelTS = now
return RedirectResponse(f"/pkgbase/{name}", return RedirectResponse(f"/pkgbase/{name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
@router.post("/pkgbase/{name}/comments/{id}/undelete") @router.post("/pkgbase/{name}/comments/{id}/undelete")
@ -412,7 +412,7 @@ async def pkgbase_comment_undelete(request: Request, name: str, id: int):
if not has_cred: if not has_cred:
_ = l10n.get_translator_for_request(request) _ = l10n.get_translator_for_request(request)
raise HTTPException( raise HTTPException(
status_code=int(HTTPStatus.UNAUTHORIZED), status_code=HTTPStatus.UNAUTHORIZED,
detail=_("You are not allowed to undelete this comment.")) detail=_("You are not allowed to undelete this comment."))
with db.begin(): with db.begin():
@ -420,7 +420,7 @@ async def pkgbase_comment_undelete(request: Request, name: str, id: int):
comment.DelTS = None comment.DelTS = None
return RedirectResponse(f"/pkgbase/{name}", return RedirectResponse(f"/pkgbase/{name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
@router.post("/pkgbase/{name}/comments/{id}/pin") @router.post("/pkgbase/{name}/comments/{id}/pin")
@ -434,7 +434,7 @@ async def pkgbase_comment_pin(request: Request, name: str, id: int):
if not has_cred: if not has_cred:
_ = l10n.get_translator_for_request(request) _ = l10n.get_translator_for_request(request)
raise HTTPException( raise HTTPException(
status_code=int(HTTPStatus.UNAUTHORIZED), status_code=HTTPStatus.UNAUTHORIZED,
detail=_("You are not allowed to pin this comment.")) detail=_("You are not allowed to pin this comment."))
now = int(datetime.utcnow().timestamp()) now = int(datetime.utcnow().timestamp())
@ -442,7 +442,7 @@ async def pkgbase_comment_pin(request: Request, name: str, id: int):
comment.PinnedTS = now comment.PinnedTS = now
return RedirectResponse(f"/pkgbase/{name}", return RedirectResponse(f"/pkgbase/{name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
@router.post("/pkgbase/{name}/comments/{id}/unpin") @router.post("/pkgbase/{name}/comments/{id}/unpin")
@ -456,14 +456,14 @@ async def pkgbase_comment_unpin(request: Request, name: str, id: int):
if not has_cred: if not has_cred:
_ = l10n.get_translator_for_request(request) _ = l10n.get_translator_for_request(request)
raise HTTPException( raise HTTPException(
status_code=int(HTTPStatus.UNAUTHORIZED), status_code=HTTPStatus.UNAUTHORIZED,
detail=_("You are not allowed to unpin this comment.")) detail=_("You are not allowed to unpin this comment."))
with db.begin(): with db.begin():
comment.PinnedTS = 0 comment.PinnedTS = 0
return RedirectResponse(f"/pkgbase/{name}", return RedirectResponse(f"/pkgbase/{name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
@router.get("/pkgbase/{name}/comaintainers") @router.get("/pkgbase/{name}/comaintainers")
@ -478,7 +478,7 @@ async def package_base_comaintainers(request: Request, name: str) -> Response:
approved=[pkgbase.Maintainer]) approved=[pkgbase.Maintainer])
if not has_creds: if not has_creds:
return RedirectResponse(f"/pkgbase/{name}", return RedirectResponse(f"/pkgbase/{name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
# Add our base information. # Add our base information.
context = make_context(request, "Manage Co-maintainers") context = make_context(request, "Manage Co-maintainers")
@ -527,7 +527,7 @@ async def package_base_comaintainers_post(
approved=[pkgbase.Maintainer]) approved=[pkgbase.Maintainer])
if not has_creds: if not has_creds:
return RedirectResponse(f"/pkgbase/{name}", return RedirectResponse(f"/pkgbase/{name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
users = set(users.split("\n")) users = set(users.split("\n"))
users.remove(str()) # Remove any empty strings from the set. users.remove(str()) # Remove any empty strings from the set.
@ -605,7 +605,7 @@ async def package_base_comaintainers_post(
return render_template(request, "pkgbase/comaintainers.html", context) return render_template(request, "pkgbase/comaintainers.html", context)
return RedirectResponse(f"/pkgbase/{pkgbase.Name}", return RedirectResponse(f"/pkgbase/{pkgbase.Name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
@router.get("/requests") @router.get("/requests")
@ -648,7 +648,7 @@ async def package_request(request: Request, name: str):
pkgbase = db.query(PackageBase).filter(PackageBase.Name == name).first() pkgbase = db.query(PackageBase).filter(PackageBase.Name == name).first()
if not pkgbase: if not pkgbase:
raise HTTPException(status_code=int(HTTPStatus.NOT_FOUND)) raise HTTPException(status_code=HTTPStatus.NOT_FOUND)
context["pkgbase"] = pkgbase context["pkgbase"] = pkgbase
return render_template(request, "pkgbase/request.html", context) return render_template(request, "pkgbase/request.html", context)
@ -720,7 +720,7 @@ async def pkgbase_request_post(request: Request, name: str,
# Redirect the submitting user to /packages. # Redirect the submitting user to /packages.
return RedirectResponse("/packages", return RedirectResponse("/packages",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
@router.get("/requests/{id}/close") @router.get("/requests/{id}/close")
@ -729,7 +729,7 @@ async def requests_close(request: Request, id: int):
pkgreq = db.query(PackageRequest).filter(PackageRequest.ID == id).first() pkgreq = db.query(PackageRequest).filter(PackageRequest.ID == id).first()
if not request.user.is_elevated() and request.user != pkgreq.User: if not request.user.is_elevated() and request.user != pkgreq.User:
# Request user doesn't have permission here: redirect to '/'. # Request user doesn't have permission here: redirect to '/'.
return RedirectResponse("/", status_code=int(HTTPStatus.SEE_OTHER)) return RedirectResponse("/", status_code=HTTPStatus.SEE_OTHER)
context = make_context(request, "Close Request") context = make_context(request, "Close Request")
context["pkgreq"] = pkgreq context["pkgreq"] = pkgreq
@ -744,7 +744,7 @@ async def requests_close_post(request: Request, id: int,
pkgreq = db.query(PackageRequest).filter(PackageRequest.ID == id).first() pkgreq = db.query(PackageRequest).filter(PackageRequest.ID == id).first()
if not request.user.is_elevated() and request.user != pkgreq.User: if not request.user.is_elevated() and request.user != pkgreq.User:
# Request user doesn't have permission here: redirect to '/'. # Request user doesn't have permission here: redirect to '/'.
return RedirectResponse("/", status_code=int(HTTPStatus.SEE_OTHER)) return RedirectResponse("/", status_code=HTTPStatus.SEE_OTHER)
context = make_context(request, "Close Request") context = make_context(request, "Close Request")
context["pkgreq"] = pkgreq context["pkgreq"] = pkgreq
@ -770,7 +770,7 @@ async def requests_close_post(request: Request, id: int,
conn, request.user.ID, pkgreq.ID, pkgreq.status_display()) conn, request.user.ID, pkgreq.ID, pkgreq.status_display())
notify_.send() notify_.send()
return RedirectResponse("/requests", status_code=int(HTTPStatus.SEE_OTHER)) return RedirectResponse("/requests", status_code=HTTPStatus.SEE_OTHER)
@router.get("/pkgbase/{name}/flag") @router.get("/pkgbase/{name}/flag")
@ -781,7 +781,7 @@ async def pkgbase_flag_get(request: Request, name: str):
has_cred = request.user.has_credential("CRED_PKGBASE_FLAG") has_cred = request.user.has_credential("CRED_PKGBASE_FLAG")
if not has_cred or pkgbase.Flagger is not None: if not has_cred or pkgbase.Flagger is not None:
return RedirectResponse(f"/pkgbase/{name}", return RedirectResponse(f"/pkgbase/{name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
context = make_context(request, "Flag Package Out-Of-Date") context = make_context(request, "Flag Package Out-Of-Date")
context["pkgbase"] = pkgbase context["pkgbase"] = pkgbase
@ -800,7 +800,7 @@ async def pkgbase_flag_post(request: Request, name: str,
context["errors"] = ["The selected packages have not been flagged, " context["errors"] = ["The selected packages have not been flagged, "
"please enter a comment."] "please enter a comment."]
return render_template(request, "packages/flag.html", context, return render_template(request, "packages/flag.html", context,
status_code=int(HTTPStatus.BAD_REQUEST)) status_code=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:
@ -811,7 +811,7 @@ async def pkgbase_flag_post(request: Request, name: str,
pkgbase.FlaggerComment = comments pkgbase.FlaggerComment = comments
return RedirectResponse(f"/pkgbase/{name}", return RedirectResponse(f"/pkgbase/{name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
@router.post("/pkgbase/{name}/unflag") @router.post("/pkgbase/{name}/unflag")
@ -828,7 +828,7 @@ async def pkgbase_unflag(request: Request, name: str):
pkgbase.FlaggerComment = str() pkgbase.FlaggerComment = str()
return RedirectResponse(f"/pkgbase/{name}", return RedirectResponse(f"/pkgbase/{name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
@router.post("/pkgbase/{name}/notify") @router.post("/pkgbase/{name}/notify")
@ -847,7 +847,7 @@ async def pkgbase_notify(request: Request, name: str):
User=request.user) User=request.user)
return RedirectResponse(f"/pkgbase/{name}", return RedirectResponse(f"/pkgbase/{name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
@router.post("/pkgbase/{name}/unnotify") @router.post("/pkgbase/{name}/unnotify")
@ -864,7 +864,7 @@ async def pkgbase_unnotify(request: Request, name: str):
db.session.delete(notif) db.session.delete(notif)
return RedirectResponse(f"/pkgbase/{name}", return RedirectResponse(f"/pkgbase/{name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
@router.post("/pkgbase/{name}/vote") @router.post("/pkgbase/{name}/vote")
@ -889,7 +889,7 @@ async def pkgbase_vote(request: Request, name: str):
popupdate.run_single(conn, pkgbase) popupdate.run_single(conn, pkgbase)
return RedirectResponse(f"/pkgbase/{name}", return RedirectResponse(f"/pkgbase/{name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
@router.post("/pkgbase/{name}/unvote") @router.post("/pkgbase/{name}/unvote")
@ -910,7 +910,7 @@ async def pkgbase_unvote(request: Request, name: str):
popupdate.run_single(conn, pkgbase) popupdate.run_single(conn, pkgbase)
return RedirectResponse(f"/pkgbase/{name}", return RedirectResponse(f"/pkgbase/{name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
def disown_pkgbase(pkgbase: PackageBase, disowner: User): def disown_pkgbase(pkgbase: PackageBase, disowner: User):
@ -944,7 +944,7 @@ async def pkgbase_disown_get(request: Request, name: str):
approved=[pkgbase.Maintainer]) approved=[pkgbase.Maintainer])
if not has_cred: if not has_cred:
return RedirectResponse(f"/pkgbase/{name}", return RedirectResponse(f"/pkgbase/{name}",
int(HTTPStatus.SEE_OTHER)) HTTPStatus.SEE_OTHER)
context = make_context(request, "Disown Package") context = make_context(request, "Disown Package")
context["pkgbase"] = pkgbase context["pkgbase"] = pkgbase
@ -961,7 +961,7 @@ async def pkgbase_disown_post(request: Request, name: str,
approved=[pkgbase.Maintainer]) approved=[pkgbase.Maintainer])
if not has_cred: if not has_cred:
return RedirectResponse(f"/pkgbase/{name}", return RedirectResponse(f"/pkgbase/{name}",
int(HTTPStatus.SEE_OTHER)) HTTPStatus.SEE_OTHER)
if not confirm: if not confirm:
context = make_context(request, "Disown Package") context = make_context(request, "Disown Package")
@ -969,11 +969,11 @@ async def pkgbase_disown_post(request: Request, name: str,
context["errors"] = [("The selected packages have not been disowned, " context["errors"] = [("The selected packages have not been disowned, "
"check the confirmation checkbox.")] "check the confirmation checkbox.")]
return render_template(request, "packages/disown.html", context, return render_template(request, "packages/disown.html", context,
status_code=int(HTTPStatus.EXPECTATION_FAILED)) status_code=HTTPStatus.EXPECTATION_FAILED)
disown_pkgbase(pkgbase, request.user) disown_pkgbase(pkgbase, request.user)
return RedirectResponse(f"/pkgbase/{name}", return RedirectResponse(f"/pkgbase/{name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
@router.post("/pkgbase/{name}/adopt") @router.post("/pkgbase/{name}/adopt")
@ -990,7 +990,7 @@ async def pkgbase_adopt_post(request: Request, name: str):
pkgbase.Maintainer = request.user pkgbase.Maintainer = request.user
return RedirectResponse(f"/pkgbase/{name}", return RedirectResponse(f"/pkgbase/{name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
@router.get("/pkgbase/{name}/delete") @router.get("/pkgbase/{name}/delete")
@ -998,7 +998,7 @@ async def pkgbase_adopt_post(request: Request, name: str):
async def pkgbase_delete_get(request: Request, name: str): async def pkgbase_delete_get(request: Request, name: str):
if not request.user.has_credential("CRED_PKGBASE_DELETE"): if not request.user.has_credential("CRED_PKGBASE_DELETE"):
return RedirectResponse(f"/pkgbase/{name}", return RedirectResponse(f"/pkgbase/{name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
context = make_context(request, "Package Deletion") context = make_context(request, "Package Deletion")
context["pkgbase"] = get_pkg_or_base(name, PackageBase) context["pkgbase"] = get_pkg_or_base(name, PackageBase)
@ -1013,7 +1013,7 @@ async def pkgbase_delete_post(request: Request, name: str,
if not request.user.has_credential("CRED_PKGBASE_DELETE"): if not request.user.has_credential("CRED_PKGBASE_DELETE"):
return RedirectResponse(f"/pkgbase/{name}", return RedirectResponse(f"/pkgbase/{name}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)
if not confirm: if not confirm:
context = make_context(request, "Package Deletion") context = make_context(request, "Package Deletion")
@ -1021,10 +1021,10 @@ async def pkgbase_delete_post(request: Request, name: str,
context["errors"] = [("The selected packages have not been deleted, " context["errors"] = [("The selected packages have not been deleted, "
"check the confirmation checkbox.")] "check the confirmation checkbox.")]
return render_template(request, "packages/delete.html", context, return render_template(request, "packages/delete.html", context,
status_code=int(HTTPStatus.EXPECTATION_FAILED)) status_code=HTTPStatus.EXPECTATION_FAILED)
packages = pkgbase.packages.all() packages = pkgbase.packages.all()
for package in packages: for package in packages:
delete_package(request.user, package) delete_package(request.user, package)
return RedirectResponse("/packages", status_code=int(HTTPStatus.SEE_OTHER)) return RedirectResponse("/packages", status_code=HTTPStatus.SEE_OTHER)

View file

@ -157,7 +157,7 @@ async def trusted_user_proposal(request: Request, proposal: int):
voteinfo = db.query(TUVoteInfo, TUVoteInfo.ID == proposal).first() voteinfo = db.query(TUVoteInfo, TUVoteInfo.ID == proposal).first()
if not voteinfo: if not voteinfo:
raise HTTPException(status_code=int(HTTPStatus.NOT_FOUND)) raise HTTPException(status_code=HTTPStatus.NOT_FOUND)
voters = db.query(User).join(TUVote).filter(TUVote.VoteID == voteinfo.ID) voters = db.query(User).join(TUVote).filter(TUVote.VoteID == voteinfo.ID)
vote = db.query(TUVote, and_(TUVote.UserID == request.user.ID, vote = db.query(TUVote, and_(TUVote.UserID == request.user.ID,
@ -185,7 +185,7 @@ async def trusted_user_proposal_post(request: Request,
voteinfo = db.query(TUVoteInfo, TUVoteInfo.ID == proposal).first() voteinfo = db.query(TUVoteInfo, TUVoteInfo.ID == proposal).first()
if not voteinfo: if not voteinfo:
raise HTTPException(status_code=int(HTTPStatus.NOT_FOUND)) raise HTTPException(status_code=HTTPStatus.NOT_FOUND)
voters = db.query(User).join(TUVote).filter(TUVote.VoteID == voteinfo.ID) voters = db.query(User).join(TUVote).filter(TUVote.VoteID == voteinfo.ID)
vote = db.query(TUVote, and_(TUVote.UserID == request.user.ID, vote = db.query(TUVote, and_(TUVote.UserID == request.user.ID,
@ -212,7 +212,7 @@ async def trusted_user_proposal_post(request: Request,
setattr(voteinfo, decision, getattr(voteinfo, decision) + 1) setattr(voteinfo, decision, getattr(voteinfo, decision) + 1)
else: else:
return Response("Invalid 'decision' value.", return Response("Invalid 'decision' value.",
status_code=int(HTTPStatus.BAD_REQUEST)) status_code=HTTPStatus.BAD_REQUEST)
with db.begin(): with db.begin():
vote = db.create(TUVote, User=request.user, VoteInfo=voteinfo) vote = db.create(TUVote, User=request.user, VoteInfo=voteinfo)
@ -303,4 +303,4 @@ async def trusted_user_addvote_post(request: Request,
# Redirect to the new proposal. # Redirect to the new proposal.
return RedirectResponse(f"/tu/{voteinfo.ID}", return RedirectResponse(f"/tu/{voteinfo.ID}",
status_code=int(HTTPStatus.SEE_OTHER)) status_code=HTTPStatus.SEE_OTHER)

View file

@ -139,7 +139,7 @@ def render_template(request: Request,
status_code: HTTPStatus = HTTPStatus.OK): status_code: HTTPStatus = HTTPStatus.OK):
""" Render a template as an HTMLResponse. """ """ Render a template as an HTMLResponse. """
rendered = render_raw_template(request, path, context) rendered = render_raw_template(request, path, context)
response = HTMLResponse(rendered, status_code=status_code) response = HTMLResponse(rendered, status_code=int(status_code))
secure_cookies = aurweb.config.getboolean("options", "disable_http_login") secure_cookies = aurweb.config.getboolean("options", "disable_http_login")
response.set_cookie("AURLANG", context.get("language"), response.set_cookie("AURLANG", context.get("language"),
secure=secure_cookies, httponly=True) secure=secure_cookies, httponly=True)