mirror of
https://github.com/GAM-team/GAM.git
synced 2026-06-22 15:11:37 +00:00
Clean up Vault (#542)
* Clean up Vault * Clean up print vault titles * More cleanup * Rework validateCollaborators * Recode per Jay's request * Recode per Jay's request
This commit is contained in:
@@ -403,7 +403,7 @@ Items, separated by spaces, with spaces or commas in the items themselves: "'it
|
||||
|
||||
<ACLList> ::== "<ACLScope>(,<ACLScope>)*"
|
||||
<CalendarList> ::= "<CalendarItem>(,<CalendarItem>)*"
|
||||
<CollaboratorList> ::= "<CollaboratorItem>(,<CollaboratorItem>)*"
|
||||
<CollaboratorItemList> ::= "<CollaboratorItem>(,<CollaboratorItem>)*"
|
||||
<CourseAliasList> ::= "<CourseAlias>(,<CourseAlias>)*"
|
||||
<CourseIDList> ::= "<CourseID>(,<CourseID>)*"
|
||||
<CrOSFieldNameList> ::= "<CrOSFieldName>(,<CrOSFieldName>)*"
|
||||
@@ -840,19 +840,21 @@ gam print printjobs [todrive] [printer|printerid <PrinterID>]
|
||||
gam create vaulthold|hold corpus drive|groups|mail matter <MatterItem> [name <String>] [query <QueryVaultCorpus>]
|
||||
[(accounts|groups|users <EmailItemList>) | (orgunit|ou <OrgUnit>)]
|
||||
[starttime <Date>|<DateTime>] [endtime <Date>|<DateTime>]
|
||||
gam delete vaulthold|hold <HoldItem> matter <MatterItem>
|
||||
gam update vaulthold|hold <HoldItem> matter <MatterItem> [query <QueryVaultCorpus>]
|
||||
[([addaccounts|addgroups|addusers <EmailItemList>] [removeaccounts|removegroups|removeusers <EmailItemList>]) | (orgunit|ou <OrgUnit>)]
|
||||
[starttime <Date>|<DateTime>] [endtime <Date>|<DateTime>]
|
||||
gam info vaulthold|hold <HoldItem> [matter <MatterItem>]
|
||||
gam delete vaulthold|hold <HoldItem> matter <MatterItem>
|
||||
gam info vaulthold|hold <HoldItem> matter <MatterItem>
|
||||
gam print vaultholds|holds [todrive] [matters <MatterItemList>]
|
||||
|
||||
gam create vaultmatter|matter [name <String>] [description <string>]
|
||||
[collaborator|collaborators <CollaboratorList>]
|
||||
[collaborator|collaborators <CollaboratorItemList>]
|
||||
gam update vaultmatter|matter <MatterItem> [action close|reopen|delete|undelete] [name <String>] [description <string>]
|
||||
[addcollaborator|addcollaborators <CollaboratorList>] [removecollaborator|removecollaborators <CollaboratorList>]
|
||||
[addcollaborator|addcollaborators <CollaboratorItemList>] [removecollaborator|removecollaborators <CollaboratorItemList>]
|
||||
gam delete vaultmatter|matter <MatterItem>
|
||||
gam undelete vaultmatter|matter <MatterItem>
|
||||
gam info vaultmatter|matter <MatterItem>
|
||||
gam print vaultmatters|matters [todrive] [view basic|full]
|
||||
gam print vaultmatters|matters [todrive] [basic|full]
|
||||
|
||||
gam <UserTypeEntity> delete|del asp|asps|applicationspecificpasswords <AspID>
|
||||
gam <UserTypeEntity> show asps|asp|applicationspecificpasswords
|
||||
|
||||
97
src/gam.py
97
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():
|
||||
|
||||
Reference in New Issue
Block a user