MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / update_user

Function update_user

web/pgadmin/tools/user_management/__init__.py:704–738  ·  view source on GitHub ↗

This function is used to update the users.

(uid, data)

Source from the content-addressed store, hash-verified

702
703
704def update_user(uid, data):
705 """
706 This function is used to update the users.
707 """
708
709 usr = User.query.get(uid)
710 if not usr:
711 return False, _("Unable to update user '{0}'").format(uid)
712
713 # Username and email can not be changed for internal users
714 if usr.auth_source == INTERNAL:
715 non_editable_params = ('username', 'email')
716 else:
717 non_editable_params = ('username',)
718
719 for f in non_editable_params:
720 if f in data:
721 return False, _("'{0}' cannot be modified.").format(f)
722
723 try:
724 new_data = validate_user(data)
725 if 'roles' in new_data:
726 new_data['roles'] = [Role.query.get(new_data['roles'])]
727 except Exception as e:
728 return False, str(e)
729
730 try:
731 for k, v in new_data.items():
732 setattr(usr, k, v)
733
734 db.session.commit()
735 except Exception as e:
736 return False, str(e)
737
738 return True, ''
739
740
741def delete_user(uid):

Callers 1

saveFunction · 0.85

Calls 2

validate_userFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected