Merge branch 'v1' of csclub.uwaterloo.ca:public/pyceo into v1

This commit is contained in:
Max Erenberg 2021-10-25 07:41:52 -04:00
commit a5bab379e2
4 changed files with 37 additions and 2 deletions

View File

@ -70,6 +70,7 @@ class User:
self.ldap_srv = component.getUtility(ILDAPService)
self.krb_srv = component.getUtility(IKerberosService)
self.base_domain = cfg.get('base_domain')
def to_dict(self, get_forwarding_addresses: bool = False) -> Dict:
data = {
@ -105,6 +106,8 @@ class User:
return self._is_club
def add_to_ldap(self):
if not self.mail_local_addresses:
self.mail_local_addresses = [f'{self.uid}@{self.base_domain}']
self.ldap_srv.add_user(self)
def remove_from_ldap(self):

View File

@ -14,9 +14,9 @@ import traceback
import ldap3
# modify as necessary
LDAP_URI = "ldap://auth1.csclub.uwaterloo.ca"
LDAP_URI = "ldaps://auth1.csclub.uwaterloo.ca"
LDAP_MEMBERS_BASE = "ou=People,dc=csclub,dc=uwaterloo,dc=ca"
UWLDAP_URI = "ldap://auth1.csclub.uwaterloo.ca"
UWLDAP_URI = "ldaps://auth1.csclub.uwaterloo.ca"
UWLDAP_MEMBERS_BASE = "ou=UWLDAP,dc=csclub,dc=uwaterloo,dc=ca"
csc_conn = ldap3.Connection(

View File

@ -0,0 +1,31 @@
#!/usr/bin/env python3
"""
This is a script which adds the mailLocalAddress to all members.
GSSAPI is used for LDAP authentication, so make sure to run `kinit` first.
Also, make sure to run this script from the top-level of the git directory
(see the sys.path hack below).
"""
import ldap3
# modify as necessary
BASE_DOMAIN = "csclub.uwaterloo.ca"
LDAP_URI = "ldaps://auth1.csclub.uwaterloo.ca"
LDAP_MEMBERS_BASE = "ou=People,dc=csclub,dc=uwaterloo,dc=ca"
conn = ldap3.Connection(
LDAP_URI, authentication=ldap3.SASL, sasl_mechanism=ldap3.KERBEROS,
auto_bind=True, raise_exceptions=True)
conn.search(LDAP_MEMBERS_BASE, '(&(objectClass=member)(!(mailLocalAddress=*)))',
attributes=['uid', 'objectClass'])
total_records_updated = 0
for entry in conn.entries:
uid = entry.uid.value
address = f'{uid}@{BASE_DOMAIN}'
changes = {'mailLocalAddress': [(ldap3.MODIFY_REPLACE, [address])]}
if 'inetLocalMailRecipient' not in entry.objectClass.values:
changes['objectClass'] = [(ldap3.MODIFY_ADD, ['inetLocalMailRecipient'])]
conn.modify(entry.entry_dn, changes)
print('Modified %s' % entry.uid.value)
total_records_updated += 1
print('Total records updated: %d' % total_records_updated)

View File

@ -63,6 +63,7 @@ def test_api_create_user(cfg, create_user_resp, mock_mail_server):
"is_club_rep": False,
"program": "Math",
"terms": ["s2021"],
"mail_local_addresses": ["test_1@csclub.internal"],
"forwarding_addresses": ['test_1@uwaterloo.internal'],
"password": "krb5"
}},