From 0fd47a5b3db28509f12668b5d99a72f41c1c7635 Mon Sep 17 00:00:00 2001 From: Robin Goodall <rjg21@cam.ac.uk> Date: Wed, 11 Nov 2020 16:13:17 +0000 Subject: [PATCH] Update group settings for newly created groups even without --group-settings flag --- gsuitesync/sync.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/gsuitesync/sync.py b/gsuitesync/sync.py index 8e528d4..5f6deb4 100644 --- a/gsuitesync/sync.py +++ b/gsuitesync/sync.py @@ -267,9 +267,8 @@ def sync(configuration, *, read_only=True, group_settings=False): # Build the directory service using Google API discovery. directory_service = discovery.build('admin', 'directory_v1', credentials=creds) - if group_settings: - # Also build the groupssettings service, which is a parallel API to manage group settings - groupssettings_service = discovery.build('groupssettings', 'v1', credentials=creds) + # Also build the groupssettings service, which is a parallel API to manage group settings + groupssettings_service = discovery.build('groupssettings', 'v1', credentials=creds) # Retrieve information on all users excluding domain admins. LOG.info('Getting information on Google domain users') @@ -733,13 +732,17 @@ def sync(configuration, *, read_only=True, group_settings=False): LOG.info('Updating settings for new group "%s": %s', gid, settings) yield groupssettings_service.groups().patch(groupUniqueId=email, body=settings) - # Apply any settings that differ to pre-existing groups. - for gid, settings in all_google_group_settings_by_gid.items(): - patch = {k: v for k, v in sync_config.group_settings.items() if settings.get(k) != v} - if patch: - email = gid_to_email(gid) - LOG.info('Updating settings for existing group "%s": %s', gid, patch) - yield groupssettings_service.groups().patch(groupUniqueId=email, body=patch) + if group_settings: + # Apply any settings that differ to pre-existing groups. + for gid, settings in all_google_group_settings_by_gid.items(): + patch = {k: v for k, v in sync_config.group_settings.items() + if settings.get(k) != v} + if patch: + email = gid_to_email(gid) + LOG.info('Updating settings for existing group "%s": %s', gid, patch) + yield groupssettings_service.groups().patch(groupUniqueId=email, body=patch) + else: + LOG.info('Skipping updating settings for existing groups') # A generator which will generate insert() and delete() calls to the directory service to # perform the actions required to update group members @@ -793,11 +796,7 @@ def sync(configuration, *, read_only=True, group_settings=False): # Process all the user, group and group member updates process_requests(directory_service, user_api_requests()) process_requests(directory_service, group_api_requests()) - if group_settings: - LOG.info('Performing group settings update') - process_requests(groupssettings_service, group_settings_api_requests()) - else: - LOG.info('Skipping group settings update') + process_requests(groupssettings_service, group_settings_api_requests()) process_requests(directory_service, member_api_requests()) -- GitLab