mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat(auth): add requires_{auth,guest} decorators
These new decorators are meant to be used without any arguments and provide aliases to auth_required: - `auth_required(True) -> requires_auth` - `auth_required(False) -> requires_guest` These decorators should be used without arguments, e.g.: @router.get("/") @requires_guest async def my_route(request: Request): return HTMLResponse() Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
3e048e9675
commit
51b60f4210
8 changed files with 82 additions and 58 deletions
|
@ -7,7 +7,7 @@ from fastapi import HTTPException
|
|||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
from aurweb import config, db
|
||||
from aurweb.auth import AnonymousUser, BasicAuthBackend, account_type_required, auth_required
|
||||
from aurweb.auth import AnonymousUser, BasicAuthBackend, _auth_required, account_type_required
|
||||
from aurweb.models.account_type import USER, USER_ID
|
||||
from aurweb.models.session import Session
|
||||
from aurweb.models.user import User
|
||||
|
@ -105,7 +105,7 @@ async def test_auth_required_redirection_bad_referrer():
|
|||
pass
|
||||
|
||||
# Get down to the nitty gritty internal wrapper.
|
||||
bad_referrer_route = auth_required()(bad_referrer_route)
|
||||
bad_referrer_route = _auth_required()(bad_referrer_route)
|
||||
|
||||
# Execute the route with a "./blahblahblah" Referer, which does not
|
||||
# match aur_location; `./` has been used as a prefix to attempt to
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue