quart-imp/docs/_md/v1/quart_imp_security-permission_check.md

58 lines
1.4 KiB
Markdown
Raw Normal View History

2024-08-16 15:09:07 +01:00
```
Menu = quart_imp.security/permission_check
Title = permission_check - quart_imp.security
```
```python
from quart_imp.security import permission_check
```
```python
permission_check(
session_key: str,
values_allowed: t.Union[t.List[t.Union[str, int, bool]], str, int, bool],
fail_endpoint: t.Optional[str] = None,
endpoint_kwargs: t.Optional[t.Dict[str, t.Union[str, int]]] = None,
message: t.Optional[str] = None,
message_category: str = "message"
)
```
`@permission_check(...)`
---
A decorator that checks if the specified session key exists and its value(s) match the specified value(s).
`session_key` The session key to check for.
`values_allowed` A list of or singular value(s) that the session key must contain.
`fail_endpoint` The endpoint to redirect to if the session key does not exist or does not contain the specified values.
`endpoint_kwargs` A dictionary of keyword arguments to pass to the redirect endpoint.
`message` If a message is specified, a flash message is shown.
`message_category` The category of the flash message.
##### Example:
```python
@bp.route("/admin-page", methods=["GET"])
@login_check(
'logged_in',
True,
'blueprint.login_page'
) # can be mixed with login_check
@permission_check(
'permissions',
['admin'],
fail_endpoint='www.index',
message="Failed message"
)
async def admin_page():
...
```