Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A AlekSIS-App-LDAP
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 6
    • Issues 6
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 3
    • Merge requests 3
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • AlekSIS®
  • Official
  • AlekSIS-App-LDAP
  • Issues
  • #29
Closed
Open
Created Aug 09, 2021 by Jonathan Weth@hansegucker⌨Owner

Allow OR matching in addition to AND matching

Currently, the importer only supports matching persons by a combination of fields. If we use email and import_ref_csv, the importer will find only persons with the same email AND the same import reference. But for use at the Katharineum, we need an option to find persons with the same email OR the same import reference.

Here is a simple patch which removes the AND mode for a OR mode, but there are much better options to solve this:

--- ldap_sync.py	2021-08-09 19:26:52.140242913 +0200
+++ production/lib/python3.9/site-packages/aleksis/apps/ldap/util/ldap_sync.py	2021-08-09 19:35:55.465769996 +0200
@@ -6,7 +6,7 @@
 from django.conf import settings
 from django.core.files import File
 from django.db import DataError, IntegrityError, transaction
-from django.db.models import fields
+from django.db.models import fields, Q
 from django.db.models.fields.files import FileField
 from django.utils.text import slugify
 from django.utils.translation import gettext as _
@@ -267,11 +267,17 @@
             if missing_key not in matches:
                 defaults[missing_key] = getattr(user, missing_key)
 
-        if get_site_preferences()["ldap__create_missing_persons"]:
-            person, created = Person.objects.get_or_create(**matches, defaults=defaults)
-        else:
-            person = Person.objects.get(**matches)
+        person = None
+        q = Q()
+        for key, value in matches.items():
+            q = q | Q(**{key: value})
+        try:
+            person = Person.objects.get(q)
             created = False
+        except Person.DoesNotExist:
+            if get_site_preferences()["ldap__create_missing_persons"]:
+                person = Person.objects.create(**matches, **defaults)
+                created = True
 
         person.user = user
         status = "New" if created else "Existing"

This has a high priority for @fph.

Assignee
Assign to
Time tracking