Skip to content

Commit

Permalink
Fixed issue where removing a user from the member group would fail if…
Browse files Browse the repository at this point in the history
… the user was not part of the group. An addition to the already resolved issue #186.
  • Loading branch information
filiptypjeu committed Jan 6, 2024
1 parent ee35cef commit 0b9d9fc
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions teknologr/api/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,16 @@ def check_account(self, username):
raise e

def delete_account(self, username):
# Remove user from members group
group_dn = env("LDAP_MEMBER_GROUP_DN")
self.ldap.modify_s(group_dn, [(ldap.MOD_DELETE, 'memberUid', username.encode('utf-8'))])
# Remove user from the members LDAP group, but do not throw if the user it not part of it
try:
group_dn = env("LDAP_MEMBER_GROUP_DN")
self.ldap.modify_s(group_dn, [(ldap.MOD_DELETE, 'memberUid', username.encode('utf-8'))])
except ldap.LDAPError as e:
# Result code 16 = noSuchAttribute
if e.args[0].get('result') != 16:
raise e

# Remove user, if it exists
# Removing non-existent user would fail, so checking that first
if self.check_account(username):
dn = env("LDAP_USER_DN_TEMPLATE") % {'user': username}
self.ldap.delete_s(dn)
Expand Down

0 comments on commit 0b9d9fc

Please sign in to comment.