You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
4 years ago
|
import typing as t
|
||
|
from dataclasses import dataclass
|
||
|
|
||
4 years ago
|
from django.db.models import QuerySet
|
||
4 years ago
|
from django.core.exceptions import PermissionDenied
|
||
3 years ago
|
from etebase_server.myauth.models import UserType, get_typed_user_model
|
||
4 years ago
|
|
||
4 years ago
|
from . import app_settings
|
||
|
|
||
|
|
||
4 years ago
|
User = get_typed_user_model()
|
||
4 years ago
|
|
||
|
|
||
4 years ago
|
@dataclass
|
||
|
class CallbackContext:
|
||
|
"""Class for passing extra context to callbacks"""
|
||
|
|
||
|
url_kwargs: t.Dict[str, t.Any]
|
||
4 years ago
|
user: t.Optional[UserType] = None
|
||
4 years ago
|
|
||
|
|
||
4 years ago
|
def get_user_queryset(queryset: QuerySet[UserType], context: CallbackContext) -> QuerySet[UserType]:
|
||
4 years ago
|
custom_func = app_settings.GET_USER_QUERYSET_FUNC
|
||
4 years ago
|
if custom_func is not None:
|
||
4 years ago
|
return custom_func(queryset, context)
|
||
4 years ago
|
return queryset
|
||
4 years ago
|
|
||
|
|
||
4 years ago
|
def create_user(context: CallbackContext, *args, **kwargs) -> UserType:
|
||
4 years ago
|
custom_func = app_settings.CREATE_USER_FUNC
|
||
|
if custom_func is not None:
|
||
4 years ago
|
return custom_func(context, *args, **kwargs)
|
||
4 years ago
|
return User.objects.create_user(*args, **kwargs)
|
||
4 years ago
|
|
||
|
|
||
|
def create_user_blocked(*args, **kwargs):
|
||
4 years ago
|
raise PermissionDenied("Signup is disabled for this server. Please refer to the README for more information.")
|