From 950e794bb701cdf8602a634b55e9ba22361f8381 Mon Sep 17 00:00:00 2001 From: Max Erenberg Date: Tue, 1 Nov 2022 00:19:13 -0400 Subject: [PATCH] assume alumni if UWLDAP is missing data --- ceod/model/LDAPService.py | 15 ++++++++++----- tests/conftest.py | 11 +++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/ceod/model/LDAPService.py b/ceod/model/LDAPService.py index 7ec6388..c15f916 100644 --- a/ceod/model/LDAPService.py +++ b/ceod/model/LDAPService.py @@ -316,12 +316,12 @@ class LDAPService: self, dry_run: bool = False, members: Union[List[str], None] = None, - uwldap_batch_size: int = 10, + uwldap_batch_size: int = 100, ): if members: filter = '(|' + ''.join([f'(uid={uid})' for uid in members]) + ')' else: - filter = '(objectClass=*)' + filter = '(objectClass=member)' conn = self._get_ldap_conn() conn.search( self.ldap_users_base, filter, attributes=['uid', 'program']) @@ -336,12 +336,17 @@ class LDAPService: batch_uids = uids[i:i + uwldap_batch_size] batch_uw_programs = uwldap_srv.get_programs_for_users(batch_uids) uw_programs.extend(batch_uw_programs) + # uw_programs[i] will be None if the 'ou' attribute was not + # present in UWLDAP, or if no UWLDAP entry was found at all + for i, uw_program in enumerate(uw_programs): + if uw_program in (None, 'expired', 'orphaned'): + # If the UWLDAP record is orphaned, nonexistent, or missing + # data, assume that the member graduated + uw_programs[i] = 'Alumni' users_to_change = [ (uids[i], csc_programs[i], uw_programs[i]) for i in range(len(uids)) - if csc_programs[i] != uw_programs[i] and ( - uw_programs[i] not in (None, 'expired', 'orphaned') - ) + if csc_programs[i] != uw_programs[i] ] if dry_run: return users_to_change diff --git a/tests/conftest.py b/tests/conftest.py index e3c3c3a..208bc90 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -298,6 +298,17 @@ def uwldap_srv(cfg, ldap_conn): delete_subtree(conn, base_dn) conn.add(base_dn, 'organizationalUnit') + conn.add( + f'uid=ctdalek,{base_dn}', + ['inetLocalMailRecipient', 'inetOrgPerson', 'organizationalPerson', 'person'], + { + 'mailLocalAddress': 'ctdalek@uwaterloo.internal', + 'ou': 'Math', + 'cn': 'Calum T. Dalek', + 'sn': 'Dalek', + 'givenName': 'Calum', + }, + ) _uwldap_srv = UWLDAPService() component.getGlobalSiteManager().registerUtility(_uwldap_srv, IUWLDAPService) yield _uwldap_srv