Show holds for users, hide shared drives

This commit is contained in:
Jay Lee
2022-01-14 13:29:50 -05:00
parent f7ab4aef4e
commit 15b1ce370c
3 changed files with 84 additions and 15 deletions

View File

@@ -8196,6 +8196,7 @@ def doUpdateTeamDrive(users):
teamDriveId = sys.argv[5]
body = {}
useDomainAdminAccess = False
change_hide = None
i = 6
while i < len(sys.argv):
myarg = sys.argv[i].lower().replace('_', '')
@@ -8219,6 +8220,15 @@ def doUpdateTeamDrive(users):
elif myarg == 'asadmin':
useDomainAdminAccess = True
i += 1
elif myarg in ['ou', 'orgunit']:
body['orgUnitId'] = sys.argv[i+1]
i += 2
elif myarg in ['hidden']:
if getBoolean(sys.argv[i+1], myarg):
change_hide = 'hide'
else:
change_hide = 'unhide'
i += 2
elif myarg in TEAMDRIVE_RESTRICTIONS_MAP:
body.setdefault('restrictions', {})
body['restrictions'][
@@ -8228,25 +8238,31 @@ def doUpdateTeamDrive(users):
else:
controlflow.invalid_argument_exit(sys.argv[i],
'gam <users> update teamdrive')
if not body:
if not body and not change_hide:
controlflow.system_error_exit(
4, 'nothing to update. Need at least a name argument.')
for user in users:
user, drive = buildDrive3GAPIObject(user)
if not drive:
continue
result = gapi.call(drive.drives(),
if body:
result = gapi.call(drive.drives(),
'update',
useDomainAdminAccess=useDomainAdminAccess,
body=body,
driveId=teamDriveId,
fields='id',
soft_errors=True)
if not result:
continue
if not result:
continue
if change_hide:
ch_result = gapi.call(drive.drives(),
change_hide,
driveId=teamDriveId,
fields='id',
soft_errors=True)
print(f'Updated Team Drive {teamDriveId}')
def printShowTeamDrives(users, csvFormat):
todrive = False
useDomainAdminAccess = False
@@ -12026,6 +12042,8 @@ def ProcessGAMCommand(args):
doGetTeamDriveInfo(users)
elif showWhat in ['contactdelegate', 'contactdelegates']:
gapi_contactdelegation.print_(users, False)
elif showWhat in ['holds', 'vaultholds']:
gapi_vault.showHoldsForUsers(users)
else:
controlflow.invalid_argument_exit(showWhat, 'gam <users> show')
elif command == 'print':

View File

@@ -9,6 +9,27 @@ from gam.gapi import directory as gapi_directory
from gam.gapi import errors as gapi_errors
def _getAllParentOrgUnitIdsForUser(user, cd=None):
if not cd:
cd = gapi_directory.build()
parent_path = gapi.call(
cd.users(),
'get',
userKey=user,
fields='orgUnitPath',
projection='basic').get('orgUnitPath')
orgunit_ids = []
all_parent_paths = ['/']
path_split = parent_path.split('/')
for i in range(len(path_split)):
a_parent = '/'.join(path_split[:i])
if a_parent and a_parent not in all_parent_paths:
all_parent_paths.append(a_parent)
if parent_path not in all_parent_paths:
all_parent_paths.append(parent_path)
return [getOrgUnitId(a_parent, cd)[1] for a_parent in all_parent_paths]
def create():
cd = gapi_directory.build()
name = getOrgUnitItem(sys.argv[3], pathOnly=True, absolutePath=False)

View File

@@ -667,6 +667,28 @@ def updateHold():
accountId=accountId)
def showHoldsForUsers(users):
v = buildGAPIObject()
for user in users:
user = user.lower()
org_ids = gapi_directory_orgunits._getAllParentOrgUnitIdsForUser(user)
matterIds = _getAllMatterIds(v)
for matterId in matterIds:
holds = gapi.get_all_pages(v.matters().holds(),
'list',
'holds',
fields='holds(holdId,name,accounts,orgUnit),nextPageToken',
matterId=matterId)
for hold in holds:
if 'orgUnit' in hold:
if hold['orgUnit'].get('orgUnitId') in org_ids:
print(f'FOUND: User\'s OrgUnit is on hold in matterId {matterId} and holdId {hold["holdId"]} named "{hold["name"]}"')
else:
for account in hold.get('accounts', []):
if user in account.get('email', '').lower():
print(f'FOUND: User account is on hold in matterId {matterId} and holdId {hold["holdId"]} named "{hold["name"]}"')
def updateMatter(action=None):
v = buildGAPIObject()
matterId = getMatterItem(v, sys.argv[3])
@@ -894,6 +916,19 @@ def printExports():
display.write_csv_file(csvRows, titles, 'Vault Exports', todrive)
def _getAllMatterIds(v=None, state='OPEN'):
if not v:
v = buildGAPIObject()
fields = 'matters(matterId),nextPageToken'
results = gapi.get_all_pages(v.matters(),
'list',
'matters',
view='BASIC',
state=state,
fields=fields)
return [matter['matterId'] for matter in results]
def printHolds():
v = buildGAPIObject()
todrive = False
@@ -914,20 +949,15 @@ def printHolds():
else:
controlflow.invalid_argument_exit(myarg, 'gam print holds')
if not matters:
fields = 'matters(matterId),nextPageToken'
matters_results = gapi.get_all_pages(v.matters(),
'list',
'matters',
view='BASIC',
state='OPEN',
fields=fields)
for matter in matters_results:
matterIds.append(matter['matterId'])
matterIds = _getAllMatterIds(v)
else:
for matter in matters:
matterIds.append(getMatterItem(v, matter))
i = 0
matter_count = len(matterIds)
for matterId in matterIds:
sys.stderr.write(f'Retrieving holds for matter {matterId}\n')
i += 1
sys.stderr.write(f'Retrieving holds for matter {matterId} ({i}/{matter_count})\n')
holds = gapi.get_all_pages(v.matters().holds(),
'list',
'holds',