From 3a224fcff2b29d8d794f978a04b98c098923bb95 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Sun, 5 May 2024 00:53:09 -0400 Subject: [PATCH] Ensure moderators are also added as members --- mailman_sync.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/mailman_sync.py b/mailman_sync.py index 18c0113..0132b1e 100755 --- a/mailman_sync.py +++ b/mailman_sync.py @@ -64,7 +64,7 @@ def config_list( # TODO: this will never update someone's display name def diff_roster( - expected_members: list[str], existing_members: list[mailmanclient.Member] + expected_members: set[str], existing_members: set[mailmanclient.Member] ) -> tuple[dict[str, str], list[mailmanclient.Member]]: expected_members_dict = dict( list(reversed(email.utils.parseaddr(member))) for member in expected_members @@ -82,9 +82,9 @@ def diff_roster( def sync_members( - list: mailmanclient.MailingList, dry_run: bool, expected_members: list[str] + list: mailmanclient.MailingList, dry_run: bool, expected_members: set[str] ): - members_to_add, members_to_remove = diff_roster(expected_members, list.members) + members_to_add, members_to_remove = diff_roster(expected_members, set(list.members)) for address, display_name in members_to_add.items(): print(f"Adding '{display_name} <{address}>' to list {list}") @@ -106,9 +106,11 @@ def sync_members( def sync_moderators( - list: mailmanclient.MailingList, dry_run: bool, expected_members: list[str] + list: mailmanclient.MailingList, dry_run: bool, expected_members: set[str] ): - members_to_add, members_to_remove = diff_roster(expected_members, list.moderators) + members_to_add, members_to_remove = diff_roster( + expected_members, set(list.moderators) + ) for address, display_name in members_to_add.items(): print(f"Adding '{display_name} <{address}>' as moderator to list {list}") @@ -197,8 +199,10 @@ def main( config_list(list, dry_run, **props["config"]) if "moderators" in props: - sync_moderators(list, dry_run, props["moderators"]) - sync_members(list, dry_run, props["members"]) + sync_moderators(list, dry_run, set(props["moderators"])) + sync_members( + list, dry_run, set(props["members"]) | set(props.get("moderators", [])) + ) lists = [list.list_name.lower() for list in domain.get_lists()] update_cloudflare_lists(