From 117ab96017c52bab0e9f447d76db015e1a7f0f11 Mon Sep 17 00:00:00 2001 From: Alexander PapaTutuWawa Date: Fri, 5 Feb 2021 12:23:32 +0100 Subject: [PATCH] Fix user creation --- etebase_server/settings.py | 4 ++-- myauth/ldap.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/etebase_server/settings.py b/etebase_server/settings.py index 8ace7bb..e5dad08 100644 --- a/etebase_server/settings.py +++ b/etebase_server/settings.py @@ -143,6 +143,8 @@ config_locations = [ "/etc/etebase-server/etebase-server.ini", ] +ETEBASE_CREATE_USER_FUNC = "django_etebase.utils.create_user_blocked" + # Use config file if present if any(os.path.isfile(x) for x in config_locations): config = configparser.ConfigParser() @@ -180,8 +182,6 @@ if any(os.path.isfile(x) for x in config_locations): ETEBASE_CREATE_USER_FUNC = "myauth.ldap.create_user" ETEBASE_API_PERMISSIONS.append("myauth.ldap.LDAPUserExists") -ETEBASE_CREATE_USER_FUNC = "django_etebase.utils.create_user_blocked" - # Efficient file streaming (for large files) SENDFILE_BACKEND = "django_etebase.sendfile.backends.simple" SENDFILE_ROOT = MEDIA_URL diff --git a/myauth/ldap.py b/myauth/ldap.py index 273834e..1d757e7 100644 --- a/myauth/ldap.py +++ b/myauth/ldap.py @@ -3,12 +3,13 @@ import logging from django.utils import timezone from django.conf import settings from django.core.exceptions import PermissionDenied -from django.contrib.auth import get_user_model +from django_etebase.utils import CallbackContext +from myauth.models import get_typed_user_model from rest_framework.permissions import BasePermission import ldap -User = get_user_model() +User = get_typed_user_model() def ldap_setting(name, default): """Wrapper around django.conf.settings""" @@ -85,12 +86,11 @@ class LDAPUserExists(BasePermission): def has_permission(self, request, view): return LDAPConnection.get_instance().has_user(request.user.username) -def create_user(*args, **kwargs): +def create_user(context: CallbackContext, *args, **kwargs): """ A create_user function which first checks if the user already exists in the configured LDAP directory. """ if not LDAPConnection.get_instance().has_user(kwargs["username"]): raise PermissionDenied("User not in the LDAP directory.") - _ = kwargs.pop("view") return User.objects.create_user(*args, **kwargs)