Ensure moderators are also added as members

This commit is contained in:
Adam Goldsmith 2024-05-05 00:53:09 -04:00
parent 8f2597e40c
commit 3a224fcff2

View File

@ -64,7 +64,7 @@ def config_list(
# TODO: this will never update someone's display name # TODO: this will never update someone's display name
def diff_roster( 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]]: ) -> tuple[dict[str, str], list[mailmanclient.Member]]:
expected_members_dict = dict( expected_members_dict = dict(
list(reversed(email.utils.parseaddr(member))) for member in expected_members list(reversed(email.utils.parseaddr(member))) for member in expected_members
@ -82,9 +82,9 @@ def diff_roster(
def sync_members( 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(): for address, display_name in members_to_add.items():
print(f"Adding '{display_name} <{address}>' to list {list}") print(f"Adding '{display_name} <{address}>' to list {list}")
@ -106,9 +106,11 @@ def sync_members(
def sync_moderators( 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(): for address, display_name in members_to_add.items():
print(f"Adding '{display_name} <{address}>' as moderator to list {list}") print(f"Adding '{display_name} <{address}>' as moderator to list {list}")
@ -197,8 +199,10 @@ def main(
config_list(list, dry_run, **props["config"]) config_list(list, dry_run, **props["config"])
if "moderators" in props: if "moderators" in props:
sync_moderators(list, dry_run, props["moderators"]) sync_moderators(list, dry_run, set(props["moderators"]))
sync_members(list, dry_run, props["members"]) sync_members(
list, dry_run, set(props["members"]) | set(props.get("moderators", []))
)
lists = [list.list_name.lower() for list in domain.get_lists()] lists = [list.list_name.lower() for list in domain.get_lists()]
update_cloudflare_lists( update_cloudflare_lists(