mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-03 12:21:35 +00:00
Improve gam user show vaultholds (#1472)
* Improve gam user show vaultholds * Handle user in / * Handle user in / more efficiently * Display total holds, don't set rc, allow uid
This commit is contained in:
@@ -9,25 +9,30 @@ 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):
|
def _getAllParentOrgUnitsForUser(user, cd=None):
|
||||||
if not cd:
|
if not cd:
|
||||||
cd = gapi_directory.build()
|
cd = gapi_directory.build()
|
||||||
parent_path = gapi.call(
|
parent_path = gapi.call(cd.users(),
|
||||||
cd.users(),
|
|
||||||
'get',
|
'get',
|
||||||
userKey=user,
|
userKey=user,
|
||||||
fields='orgUnitPath',
|
fields='orgUnitPath',
|
||||||
projection='basic').get('orgUnitPath')
|
projection='basic')['orgUnitPath']
|
||||||
orgunit_ids = []
|
if parent_path == '/':
|
||||||
all_parent_paths = ['/']
|
orgUnitPath, orgUnitId = getOrgUnitId('/', cd)
|
||||||
path_split = parent_path.split('/')
|
return {orgUnitId: orgUnitPath}
|
||||||
for i in range(len(path_split)):
|
parent_path = encodeOrgUnitPath(makeOrgUnitPathRelative(parent_path))
|
||||||
a_parent = '/'.join(path_split[:i])
|
orgUnits = {}
|
||||||
if a_parent and a_parent not in all_parent_paths:
|
while True:
|
||||||
all_parent_paths.append(a_parent)
|
result = gapi.call(cd.orgunits(),
|
||||||
if parent_path not in all_parent_paths:
|
'get',
|
||||||
all_parent_paths.append(parent_path)
|
customerId=GC_Values[GC_CUSTOMER_ID],
|
||||||
return [getOrgUnitId(a_parent, cd)[1] for a_parent in all_parent_paths]
|
orgUnitPath=parent_path,
|
||||||
|
fields='orgUnitId,orgUnitPath,parentOrgUnitId')
|
||||||
|
orgUnits[result['orgUnitId']] = result['orgUnitPath']
|
||||||
|
if 'parentOrgUnitId' not in result:
|
||||||
|
break
|
||||||
|
parent_path = result['parentOrgUnitId']
|
||||||
|
return orgUnits
|
||||||
|
|
||||||
|
|
||||||
def create():
|
def create():
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from gam import display
|
|||||||
from gam import fileutils
|
from gam import fileutils
|
||||||
from gam import gapi
|
from gam import gapi
|
||||||
from gam.gapi import storage as gapi_storage
|
from gam.gapi import storage as gapi_storage
|
||||||
|
from gam.gapi import directory as gapi_directory
|
||||||
from gam.gapi.directory import orgunits as gapi_directory_orgunits
|
from gam.gapi.directory import orgunits as gapi_directory_orgunits
|
||||||
from gam import utils
|
from gam import utils
|
||||||
|
|
||||||
@@ -668,26 +669,34 @@ def updateHold():
|
|||||||
|
|
||||||
|
|
||||||
def showHoldsForUsers(users):
|
def showHoldsForUsers(users):
|
||||||
|
cd = gapi_directory.build()
|
||||||
v = buildGAPIObject()
|
v = buildGAPIObject()
|
||||||
for user in users:
|
|
||||||
user = user.lower()
|
|
||||||
org_ids = gapi_directory_orgunits._getAllParentOrgUnitIdsForUser(user)
|
|
||||||
matterIds = _getAllMatterIds(v)
|
matterIds = _getAllMatterIds(v)
|
||||||
|
matterHolds = {}
|
||||||
for matterId in matterIds:
|
for matterId in matterIds:
|
||||||
holds = gapi.get_all_pages(v.matters().holds(),
|
matterHolds[matterId] = gapi.get_all_pages(v.matters().holds(),
|
||||||
'list',
|
'list',
|
||||||
'holds',
|
'holds',
|
||||||
fields='holds(holdId,name,accounts,orgUnit),nextPageToken',
|
fields='holds(holdId,name,accounts(accountId,email),orgUnit),nextPageToken',
|
||||||
matterId=matterId)
|
matterId=matterId)
|
||||||
for hold in holds:
|
totalHolds = 0
|
||||||
|
for user in users:
|
||||||
|
user = user.lower()
|
||||||
|
orgUnits = gapi_directory_orgunits._getAllParentOrgUnitsForUser(user, cd)
|
||||||
|
for matterId in matterIds:
|
||||||
|
for hold in matterHolds[matterId]:
|
||||||
if 'orgUnit' in hold:
|
if 'orgUnit' in hold:
|
||||||
if hold['orgUnit'].get('orgUnitId') in org_ids:
|
orgUnitId = hold['orgUnit'].get('orgUnitId')
|
||||||
print(f'FOUND: User\'s OrgUnit is on hold in matterId {matterId} and holdId {hold["holdId"]} named "{hold["name"]}"')
|
if orgUnitId in orgUnits:
|
||||||
|
print(f'FOUND: OrgUnit {orgUnits[orgUnitId]} for user {user} is on hold in matterId {matterId} and holdId {hold["holdId"]} named "{hold["name"]}"')
|
||||||
|
totalHolds += 1
|
||||||
else:
|
else:
|
||||||
for account in hold.get('accounts', []):
|
for account in hold.get('accounts', []):
|
||||||
if user == account.get('email', '').lower():
|
if (user == account.get('email', '').lower()) or (user == account.get('accountId', '')):
|
||||||
print(f'FOUND: User account is on hold in matterId {matterId} and holdId {hold["holdId"]} named "{hold["name"]}"')
|
print(f'FOUND: User account {user} is on hold in matterId {matterId} and holdId {hold["holdId"]} named "{hold["name"]}"')
|
||||||
|
totalHolds += 1
|
||||||
break
|
break
|
||||||
|
sys.stdout.write(f'Total Holds: {totalHolds}\n')
|
||||||
|
|
||||||
|
|
||||||
def updateMatter(action=None):
|
def updateMatter(action=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user