@@ -155,43 +155,34 @@ def create(self, first_name=None, last_name=None, country=None, email=None,
155155 :param on_conflict: IfAlreadyExistsOption (or string name thereof) controlling creation of existing users
156156 :return: the User, so you can do User(...).create(...).add_to_groups(...)
157157 """
158- # all types handle email and on_conflict similarly
158+ # first validate the params: email, on_conflict, first_name, last_name, country
159159 create_params = {}
160160 if email is None :
161- email = self .email
161+ if not self .email :
162+ raise ArgumentError ("You must specify email when creating a user" )
162163 elif self .email is None :
163164 self ._validate (email = email )
164165 self .email = email
165166 elif self .email .lower () != email .lower ():
166167 raise ArgumentError ("Specified email (%s) doesn't match user's email (%s)" % (email , self .email ))
168+ create_params ["email" ] = self .email
167169 if on_conflict in IfAlreadyExistsOptions .__members__ :
168170 on_conflict = IfAlreadyExistsOptions [on_conflict ]
169171 if on_conflict not in IfAlreadyExistsOptions :
170172 raise ArgumentError ("on_conflict must be one of {}" .format ([o .name for o in IfAlreadyExistsOptions ]))
171173 if on_conflict != IfAlreadyExistsOptions .errorIfAlreadyExists :
172174 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
173178
174- # each type handles the create differently
179+ # each type is created using a different call
175180 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 ))
180184 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 ))
195186
196187 def update (self , email = None , username = None , first_name = None , last_name = None , country = None ):
197188 """
@@ -203,11 +194,10 @@ def update(self, email=None, username=None, first_name=None, last_name=None, cou
203194 :param country: new country for this user
204195 :return: the User, so you can do User(...).update(...).add_to_groups(...)
205196 """
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 )
211201 updates = {}
212202 for k , v in six .iteritems (dict (email = email , username = username ,
213203 firstname = first_name , lastname = last_name ,
0 commit comments