@@ -155,43 +155,34 @@ def create(self, first_name=None, last_name=None, country=None, email=None,
155
155
:param on_conflict: IfAlreadyExistsOption (or string name thereof) controlling creation of existing users
156
156
:return: the User, so you can do User(...).create(...).add_to_groups(...)
157
157
"""
158
- # all types handle email and on_conflict similarly
158
+ # first validate the params: email, on_conflict, first_name, last_name, country
159
159
create_params = {}
160
160
if email is None :
161
- email = self .email
161
+ if not self .email :
162
+ raise ArgumentError ("You must specify email when creating a user" )
162
163
elif self .email is None :
163
164
self ._validate (email = email )
164
165
self .email = email
165
166
elif self .email .lower () != email .lower ():
166
167
raise ArgumentError ("Specified email (%s) doesn't match user's email (%s)" % (email , self .email ))
168
+ create_params ["email" ] = self .email
167
169
if on_conflict in IfAlreadyExistsOptions .__members__ :
168
170
on_conflict = IfAlreadyExistsOptions [on_conflict ]
169
171
if on_conflict not in IfAlreadyExistsOptions :
170
172
raise ArgumentError ("on_conflict must be one of {}" .format ([o .name for o in IfAlreadyExistsOptions ]))
171
173
if on_conflict != IfAlreadyExistsOptions .errorIfAlreadyExists :
172
174
create_params ["option" ] = on_conflict .name
175
+ if first_name : create_params ["firstname" ] = first_name # per issue #54 now allowed for all identity types
176
+ if last_name : create_params ["lastname" ] = last_name # per issue #54 now allowed for all identity types
177
+ if country : create_params ["country" ] = country # per issue #55 should not be defaulted
173
178
174
- # each type handles the create differently
179
+ # each type is created using a different call
175
180
if self .id_type == IdentityTypes .adobeID :
176
- # Adobe ID doesn't allow anything but email
177
- if first_name or last_name or country :
178
- raise ArgumentError ("You cannot specify first or last name or country for an Adobe ID." )
179
- return self .insert (addAdobeID = dict (email = email , ** create_params ))
181
+ return self .insert (addAdobeID = dict (** create_params ))
182
+ elif self .id_type == IdentityTypes .enterpriseID :
183
+ return self .insert (createEnterpriseID = dict (** create_params ))
180
184
else :
181
- # Federated and Enterprise allow specifying the name
182
- if first_name : create_params ["firstname" ] = first_name
183
- if last_name : create_params ["lastname" ] = last_name
184
- if self .id_type == IdentityTypes .enterpriseID :
185
- # Enterprise ID can default country, already has email on create
186
- create_params ["country" ] = country if country else "UD"
187
- return self .insert (createEnterpriseID = dict (email = email , ** create_params ))
188
- else :
189
- # Federated ID must specify email if that wasn't done already
190
- if not email :
191
- raise ArgumentError ("You must specify email when creating a Federated ID" )
192
- if not country :
193
- raise ArgumentError ("You must specify country when creating a Federated ID" )
194
- return self .insert (createFederatedID = dict (email = email , country = country , ** create_params ))
185
+ return self .insert (createFederatedID = dict (** create_params ))
195
186
196
187
def update (self , email = None , username = None , first_name = None , last_name = None , country = None ):
197
188
"""
@@ -203,11 +194,10 @@ def update(self, email=None, username=None, first_name=None, last_name=None, cou
203
194
:param country: new country for this user
204
195
:return: the User, so you can do User(...).update(...).add_to_groups(...)
205
196
"""
206
- if self .id_type is IdentityTypes .adobeID :
207
- raise ArgumentError ("You cannot update any attributes of an Adobe ID." )
208
- if email : self ._validate (email = email )
209
- if username and self .id_type is IdentityTypes .enterpriseID :
210
- self ._validate (email = username )
197
+ if email :
198
+ self ._validate (email = email )
199
+ if username :
200
+ self ._validate (username = username )
211
201
updates = {}
212
202
for k , v in six .iteritems (dict (email = email , username = username ,
213
203
firstname = first_name , lastname = last_name ,
0 commit comments