1
0
bthlabs-jsonrpc/packages/bthlabs-jsonrpc-django/bthlabs_jsonrpc_django/auth_checks.py
2024-01-15 20:20:10 +00:00

30 lines
801 B
Python

# -*- coding: utf-8 -*-
# bthlabs-jsonrpc-django | (c) 2022-present Tomek Wójcik | MIT License
from __future__ import annotations
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