admin->admins migration: try to handle boring case where the 'first' user cant be identified because it doesnt have the root@ alias

This commit is contained in:
Alexandre Aubin 2023-02-03 21:13:17 +01:00
parent 3bbba640e9
commit 8485ebc75a

View file

@ -46,6 +46,19 @@ class MyMigration(Migration):
new_admin_user = user
break
# For some reason some system have no user with root@ alias,
# but the user does has admin / postmaster / ... alias
# ... try to find it instead otherwise this creashes the migration
# later because the admin@, postmaster@, .. aliases will already exist
if not new_admin_user:
for user in all_users:
aliases = user_info(user).get("mail-aliases", [])
if any(alias.startswith(f"admin@{main_domain}") for alias in aliases) \
and any(alias.startswith(f"postmaster@{main_domain}") for alias in aliases):
new_admin_user = user
break
self.ldap_migration_started = True
if new_admin_user: