(Hopefully) Fix user creation

This commit is contained in:
PapaTutuWawa 2021-02-04 18:49:00 +01:00
parent 0a9ffd1c9b
commit 261d65f8b3

View File

@ -3,10 +3,12 @@ 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 rest_framework.permissions import BasePermission
import ldap
User = get_user_model()
def ldap_setting(name, default):
"""Wrapper around django.conf.settings"""
@ -83,7 +85,6 @@ class LDAPUserExists(BasePermission):
def has_permission(self, request, view):
return LDAPConnection.get_instance().has_user(request.user.username)
def create_user(*args, **kwargs):
"""
A create_user function which first checks if the user already exists in the
@ -91,4 +92,5 @@ def create_user(*args, **kwargs):
"""
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)