Fix user creation

This commit is contained in:
PapaTutuWawa 2021-02-05 12:23:32 +01:00
parent 4229cebd61
commit 117ab96017
2 changed files with 6 additions and 6 deletions

View File

@ -143,6 +143,8 @@ config_locations = [
"/etc/etebase-server/etebase-server.ini", "/etc/etebase-server/etebase-server.ini",
] ]
ETEBASE_CREATE_USER_FUNC = "django_etebase.utils.create_user_blocked"
# Use config file if present # Use config file if present
if any(os.path.isfile(x) for x in config_locations): if any(os.path.isfile(x) for x in config_locations):
config = configparser.ConfigParser() 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_CREATE_USER_FUNC = "myauth.ldap.create_user"
ETEBASE_API_PERMISSIONS.append("myauth.ldap.LDAPUserExists") ETEBASE_API_PERMISSIONS.append("myauth.ldap.LDAPUserExists")
ETEBASE_CREATE_USER_FUNC = "django_etebase.utils.create_user_blocked"
# Efficient file streaming (for large files) # Efficient file streaming (for large files)
SENDFILE_BACKEND = "django_etebase.sendfile.backends.simple" SENDFILE_BACKEND = "django_etebase.sendfile.backends.simple"
SENDFILE_ROOT = MEDIA_URL SENDFILE_ROOT = MEDIA_URL

View File

@ -3,12 +3,13 @@ import logging
from django.utils import timezone from django.utils import timezone
from django.conf import settings from django.conf import settings
from django.core.exceptions import PermissionDenied 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 from rest_framework.permissions import BasePermission
import ldap import ldap
User = get_user_model() User = get_typed_user_model()
def ldap_setting(name, default): def ldap_setting(name, default):
"""Wrapper around django.conf.settings""" """Wrapper around django.conf.settings"""
@ -85,12 +86,11 @@ class LDAPUserExists(BasePermission):
def has_permission(self, request, view): def has_permission(self, request, view):
return LDAPConnection.get_instance().has_user(request.user.username) 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 A create_user function which first checks if the user already exists in the
configured LDAP directory. configured LDAP directory.
""" """
if not LDAPConnection.get_instance().has_user(kwargs["username"]): if not LDAPConnection.get_instance().has_user(kwargs["username"]):
raise PermissionDenied("User not in the LDAP directory.") raise PermissionDenied("User not in the LDAP directory.")
_ = kwargs.pop("view")
return User.objects.create_user(*args, **kwargs) return User.objects.create_user(*args, **kwargs)