mirror of
https://github.com/GAM-team/GAM.git
synced 2026-06-28 09:51:36 +00:00
Make contact delegation consistent with email delegation (#1296)
Add auth to discovery document uid allowed in create/delete as input is converted to primaryemail
This commit is contained in:
@@ -1437,6 +1437,11 @@ gam <UserTypeEntity> delete|del delegate|delegates <EmailAddress>
|
||||
gam <UserTypeEntity> show delegates|delegate [csv]
|
||||
gam <UserTypeEntity> print delegates [todrive]
|
||||
|
||||
gam <UserTypeEntity> create|add contactdelegate <EmailAddress>
|
||||
gam <UserTypeEntity> delete|del contactdelegate <EmailAddress>
|
||||
gam <UserTypeEntity> show contactdelegates [csv]
|
||||
gam <UserTypeEntity> print contactdelegates [todrive]
|
||||
|
||||
gam <UserTypeEntity> [create|add] filter [from <EmailAddress>] [to <EmailAddress>] [subject <String>] [haswords|query <List>] [nowords|negatedquery <List>] [musthaveattachment|hasattachment] [excludechats] [size larger|smaller <ByteCount>]
|
||||
[label <LabelID>] [important|notimportant] [star] [trash] [markread] [archive] [neverspam] [forward <EmailAddress>]
|
||||
gam <UserTypeEntity> delete filters <FilterIDEntity>
|
||||
|
||||
@@ -1,4 +1,16 @@
|
||||
{
|
||||
"auth": {
|
||||
"oauth2": {
|
||||
"scopes": {
|
||||
"https://www.googleapis.com/auth/admin.contact.delegation": {
|
||||
"description": "View and manage your Contact Delegation"
|
||||
},
|
||||
"https://www.googleapis.com/auth/admin.contact.delegation.readonly": {
|
||||
"description": "View your Contact Delegation"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"basePath": "",
|
||||
"baseUrl": "https://admin.googleapis.com/admin/contacts/v1/",
|
||||
"batchPath": "batch",
|
||||
|
||||
@@ -11602,8 +11602,8 @@ def ProcessGAMCommand(args):
|
||||
printShowTeamDrives(users, False)
|
||||
elif showWhat in ['teamdriveinfo']:
|
||||
doGetTeamDriveInfo(users)
|
||||
elif showWhat in ['contactdelegation']:
|
||||
gapi_contactdelegation.print_(users)
|
||||
elif showWhat in ['contactdelegate', 'contactdelegates']:
|
||||
gapi_contactdelegation.print_(users, False)
|
||||
else:
|
||||
controlflow.invalid_argument_exit(showWhat, 'gam <users> show')
|
||||
elif command == 'print':
|
||||
@@ -11632,8 +11632,8 @@ def ProcessGAMCommand(args):
|
||||
printShowTokens(5, 'users', users, True)
|
||||
elif printWhat in ['teamdrive', 'teamdrives']:
|
||||
printShowTeamDrives(users, True)
|
||||
elif printWhat in ['contactdelegation']:
|
||||
gapi_contactdelegation.print_(users)
|
||||
elif printWhat in ['contactdelegate', 'contactdelegates']:
|
||||
gapi_contactdelegation.print_(users, True)
|
||||
else:
|
||||
controlflow.invalid_argument_exit(printWhat,
|
||||
'gam <users> print')
|
||||
@@ -11748,7 +11748,7 @@ def ProcessGAMCommand(args):
|
||||
addSmime(users)
|
||||
elif addWhat == 'teamdrive':
|
||||
doCreateTeamDrive(users)
|
||||
elif addWhat == 'contactdelegation':
|
||||
elif addWhat == 'contactdelegate':
|
||||
gapi_contactdelegation.create(users)
|
||||
else:
|
||||
controlflow.invalid_argument_exit(addWhat,
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
"""Contact Delegation API calls"""
|
||||
|
||||
import csv
|
||||
import os.path
|
||||
import sys
|
||||
|
||||
import gam
|
||||
@@ -17,7 +15,7 @@ def build():
|
||||
|
||||
def create(users):
|
||||
condel = build()
|
||||
delegate = gam.normalizeEmailAddressOrUID(sys.argv[5], noUid=True)
|
||||
delegate = gam.normalizeEmailAddressOrUID(sys.argv[5])
|
||||
delegate = gapi_directory_users.get_primary(delegate)
|
||||
if not delegate:
|
||||
controlflow.system_error_exit(5,
|
||||
@@ -39,7 +37,7 @@ def create(users):
|
||||
|
||||
def delete(users):
|
||||
condel = build()
|
||||
delegate = gam.normalizeEmailAddressOrUID(sys.argv[5], noUid=True)
|
||||
delegate = gam.normalizeEmailAddressOrUID(sys.argv[5])
|
||||
delegate = gapi_directory_users.get_primary(delegate)
|
||||
if not delegate:
|
||||
controlflow.system_error_exit(5,
|
||||
@@ -58,20 +56,26 @@ def delete(users):
|
||||
delegate=delegate)
|
||||
|
||||
|
||||
def print_(users):
|
||||
def print_(users, csvFormat):
|
||||
condel = build()
|
||||
titles = ['user', 'delegate']
|
||||
csv_rows = []
|
||||
todrive = False
|
||||
i = 5
|
||||
if csvFormat:
|
||||
todrive = False
|
||||
csv_rows = []
|
||||
titles = ['User', 'delegateAddress']
|
||||
else:
|
||||
csvStyle = False
|
||||
i = 5
|
||||
while i < len(sys.argv):
|
||||
myarg = sys.argv[i].lower().replace('_', '')
|
||||
if myarg == 'todrive':
|
||||
if not csvFormat and myarg == 'csv':
|
||||
csvStyle = True
|
||||
i += 1
|
||||
elif csvFormat and myarg == 'todrive':
|
||||
todrive = True
|
||||
i += 1
|
||||
else:
|
||||
controlflow.invalid_argument_exit(sys.argv[i],
|
||||
'gam print browsers')
|
||||
'gam print contactdelegation')
|
||||
page_message = gapi.got_total_items_msg('Contact Delegates', '...\n')
|
||||
for user in users:
|
||||
delegates = gapi.get_all_pages(condel.delegates(), 'list',
|
||||
@@ -79,5 +83,14 @@ def print_(users):
|
||||
page_message=page_message,
|
||||
user=user)
|
||||
for delegate in delegates:
|
||||
csv_rows.append({'user': user, 'delegate': delegate.get('email')})
|
||||
display.write_csv_file(csv_rows, titles, 'Contact Delegates', todrive)
|
||||
if csvFormat:
|
||||
csv_rows.append({'User': user, 'delegateAddress': delegate['email']})
|
||||
else:
|
||||
if csvStyle:
|
||||
print(f'{user},{delegate["email"]}')
|
||||
else:
|
||||
print(
|
||||
f'Delegator: {user}\n Delegate Email: {delegate["email"]}\n'
|
||||
)
|
||||
if csvFormat:
|
||||
display.write_csv_file(csv_rows, titles, 'Contact Delegates', todrive)
|
||||
|
||||
Reference in New Issue
Block a user