2022-06-04 08:41:53 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2024-01-15 20:20:10 +00:00
|
|
|
# bthlabs-jsonrpc-django | (c) 2022-present Tomek Wójcik | MIT License
|
|
|
|
from __future__ import annotations
|
|
|
|
|
2022-06-04 08:41:53 +00:00
|
|
|
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
|