diff --git a/src/GamCommands.txt b/src/GamCommands.txt index f8f02aa1..595c56af 100644 --- a/src/GamCommands.txt +++ b/src/GamCommands.txt @@ -403,7 +403,7 @@ Items, separated by spaces, with spaces or commas in the items themselves: "'it ::== "(,)*" ::= "(,)*" - ::= "(,)*" + ::= "(,)*" ::= "(,)*" ::= "(,)*" ::= "(,)*" @@ -840,19 +840,21 @@ gam print printjobs [todrive] [printer|printerid ] gam create vaulthold|hold corpus drive|groups|mail matter [name ] [query ] [(accounts|groups|users ) | (orgunit|ou )] [starttime |] [endtime |] -gam delete vaulthold|hold matter gam update vaulthold|hold matter [query ] [([addaccounts|addgroups|addusers ] [removeaccounts|removegroups|removeusers ]) | (orgunit|ou )] [starttime |] [endtime |] -gam info vaulthold|hold [matter ] +gam delete vaulthold|hold matter +gam info vaulthold|hold matter gam print vaultholds|holds [todrive] [matters ] gam create vaultmatter|matter [name ] [description ] - [collaborator|collaborators ] + [collaborator|collaborators ] gam update vaultmatter|matter [action close|reopen|delete|undelete] [name ] [description ] - [addcollaborator|addcollaborators ] [removecollaborator|removecollaborators ] + [addcollaborator|addcollaborators ] [removecollaborator|removecollaborators ] +gam delete vaultmatter|matter +gam undelete vaultmatter|matter gam info vaultmatter|matter -gam print vaultmatters|matters [todrive] [view basic|full] +gam print vaultmatters|matters [todrive] [basic|full] gam delete|del asp|asps|applicationspecificpasswords gam show asps|asp|applicationspecificpasswords diff --git a/src/gam.py b/src/gam.py index b346f7cc..5f5ad03f 100755 --- a/src/gam.py +++ b/src/gam.py @@ -7088,11 +7088,21 @@ def doDeleteTeamDrive(users): print u'Deleting Team Drive %s' % (teamDriveId) callGAPI(drive.teamdrives(), u'delete', teamDriveId=teamDriveId, soft_errors=True) +def validateCollaborators(collaboratorList, cd): + collaborators = [] + for collaborator in collaboratorList.split(u','): + collaborator_id = convertEmailAddressToUID(collaborator, cd) + if not collaborator_id: + print u'ERROR: failed to get a UID for %s. Please make sure this is a real user.' % collaborator + sys.exit(4) + collaborators.append({u'email': collaborator, u'id': collaborator_id}) + return collaborators + def doCreateVaultMatter(): v = buildGAPIObject(u'vault') body = {u'name': u'New Matter - %s' % datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")} collaborators = [] - collaborators_map = [] + cd = None i = 3 while i < len(sys.argv): myarg = sys.argv[i].lower().replace(u'_', u'') @@ -7103,14 +7113,9 @@ def doCreateVaultMatter(): body[u'description'] = sys.argv[i+1] i += 2 elif myarg in [u'collaborator', u'collaborators']: - collaborators = sys.argv[i+1].split(u',') - cd = buildGAPIObject(u'directory') - for collaborator in collaborators: - collaborator_id = convertEmailAddressToUID(collaborator, cd) - if not collaborator_id: - print u'ERROR: failed to get a UID for %s. Please make sure this is a real user.' % collaborator - sys.exit(4) - collaborators_map.append({u'email': collaborator, u'id': collaborator_id}) + if not cd: + cd = buildGAPIObject(u'directory') + collaborators.extend(validateCollaborators(sys.argv[i+1], cd)) i += 2 else: print u'ERROR: %s is not a valid argument to "gam create matter"' % sys.argv[i] @@ -7118,10 +7123,9 @@ def doCreateVaultMatter(): result = callGAPI(v.matters(), u'create', body=body, fields=u'matterId') matterId = result[u'matterId'] print u'Created matter %s' % matterId - for collaborator in collaborators_map: + for collaborator in collaborators: print u' adding collaborator %s' % collaborator[u'email'] - perm_body = {u'matterPermission': {u'role': u'COLLABORATOR', u'accountId': collaborator[u'id']}} - perm_result = callGAPI(v.matters(), u'addPermissions', matterId=matterId, body=perm_body) + callGAPI(v.matters(), u'addPermissions', matterId=matterId, body={u'matterPermission': {u'role': u'COLLABORATOR', u'accountId': collaborator[u'id']}}) def doCreateVaultHold(): v = buildGAPIObject(u'vault') @@ -7227,7 +7231,7 @@ def doDeleteVaultHold(): print u'ERROR: you must specify a matter for the hold.' sys.exit(3) print u'Deleting hold %s / %s' % (hold, holdId) - callGAPI(v.matters().holds(), u'delete', holdId=holdId, matterId=matterId) + callGAPI(v.matters().holds(), u'delete', matterId=matterId, holdId=holdId) def doGetVaultHoldInfo(): v = buildGAPIObject(u'vault') @@ -7249,6 +7253,9 @@ def doGetVaultHoldInfo(): else: print u'ERROR: %s is not a valid argument for "gam info hold"' % myarg sys.exit(3) + if not matterId: + print u'ERROR: you must specify a matter for the hold.' + sys.exit(3) results = callGAPI(v.matters().holds(), u'get', matterId=matterId, holdId=holdId) cd = buildGAPIObject(u'directory') if u'accounts' in results: @@ -7390,25 +7397,15 @@ def doUpdateVaultMatter(action=None): body[u'description'] = sys.argv[i+1] i += 2 elif myarg in [u'addcollaborator', u'addcollaborators']: - for collaborator in sys.argv[i+1].split(u','): - if not cd: - cd = buildGAPIObject(u'directory') - collaborator_id = convertEmailAddressToUID(collaborator, cd) - if not collaborator_id: - print u'ERROR: failed to get a UID for %s. Please make sure this is a real user.' % collaborator - sys.exit(4) - add_collaborators.append({u'email': collaborator, u'id': collaborator_id}) + if not cd: + cd = buildGAPIObject(u'directory') + add_collaborators.extend(validateCollaborators(sys.argv[i+1], cd)) i += 2 elif myarg in [u'removecollaborator', u'removecollaborators']: - remove_collaborators = sys.argv[i+1].split(u',') - for collaborator in sys.argv[i+1].split(u','): - if not cd: - cd = buildGAPIObject(u'directory') - collaborator_id = convertEmailAddressToUID(collaborator, cd) - if not collaborator_id: - print u'ERROR: failed to get a UID for %s. Please make sure this is a real user.' % collaborator - sys.exit(4) - remove_collaborators.append(collaborator_id) + if not cd: + cd = buildGAPIObject(u'directory') + remove_collaborators.extend(validateCollaborators(sys.argv[i+1], cd)) + i += 2 else: print u'ERROR: %s is not a valid argument for "gam update matter"' % sys.argv[i] sys.exit(3) @@ -7416,18 +7413,16 @@ def doUpdateVaultMatter(action=None): action_kwargs = {} if body: print u'Updating matter %s...' % sys.argv[3] - result = callGAPI(v.matters(), u'update', body=body, matterId=matterId) + callGAPI(v.matters(), u'update', body=body, matterId=matterId) if action: print u'Performing %s on matter %s' % (action, sys.argv[3]) - action_result = callGAPI(v.matters(), action, matterId=matterId, **action_kwargs) + callGAPI(v.matters(), action, matterId=matterId, **action_kwargs) for collaborator in add_collaborators: print u' adding collaborator %s' % collaborator[u'email'] - perm_body = {u'matterPermission': {u'role': u'COLLABORATOR', u'accountId': collaborator[u'id']}} - perm_result = callGAPI(v.matters(), u'addPermissions', matterId=matterId, body=perm_body) + callGAPI(v.matters(), u'addPermissions', matterId=matterId, body={u'matterPermission': {u'role': u'COLLABORATOR', u'accountId': collaborator[u'id']}}) for collaborator in remove_collaborators: print u' removing collaborator %s' % collaborator[u'email'] - perm_body = {u'accountId': collaborator[u'id']} - perm_result = callGAPI(v.matters(), u'removePermissions', matterId=matterId, body=perm_body) + callGAPI(v.matters(), u'removePermissions', matterId=matterId, body={u'accountId': collaborator[u'id']}) def doGetVaultMatterInfo(): v = buildGAPIObject(u'vault') @@ -10170,17 +10165,18 @@ def doPrintVaultMatters(): v = buildGAPIObject(u'vault') todrive = False csvRows = [] - i = 3 + initialTitles = [u'matterId', u'name', u'description', u'state'] + titles = initialTitles[:] view = u'FULL' - titles = [] + i = 3 while i < len(sys.argv): myarg = sys.argv[i].lower().replace(u'_', u'') - if myarg == u'view': - view = sys.argv[i+1].upper() - i += 2 - elif myarg == u'todrive': + if myarg == u'todrive': todrive = True i += 1 + elif myarg in PROJECTION_CHOICES_MAP: + view = PROJECTION_CHOICES_MAP[myarg] + i += 1 else: print u'ERROR: %s is not a valid argument to "gam print matters"' % myarg sys.exit(3) @@ -10188,20 +10184,19 @@ def doPrintVaultMatters(): page_message = u' got %%num_items%% matters...\n' matters = callGAPIpages(v.matters(), u'list', u'matters', page_message=page_message, view=view) for matter in matters: - csvRows.append(flatten_json(matter)) - for column in csvRows[-1]: - if column not in titles: - titles.append(column) + addRowTitlesToCSVfile(flatten_json(matter), csvRows, titles) + sortCSVTitles(initialTitles, titles) writeCSVfile(csvRows, titles, u'Vault Matters', todrive) def doPrintVaultHolds(): v = buildGAPIObject(u'vault') todrive = False csvRows = [] - i = 3 + initialTitles = [u'matterId', u'holdId', u'name', u'updateTime'] + titles = initialTitles[:] matters = [] matterIds = [] - titles = [] + i = 3 while i < len(sys.argv): myarg = sys.argv[i].lower().replace(u'_', u'') if myarg == u'todrive': @@ -10226,10 +10221,8 @@ def doPrintVaultHolds(): sys.stderr.write(u'Retrieving holds for matter %s\n' % matterId) holds = callGAPIpages(v.matters().holds(), u'list', u'holds', matterId=matterId) for hold in holds: - csvRows.append(flatten_json(hold)) - for column in csvRows[-1]: - if column not in titles: - titles.append(column) + addRowTitlesToCSVfile(flatten_json(hold, flattened={u'matterId': matterId}), csvRows, titles) + sortCSVTitles(initialTitles, titles) writeCSVfile(csvRows, titles, u'Vault Holds', todrive) def doPrintMobileDevices():