1
0
bthlabs-jsonrpc/packages/bthlabs-jsonrpc-django/bthlabs_jsonrpc_django/auth_checks.py
Tomek Wójcik c75ea4ea9d Initial public releases
* `bthlabs-jsonrpc-aiohttp` v1.0.0
* `bthlabs-jsonrpc-core` v1.0.0
* `bthlabs-jsonrpc-django` v1.0.0
2022-06-04 10:41:53 +02:00

28 lines
764 B
Python

# -*- coding: utf-8 -*-
# django-jsonrpc-django | (c) 2022-present Tomek Wójcik | MIT License
import typing
from django.http import HttpRequest
def is_authenticated(request: HttpRequest) -> bool:
"""Checks if the request user is authenticated and active."""
return all((
request.user.is_anonymous is False,
request.user.is_active is True,
))
def is_staff(request: HttpRequest) -> bool:
"""Checks if the request user is a staff user."""
return request.user.is_staff
def has_perms(perms: list[str]) -> typing.Callable:
"""Checks if the request user has the specified permissions."""
def internal_has_perms(request: HttpRequest) -> bool:
return request.user.has_perms(perms)
return internal_has_perms