Skip to content

Commit b9c0a0e

Browse files
committed
tweak email/username validation
1 parent 784c423 commit b9c0a0e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

umapi_client/functional.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,16 @@ def __init__(self, id_type=IdentityTypes.adobeID, email=None, username=None, dom
8282
raise ArgumentError("Identity type (%s) must be one of %s" % (id_type, [i.name for i in IdentityTypes]))
8383
self.id_type = id_type
8484
self.email = None
85-
self.domain = domain
85+
self.domain = None
8686
if username is not None:
8787
if email and username.lower() == email.lower():
8888
# ignore the username if it's the same as the email (policy default)
8989
username = None
90-
if domain:
91-
self.domain = domain
9290
elif id_type is not IdentityTypes.federatedID:
9391
raise ArgumentError("Username must match email except for Federated ID")
92+
else:
93+
if domain:
94+
self.domain = domain
9495
if email is not None:
9596
if '@' not in email:
9697
raise ArgumentError("Invalid email address: %s" % email)
@@ -164,8 +165,12 @@ def update(self, email=None, username=None, first_name=None, last_name=None, cou
164165
:param country: new country for this user
165166
:return: the User, so you can do User(...).update(...).add_to_groups(...)
166167
"""
167-
if self.id_type != IdentityTypes.federatedID and email != username:
168-
raise ArgumentError("Username and email address must match except for Federated ID types")
168+
if username and self.id_type != IdentityTypes.federatedID:
169+
raise ArgumentError("You cannot set username except for a federated ID")
170+
if username and not email:
171+
raise ArgumentError("Cannot update username when email is not specified")
172+
if email and username and email.lower() == username.lower():
173+
raise ArgumentError("Specify just email to set both email and username for a federated ID")
169174
updates = {}
170175
for k, v in six.iteritems(dict(email=email, username=username,
171176
firstname=first_name, lastname=last_name,

0 commit comments

Comments
 (0)