aboutsummaryrefslogtreecommitdiffstats
path: root/arthur/exts/directory
diff options
context:
space:
mode:
Diffstat (limited to 'arthur/exts/directory')
-rw-r--r--arthur/exts/directory/ldap.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/arthur/exts/directory/ldap.py b/arthur/exts/directory/ldap.py
index 72cb460..f2feb9e 100644
--- a/arthur/exts/directory/ldap.py
+++ b/arthur/exts/directory/ldap.py
@@ -194,8 +194,13 @@ class LDAP(commands.Cog):
notified_users.append(message.mentions[0])
+ handled = set()
+
for user in diff:
await self._process_user(user, notified_users)
+ handled.add(user.discord_user.id)
+
+ self._handle_left_users(handled)
logger.info("LDAP: Sync complete.")
except Exception as e: # noqa: BLE001
@@ -204,6 +209,21 @@ class LDAP(commands.Cog):
f":x: LDAP Sync Error: ```python\n{e}```"
)
+ def _handle_left_users(self, handled: list[int]) -> None:
+ """Handle users that have left the guild and so were not processed."""
+ ldap_users = ldap.find_users()
+
+ for user in ldap_users:
+ if user.employee_number is None or user.employee_number in handled:
+ continue
+
+ if user.locked:
+ logger.info(f"LDAP: User {user.uid} is locked, skipping.")
+ continue
+
+ logger.info(f"LDAP: Deactivating user {user.uid} as they are no longer in the guild.")
+ freeipa.deactivate_user(user.uid)
+
async def _process_user(self, user: DiffedUser, notified_users: list[discord.User]) -> None:
if user.action == LDAPSyncAction.ADD:
if user.discord_user in notified_users: