Mercurial > kallithea
changeset 2002:bdc0ad168006 beta
API added explicit method for updating user account
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 19 Feb 2012 20:00:18 +0200 |
parents | 93d4e3eb7d84 |
children | 7dfcdf4c7dd2 |
files | docs/api/api.rst rhodecode/controllers/api/api.py |
diffstat | 2 files changed, 66 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/docs/api/api.rst Sun Feb 19 19:36:42 2012 +0200 +++ b/docs/api/api.rst Sun Feb 19 20:00:18 2012 +0200 @@ -151,7 +151,7 @@ create_user ----------- -Creates new user or updates current one if such user exists. This command can +Creates new user. This command can be executed only using api_key belonging to user with admin rights. @@ -179,6 +179,37 @@ error: null +update_user +----------- + +updates current one if such user exists. This command can +be executed only using api_key belonging to user with admin rights. + + +INPUT:: + + api_key : "<api_key>" + method : "update_user" + args : { + "username" : "<username>", + "password" : "<password>", + "email" : "<useremail>", + "firstname" : "<firstname> = None", + "lastname" : "<lastname> = None", + "active" : "<bool> = True", + "admin" : "<bool> = False", + "ldap_dn" : "<ldap_dn> = None" + } + +OUTPUT:: + + result: { + "id" : "<edited_user_id>", + "msg" : "updated user <username>" + } + error: null + + get_users_group ---------------
--- a/rhodecode/controllers/api/api.py Sun Feb 19 19:36:42 2012 +0200 +++ b/rhodecode/controllers/api/api.py Sun Feb 19 20:00:18 2012 +0200 @@ -134,7 +134,7 @@ def create_user(self, apiuser, username, password, email, firstname=None, lastname=None, active=True, admin=False, ldap_dn=None): """ - Create new user or updates current one + Create new user :param apiuser: :param username: @@ -146,7 +146,6 @@ :param admin: :param ldap_dn: """ - if User.get_by_username(username): raise JSONRPCError("user %s already exist" % username) @@ -165,6 +164,39 @@ raise JSONRPCError('failed to create user %s' % username) @HasPermissionAllDecorator('hg.admin') + def update_user(self, apiuser, username, password, email, firstname=None, + lastname=None, active=True, admin=False, ldap_dn=None): + """ + Updates given user + + :param apiuser: + :param username: + :param password: + :param email: + :param name: + :param lastname: + :param active: + :param admin: + :param ldap_dn: + """ + if not User.get_by_username(username): + raise JSONRPCError("user %s does not exist" % username) + + try: + usr = UserModel().create_or_update( + username, password, email, firstname, + lastname, active, admin, ldap_dn + ) + Session.commit() + return dict( + id=usr.user_id, + msg='updated user %s' % username + ) + except Exception: + log.error(traceback.format_exc()) + raise JSONRPCError('failed to update user %s' % username) + + @HasPermissionAllDecorator('hg.admin') def get_users_group(self, apiuser, group_name): """" Get users group by name