FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 0fd47a5b authored by Robin Goodall's avatar Robin Goodall :speech_balloon:
Browse files

Update group settings for newly created groups even without --group-settings flag

parent 42062597
No related branches found
No related tags found
1 merge request!13Add --group-settings option
Pipeline #47909 passed
......@@ -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())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment