Skip to content
Snippets Groups Projects
Verified Commit ddfc0fe4 authored by Tom Teichler's avatar Tom Teichler :beers:
Browse files

Fix ldap_create_user

parent e2ab52e4
No related branches found
No related tags found
No related merge requests found
......@@ -21,8 +21,9 @@ CONSTANCE_ADDITIONAL_FIELDS = {
CONSTANCE_CONFIG = {
"ENABLE_LDAP_SYNC": (True, _("Enable ldap sync"), bool),
"LDAP_SYNC_CREATE": (True, _("Match created persons to users"), bool),
"LDAP_SYNC_ON_UPDATE": (True, _("Also sync if user updates"), bool),
"LDAP_MATCHING_FIELDS": (None, _("LDAP sync matching fields"), "matching-fields-select"),
}
CONSTANCE_CONFIG_FIELDSETS = {
"LDAP-Sync settings": ("ENABLE_LDAP_SYNC", "LDAP_SYNC_CREATE", "LDAP_MATCHING_FIELDS"),
"LDAP-Sync settings": ("ENABLE_LDAP_SYNC", "LDAP_SYNC_CREATE", "LDAP_SYNC_ON_UPDATE", "LDAP_MATCHING_FIELDS"),
}
......@@ -3,34 +3,34 @@ from django.contrib.auth import get_user_model
from constance import config
def ldap_create_user(sender, **kwargs):
def ldap_create_user(sender, instance, created, raw, using, update_fields, **kwargs):
Person = apps.get_model("core", "Person")
if config.ENABLE_LDAP_SYNC:
if not sender.person:
if config.ENABLE_LDAP_SYNC and (created or config.LDAP_SYNC_ON_UPDATE):
if not Person.objects.filter(user=instance).exists():
if config.LDAP_MATCHING_FIELDS == 'match-email':
person, created = Person.objects.get_or_create(
email=sender.email,
email=instance.email,
defaults={
"first_name": sender.first_name,
"last_name": sender.last_name,
"first_name": instance.first_name,
"last_name": instance.last_name,
}
)
elif config.LDAP_MATCHING_FIELDS == 'match-name':
person, created = Person.objects.get_or_create(
first_name=sender.first_name,
last_name=sender.last_name,
first_name=instance.first_name,
last_name=instance.last_name,
defaults={
"email": sender.email
"email": instance.email
}
)
elif config.LDAP_MATCHING_FIELDS == 'match-email-name':
person, created = Person.objects.get_or_create(
first_name=sender.first_name,
last_name=sender.last_name,
email=sender.email
first_name=instance.first_name,
last_name=instance.last_name,
email=instance.email
)
if config.LDAP_SYNC_CREATE or not created:
person.user = sender
person.user = instance
person.save()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment