mirror of
https://github.com/GAM-team/GAM.git
synced 2025-07-08 05:33:34 +00:00
Better error on user delete pre-condition.
This commit is contained in:
@ -9445,13 +9445,6 @@ def doDeprovUser(users):
|
||||
print(f'Done deprovisioning {user}')
|
||||
|
||||
|
||||
def doDeleteUser():
|
||||
cd = buildGAPIObject('directory')
|
||||
user_email = normalizeEmailAddressOrUID(sys.argv[3])
|
||||
print(f'Deleting account for {user_email}')
|
||||
gapi.call(cd.users(), 'delete', userKey=user_email)
|
||||
|
||||
|
||||
def doUndeleteUser():
|
||||
cd = buildGAPIObject('directory')
|
||||
user = normalizeEmailAddressOrUID(sys.argv[3])
|
||||
@ -11626,7 +11619,7 @@ def ProcessGAMCommand(args):
|
||||
elif command == 'delete':
|
||||
argument = sys.argv[2].lower()
|
||||
if argument == 'user':
|
||||
doDeleteUser()
|
||||
gapi_directory_users.delete()
|
||||
elif argument == 'group':
|
||||
gapi_directory_groups.delete()
|
||||
elif argument == 'device':
|
||||
|
@ -1,11 +1,28 @@
|
||||
import sys
|
||||
from time import sleep
|
||||
|
||||
import gam
|
||||
from gam import display
|
||||
from gam import gapi
|
||||
from gam.gapi import directory as gapi_directory
|
||||
from gam.gapi import errors as gapi_errors
|
||||
|
||||
|
||||
def delete():
|
||||
cd = gapi_directory.build()
|
||||
user_email = gam.normalizeEmailAddressOrUID(sys.argv[3])
|
||||
print(f'Deleting account for {user_email}')
|
||||
try:
|
||||
gapi.call(cd.users(),
|
||||
'delete',
|
||||
userKey=user_email,
|
||||
throw_reasons=[gapi_errors.ErrorReason.CONDITION_NOT_MET])
|
||||
except gam.gapi.errors.GapiConditionNotMetError as err:
|
||||
display.print_error(
|
||||
f'{err} The user {user_email} may be (or have recently been) on Google Vault Hold and thus not eligible for deletion. You can check holds with "gam user <email> show vaultholds".'
|
||||
)
|
||||
|
||||
|
||||
def get_primary(email):
|
||||
'''returns primary email of user or empty if email is not a user primary or
|
||||
alias address.'''
|
||||
|
Reference in New Issue
Block a user