mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-03 20:31:35 +00:00
Show holds for users, hide shared drives
This commit is contained in:
@@ -8196,6 +8196,7 @@ def doUpdateTeamDrive(users):
|
|||||||
teamDriveId = sys.argv[5]
|
teamDriveId = sys.argv[5]
|
||||||
body = {}
|
body = {}
|
||||||
useDomainAdminAccess = False
|
useDomainAdminAccess = False
|
||||||
|
change_hide = None
|
||||||
i = 6
|
i = 6
|
||||||
while i < len(sys.argv):
|
while i < len(sys.argv):
|
||||||
myarg = sys.argv[i].lower().replace('_', '')
|
myarg = sys.argv[i].lower().replace('_', '')
|
||||||
@@ -8219,6 +8220,15 @@ def doUpdateTeamDrive(users):
|
|||||||
elif myarg == 'asadmin':
|
elif myarg == 'asadmin':
|
||||||
useDomainAdminAccess = True
|
useDomainAdminAccess = True
|
||||||
i += 1
|
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:
|
elif myarg in TEAMDRIVE_RESTRICTIONS_MAP:
|
||||||
body.setdefault('restrictions', {})
|
body.setdefault('restrictions', {})
|
||||||
body['restrictions'][
|
body['restrictions'][
|
||||||
@@ -8228,13 +8238,14 @@ def doUpdateTeamDrive(users):
|
|||||||
else:
|
else:
|
||||||
controlflow.invalid_argument_exit(sys.argv[i],
|
controlflow.invalid_argument_exit(sys.argv[i],
|
||||||
'gam <users> update teamdrive')
|
'gam <users> update teamdrive')
|
||||||
if not body:
|
if not body and not change_hide:
|
||||||
controlflow.system_error_exit(
|
controlflow.system_error_exit(
|
||||||
4, 'nothing to update. Need at least a name argument.')
|
4, 'nothing to update. Need at least a name argument.')
|
||||||
for user in users:
|
for user in users:
|
||||||
user, drive = buildDrive3GAPIObject(user)
|
user, drive = buildDrive3GAPIObject(user)
|
||||||
if not drive:
|
if not drive:
|
||||||
continue
|
continue
|
||||||
|
if body:
|
||||||
result = gapi.call(drive.drives(),
|
result = gapi.call(drive.drives(),
|
||||||
'update',
|
'update',
|
||||||
useDomainAdminAccess=useDomainAdminAccess,
|
useDomainAdminAccess=useDomainAdminAccess,
|
||||||
@@ -8244,9 +8255,14 @@ def doUpdateTeamDrive(users):
|
|||||||
soft_errors=True)
|
soft_errors=True)
|
||||||
if not result:
|
if not result:
|
||||||
continue
|
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}')
|
print(f'Updated Team Drive {teamDriveId}')
|
||||||
|
|
||||||
|
|
||||||
def printShowTeamDrives(users, csvFormat):
|
def printShowTeamDrives(users, csvFormat):
|
||||||
todrive = False
|
todrive = False
|
||||||
useDomainAdminAccess = False
|
useDomainAdminAccess = False
|
||||||
@@ -12026,6 +12042,8 @@ def ProcessGAMCommand(args):
|
|||||||
doGetTeamDriveInfo(users)
|
doGetTeamDriveInfo(users)
|
||||||
elif showWhat in ['contactdelegate', 'contactdelegates']:
|
elif showWhat in ['contactdelegate', 'contactdelegates']:
|
||||||
gapi_contactdelegation.print_(users, False)
|
gapi_contactdelegation.print_(users, False)
|
||||||
|
elif showWhat in ['holds', 'vaultholds']:
|
||||||
|
gapi_vault.showHoldsForUsers(users)
|
||||||
else:
|
else:
|
||||||
controlflow.invalid_argument_exit(showWhat, 'gam <users> show')
|
controlflow.invalid_argument_exit(showWhat, 'gam <users> show')
|
||||||
elif command == 'print':
|
elif command == 'print':
|
||||||
|
|||||||
@@ -9,6 +9,27 @@ from gam.gapi import directory as gapi_directory
|
|||||||
from gam.gapi import errors as gapi_errors
|
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():
|
def create():
|
||||||
cd = gapi_directory.build()
|
cd = gapi_directory.build()
|
||||||
name = getOrgUnitItem(sys.argv[3], pathOnly=True, absolutePath=False)
|
name = getOrgUnitItem(sys.argv[3], pathOnly=True, absolutePath=False)
|
||||||
|
|||||||
@@ -667,6 +667,28 @@ def updateHold():
|
|||||||
accountId=accountId)
|
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):
|
def updateMatter(action=None):
|
||||||
v = buildGAPIObject()
|
v = buildGAPIObject()
|
||||||
matterId = getMatterItem(v, sys.argv[3])
|
matterId = getMatterItem(v, sys.argv[3])
|
||||||
@@ -894,6 +916,19 @@ def printExports():
|
|||||||
display.write_csv_file(csvRows, titles, 'Vault Exports', todrive)
|
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():
|
def printHolds():
|
||||||
v = buildGAPIObject()
|
v = buildGAPIObject()
|
||||||
todrive = False
|
todrive = False
|
||||||
@@ -914,20 +949,15 @@ def printHolds():
|
|||||||
else:
|
else:
|
||||||
controlflow.invalid_argument_exit(myarg, 'gam print holds')
|
controlflow.invalid_argument_exit(myarg, 'gam print holds')
|
||||||
if not matters:
|
if not matters:
|
||||||
fields = 'matters(matterId),nextPageToken'
|
matterIds = _getAllMatterIds(v)
|
||||||
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'])
|
|
||||||
else:
|
else:
|
||||||
for matter in matters:
|
for matter in matters:
|
||||||
matterIds.append(getMatterItem(v, matter))
|
matterIds.append(getMatterItem(v, matter))
|
||||||
|
i = 0
|
||||||
|
matter_count = len(matterIds)
|
||||||
for matterId in 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(),
|
holds = gapi.get_all_pages(v.matters().holds(),
|
||||||
'list',
|
'list',
|
||||||
'holds',
|
'holds',
|
||||||
|
|||||||
Reference in New Issue
Block a user