Skip to content

Commit

Permalink
Added optional argument convertalias to all commands that manipulat…
Browse files Browse the repository at this point in the history
…e Gmail delegates.
  • Loading branch information
taers232c committed Apr 15, 2021
1 parent ef8bd69 commit dc0e560
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/GamCommands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4944,10 +4944,10 @@ gam <UserTypeEntity> deprovision|deprov [popimap] [signout] [turnoff2sv]

# Users - Gmail - Delegates

gam <UserTypeEntity> delegate to <UserEntity>
gam <UserTypeEntity> create|add delegate|delegates <UserEntity>
gam <UserTypeEntity> delete delegate|delegates <UserEntity>
gam <UserTypeEntity> update delegate|delegates [<UserEntity>]
gam <UserTypeEntity> delegate to [convertalias] <UserEntity>
gam <UserTypeEntity> create|add delegate|delegates [convertalias] <UserEntity>
gam <UserTypeEntity> delete delegate|delegates [convertalias] <UserEntity>
gam <UserTypeEntity> update delegate|delegates [convertalias] [<UserEntity>]
gam <UserTypeEntity> show delegates|delegate [shownames] [csv]
gam <UserTypeEntity> print delegates|delegate [todrive <ToDriveAttribute>*] [shownames]

Expand Down
7 changes: 7 additions & 0 deletions src/GamUpdate.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
6.02.03

Added optional argument `convertalias` to all commands that manipulate Gmail delegates.
If not specified, the extra API call introduced in 6.02.00 to convert potential delegate email aliases
to primary email addresses is not performed; if you specify an alias as a delegate, the command will fail.
If you know that all of the delegate email addresses are primary, you can omit `convertalias` and avoid the extra API calls.

6.02.02

Thanks to Jay's assistance in getting a Data Studio API discovery document,
Expand Down
19 changes: 10 additions & 9 deletions src/gam/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"""

__author__ = 'Ross Scroggs <ross.scroggs@gmail.com>'
__version__ = '6.02.02'
__version__ = '6.02.03'
__license__ = 'Apache License 2.0 (http://www.apache.org/licenses/LICENSE-2.0)'

import base64
Expand Down Expand Up @@ -50629,25 +50629,25 @@ def printShowMessages(users):
def printShowThreads(users):
printShowMessagesThreads(users, Ent.THREAD)

# gam <UserTypeEntity> create|add delegate|delegates <UserEntity>
# gam <UserTypeEntity> delete delegate|delegates <UserEntity>
# gam <UserTypeEntity> create|add delegate|delegates [convertalias] <UserEntity>
# gam <UserTypeEntity> delete delegate|delegates [convertalias] <UserEntity>
def processDelegates(users):
cd = buildGAPIObject(API.DIRECTORY)
function = 'delete' if Act.Get() == Act.DELETE else 'create'
aliasAllowed = not checkArgumentPresent(['convertalias'])
delegateEntity = getUserObjectEntity(Cmd.OB_USER_ENTITY, Ent.DELEGATE)
checkForExtraneousArguments()
i, count, users = getEntityArgument(users)
for user in users:
i += 1
user = convertUIDtoEmailAddress(user, cd=cd, aliasAllowed=False)
user, gmail, delegates, jcount = _validateUserGetObjectList(user, i, count, delegateEntity)
if jcount == 0:
continue
Ind.Increment()
j = 0
for delegate in delegates:
j += 1
delegateEmail = convertUIDtoEmailAddress(delegate, cd=cd, aliasAllowed=False)
delegateEmail = convertUIDtoEmailAddress(delegate, cd=cd, aliasAllowed=aliasAllowed)
try:
if function == 'create':
callGAPI(gmail.users().settings().delegates(), function,
Expand All @@ -50665,15 +50665,16 @@ def processDelegates(users):
entityServiceNotApplicableWarning(Ent.USER, user, i, count)
Ind.Decrement()

# gam <UserTypeEntity> delegate to <UserEntity>
# gam <UserTypeEntity> delegate to [convertalias] <UserEntity>
def delegateTo(users):
checkArgumentPresent('to', required=True)
processDelegates(users)

# gam <UserTypeEntity> update delegate|delegates [<UserEntity>]
# gam <UserTypeEntity> update delegate|delegates [convertalias] [<UserEntity>]
def updateDelegates(users):
cd = buildGAPIObject(API.DIRECTORY)
aliasAllowed = not checkArgumentPresent(['convertalias'])
if Cmd.ArgumentsRemaining():
cd = buildGAPIObject(API.DIRECTORY)
delegateEntity = getUserObjectEntity(Cmd.OB_USER_ENTITY, Ent.DELEGATE)
checkForExtraneousArguments()
else:
Expand Down Expand Up @@ -50707,7 +50708,7 @@ def updateDelegates(users):
for delegate in delegates:
j += 1
if delegateEntity is not None or delegate['verificationStatus'] == 'accepted':
delegateEmail = delegate['delegateEmail'] if delegateEntity is None else convertUIDtoEmailAddress(delegate, cd=cd)
delegateEmail = delegate['delegateEmail'] if delegateEntity is None else convertUIDtoEmailAddress(delegate, cd=cd, aliasAllowed=aliasAllowed)
try:
callGAPI(gmail.users().settings().delegates(), 'create',
throwReasons=GAPI.GMAIL_THROW_REASONS+[GAPI.ALREADY_EXISTS, GAPI.FAILED_PRECONDITION,
Expand Down

0 comments on commit dc0e560

Please sign in to comment.