@@ -256,28 +256,33 @@ def post(self, user_id):
256256 try :
257257 if not _check_incomplete_registration (user_id ):
258258 raise
259- data_dict = dict (tk .request .form )
260- files = dict (tk .request .files )
261- data_dict .update (files )
259+
260+ data_dict = logic .clean_dict (
261+ dictization_functions .unflatten (
262+ logic .tuplize_dict (logic .parse_params (tk .request .form ))
263+ )
264+ )
265+ data_dict .update (
266+ logic .clean_dict (
267+ dictization_functions .unflatten (
268+ logic .tuplize_dict (logic .parse_params (tk .request .files ))
269+ )
270+ )
271+ )
262272
263273 log .debug ("Form data received: %s" , data_dict )
264274
265- data_dict ["id" ] = user_id
266- include_fileds = [
267- "id" ,
268- "fullname" ,
269- "email" ,
270- "about" ,
271- "image_upload" ,
272- "image_url" ,
273- "guest_user" ,
274- "institution" ,
275- "clear_upload" ,
276- "save" ,
277- ]
278275 # filter out fields that are only item in include_fileds
279- data_dict = {k : v for k , v in data_dict .items () if k in include_fileds }
280276 errors = {}
277+ user_dict = {
278+ "id" : user_id ,
279+ ** {
280+ key : value
281+ for key , value in data_dict .items ()
282+ if key not in {"institution" , "guest_user" }
283+ },
284+ }
285+ print (user_dict )
281286
282287 if not data_dict .get ("fullname" ):
283288 errors ["fullname" ] = [tk ._ ("Full name is required" )]
@@ -292,6 +297,7 @@ def post(self, user_id):
292297 raise tk .ValidationError (errors )
293298
294299 data_dict ["state" ] = "pending"
300+ data_dict ["id" ] = user_id
295301 user_dict = tk .get_action ("user_update" )(context , data_dict )
296302
297303 # Add user user token table, which means the user has completed profile update process
@@ -462,83 +468,65 @@ def post(self, id):
462468 # This needed to be overrided as sysadmin cannot
463469 # edit user without providing password
464470 context , id = self ._prepare (id )
465- if tk .c .userobj .sysadmin :
466- if not context ["save" ]:
467- return self .get (id )
471+ if not context ["save" ]:
472+ return self .get (id )
468473
469- try :
470- data_dict = logic .clean_dict (
471- dictization_functions .unflatten (
472- logic .tuplize_dict (logic .parse_params (tk .request .form ))
473- )
474+ try :
475+ data_dict = logic .clean_dict (
476+ dictization_functions .unflatten (
477+ logic .tuplize_dict (logic .parse_params (tk .request .form ))
474478 )
475- data_dict . update (
476- logic . clean_dict (
477- dictization_functions . unflatten (
478- logic . tuplize_dict ( logic . parse_params ( tk . request . files ))
479- )
479+ )
480+ data_dict . update (
481+ logic . clean_dict (
482+ dictization_functions . unflatten (
483+ logic . tuplize_dict ( logic . parse_params ( tk . request . files ) )
480484 )
481485 )
486+ )
482487
483- except dictization_functions .DataError :
484- tk .abort (400 , tk ._ ("Integrity Error" ))
485- data_dict .setdefault ("activity_streams_email_notifications" , False )
486-
487- data_dict ["id" ] = id
488- # deleted user can be reactivated by sysadmin on WEB-UI
489- is_deleted = False
490- if tk .asbool (data_dict .get ("activate_user" , False )):
491- user_dict = logic .get_action ("user_show" )(context , {"id" : id })
492- # set the flag so if validation error happens we will
493- # change back the user state to deleted
494- is_deleted = user_dict .get ("state" ) == "deleted"
495- # if activate_user is checked, change the user's state to active
496- data_dict ["state" ] = "active"
497- # pop the value as we don't want to send it for
498- # validation on user_update
499- data_dict .pop ("activate_user" )
500- # we need this comparison when sysadmin edits a user,
501- # this will return True
502- # and we can utilize it for later use.
503-
504- # common users can edit their own profiles without providing
505- # password, but if they want to change
506- # their old password with new one... old password must be provided..
507- # so we are checking here if password1
508- # and password2 are filled so we can enter the validation process.
509- # when sysadmins edits a user he MUST provide sysadmin password.
510- # We are recognizing sysadmin user
511- # by email_changed variable.. this returns True
512- # and we are entering the validation.
488+ except dictization_functions .DataError :
489+ tk .abort (400 , tk ._ ("Integrity Error" ))
490+ data_dict .setdefault ("activity_streams_email_notifications" , False )
491+
492+ data_dict ["id" ] = id
493+ # deleted user can be reactivated by sysadmin on WEB-UI
494+ is_deleted = False
495+ if tk .asbool (data_dict .get ("activate_user" , False )):
496+ user_dict = logic .get_action ("user_show" )(context , {"id" : id })
497+ # set the flag so if validation error happens we will
498+ # change back the user state to deleted
499+ is_deleted = user_dict .get ("state" ) == "deleted"
500+ # if activate_user is checked, change the user's state to active
501+ data_dict ["state" ] = "active"
502+ # pop the value as we don't want to send it for
503+ # validation on user_update
504+ data_dict .pop ("activate_user" )
513505
514- try :
515- user = logic .get_action ("user_update" )(context , data_dict )
516- except tk .NotAuthorized :
517- tk .abort (403 , tk ._ ("Unauthorized to edit user %s" ) % id )
518- except tk .ObjectNotFound :
519- tk .abort (404 , tk ._ ("User not found" ))
520- except tk .ValidationError as e :
521- errors = e .error_dict
522- error_summary = e .error_summary
523- # the user state was deleted, we are trying to reactivate it but
524- # validation error happens so we want to change back the state
525- # to deleted, as it was before
526- if is_deleted and data_dict .get ("state" ) == "active" :
527- data_dict ["state" ] = "deleted"
528- return self .get (id , data_dict , errors , error_summary )
529-
530- tk .h .flash_success (tk ._ ("Profile updated" ))
531-
532- resp = tk .h .redirect_to ("user.read" , id = user ["name" ])
533- return resp
534- else :
535- return super ().post (id )
506+ try :
507+ user = logic .get_action ("user_update" )(context , data_dict )
508+ except tk .NotAuthorized :
509+ tk .abort (403 , tk ._ ("Unauthorized to edit user %s" ) % id )
510+ except tk .ObjectNotFound :
511+ tk .abort (404 , tk ._ ("User not found" ))
512+ except tk .ValidationError as e :
513+ errors = e .error_dict
514+ error_summary = e .error_summary
515+ # the user state was deleted, we are trying to reactivate it but
516+ # validation error happens so we want to change back the state
517+ # to deleted, as it was before
518+ if is_deleted and data_dict .get ("state" ) == "active" :
519+ data_dict ["state" ] = "deleted"
520+ return self .get (id , data_dict , errors , error_summary )
536521
522+ tk .h .flash_success (tk ._ ("Profile updated" ))
537523
538- def _reset_redirect ():
539- return tk . abort ( 404 , tk . _ ( "Not found" ))
524+ resp = tk . h . redirect_to ( "user.read" , id = user [ "name" ])
525+ return resp
540526
541527
528+ def _reset_redirect ():
529+ return tk .abort (404 , tk ._ ("Not found" ))
542530
543531
544532def institution_autocomplete ():
0 commit comments