Skip to content

Commit

Permalink
sync_gws_mailing_lists.py: change group skipping mechanism (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
vbrik authored May 22, 2024
1 parent cb11679 commit eef1a73
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions actions/sync_gws_mailing_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
In order to be operated on by this script, mail groups must define attribute
`email` to match them to the corresponding Google Workspace mailing group/list.
Automatic action on a group can be disabled (e.g. while testing manually) by
adding this action to the group's `automation_blocklist` attribute.
This script will skip groups with `email` set if their SKIP_GROUP_ATTR_NAME
[link:Uo1in3ae] (see code) is set to true. This is intended to facilitate
manual testing.
Only Google Workspace group members whose role is 'MANAGER' or 'MEMBER'
are managed. 'OWNER' members should be managed by other means.
Expand Down Expand Up @@ -73,6 +74,7 @@
from actions.util import retry_execute, group_tree_to_list, reflow_text

ACTION_ID = 'sync_gws_mailing_lists'
SKIP_GROUP_ATTR_NAME = f"{ACTION_ID}_skip_this_group" # link:Uo1in3ae
logger = logging.getLogger(ACTION_ID)

# Paragraph separator. Used for re-flowing text.
Expand Down Expand Up @@ -312,18 +314,18 @@ async def sync_gws_mailing_lists(gws_members_client, gws_groups_client, keycloak
else:
kc_ml_groups = kc_ml_group_root['subGroups']
for kc_ml_group in kc_ml_groups:
if kc_ml_group['attributes'].get(SKIP_GROUP_ATTR_NAME, '').strip().lower() == "true":
if single_group:
logger.warning(f"Ignoring {SKIP_GROUP_ATTR_NAME} setting since we are in single-group mode.")
else:
logger.warning(f"Skipping {kc_ml_group['path']} because its {SKIP_GROUP_ATTR_NAME} is ture.")
continue
if not (group_email := kc_ml_group['attributes'].get('email')):
logger.warning(f"Attribute 'email' of {kc_ml_group['path']} is missing or empty'. Skipping.")
continue
if group_email not in gws_group_emails:
logger.error(f"Group '{group_email}' doesn't exist in Google Workspace. Skipping.")
continue
if ACTION_ID in kc_ml_group['attributes'].get('automation_blocklist', []):
if single_group:
logger.warning(f"Bypassing {kc_ml_group['path']}'s blocklist since we are in single-group mode")
else:
logger.warning(f"Skipping {kc_ml_group['path']} because we are on its blocklist")
continue

# Sanity check. Subgroups of mail groups shouldn't have attribute 'email',
# and if they do, it definitely can't be different from the root mail group.
Expand Down

0 comments on commit eef1a73

Please sign in to comment.