From 753ecd724424e4190e80714cb13bb004624c1f7e Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Sat, 5 Jan 2019 17:45:56 -0800 Subject: [PATCH] Allow setting of Team Drive restrictions (#834) * Allow setting of Team Drive restrictions * Add asadmin to doUpdateTeamDrive --- src/GamCommands.txt | 10 +++++++++- src/gam.py | 20 ++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/GamCommands.txt b/src/GamCommands.txt index dbaf4e80..2441ed5b 100644 --- a/src/GamCommands.txt +++ b/src/GamCommands.txt @@ -1246,8 +1246,16 @@ gam print smime [todrive] [primaryonly] gam signature|sig |(file [charset ]) (replace )* [html] [name ] [replyto ] [default] [treatasalias ] gam show signature|sig [format] + ::= + adminmanagedrestrictions| + copyrequireswriterpermission| + domainusersonly| + teammembersonly + gam create|add teamdrive -gam update teamdrive [name ] [(theme|themeid ) | ([customtheme ] [color ])] +gam update teamdrive [asadmin] [name ] + [(theme|themeid ) | ([customtheme ] [color ])] + ( )* gam delete teamdrive gam show teamdriveinfo [asadmin] gam show teamdrives [asadmin] diff --git a/src/gam.py b/src/gam.py index 22e7b7a6..4120328d 100755 --- a/src/gam.py +++ b/src/gam.py @@ -7413,12 +7413,20 @@ def doCreateTeamDrive(users): result = callGAPI(drive.teamdrives(), u'create', requestId=requestId, body=body, fields=u'id') print u'Created Team Drive %s with id %s' % (body[u'name'], result[u'id']) +TEAMDRIVE_RESTRICTIONS_MAP = { + u'adminmanagedrestrictions': u'adminManagedRestrictions', + u'copyrequireswriterpermission': u'copyRequiresWriterPermission', + u'domainusersonly': u'domainUsersOnly', + u'teammembersonly': u'teamMembersOnly', + } + def doUpdateTeamDrive(users): teamDriveId = sys.argv[5] body = {} + useDomainAdminAccess = False i = 6 while i < len(sys.argv): - myarg = sys.argv[i].lower() + myarg = sys.argv[i].lower().replace(u'_', u'') if myarg == u'name': body[u'name'] = sys.argv[i+1] i += 2 @@ -7436,6 +7444,13 @@ def doUpdateTeamDrive(users): elif myarg == u'color': body[u'colorRgb'] = getColor(sys.argv[i+1]) i += 2 + elif myarg == u'asadmin': + useDomainAdminAccess = True + i += 1 + elif myarg in TEAMDRIVE_RESTRICTIONS_MAP: + body.setdefault(u'restrictions', {}) + body[u'restrictions'][TEAMDRIVE_RESTRICTIONS_MAP[myarg]] = getBoolean(sys.argv[i+1], myarg) + i += 2 else: systemErrorExit(3, '%s is not a valid argument for "gam update teamdrive"' % sys.argv[i]) if not body: @@ -7444,7 +7459,8 @@ def doUpdateTeamDrive(users): user, drive = buildDrive3GAPIObject(user) if not drive: continue - result = callGAPI(drive.teamdrives(), u'update', body=body, teamDriveId=teamDriveId, fields=u'id', soft_errors=True) + result = callGAPI(drive.teamdrives(), u'update', + useDomainAdminAccess=useDomainAdminAccess, body=body, teamDriveId=teamDriveId, fields=u'id', soft_errors=True) if not result: continue print u'Updated Team Drive %s' % (teamDriveId)