Skip to content
Snippets Groups Projects
Verified Commit 2d487984 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Add patch for OR matching

parent 5f75f1b3
No related branches found
No related tags found
No related merge requests found
...@@ -7,7 +7,7 @@ from django.apps import apps ...@@ -7,7 +7,7 @@ from django.apps import apps
from django.conf import settings from django.conf import settings
from django.core.files import File from django.core.files import File
from django.db import DataError, IntegrityError, transaction from django.db import DataError, IntegrityError, transaction
from django.db.models import fields from django.db.models import Q, fields
from django.db.models.fields.files import FileField from django.db.models.fields.files import FileField
from django.utils.text import slugify from django.utils.text import slugify
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
...@@ -270,11 +270,17 @@ def ldap_sync_from_user(user, dn, attrs): ...@@ -270,11 +270,17 @@ def ldap_sync_from_user(user, dn, attrs):
if missing_key not in matches: if missing_key not in matches:
defaults[missing_key] = getattr(user, missing_key) defaults[missing_key] = getattr(user, missing_key)
if get_site_preferences()["ldap__create_missing_persons"]: person = None
person, created = Person.objects.get_or_create(**matches, defaults=defaults) q = Q()
else: for key, value in matches.items():
person = Person.objects.get(**matches) q = q | Q(**{key: value})
try:
person = Person.objects.get(q)
created = False created = False
except Person.DoesNotExist:
if get_site_preferences()["ldap__create_missing_persons"]:
person = Person.objects.create(**matches, **defaults)
created = True
person.user = user person.user = user
status = "New" if created else "Existing" status = "New" if created else "Existing"
......
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