Changeset - 374693af2849
[Not reviewed]
beta
0 2 0
Marcin Kuzminski - 13 years ago 2012-06-25 23:20:27
marcin@python-works.com
API: update_user returns new updated user data
2 files changed with 25 insertions and 3 deletions:
0 comments (0 inline, 0 general)
docs/api/api.rst
Show inline comments
 
@@ -252,49 +252,60 @@ updates given user if such user exists. 
 
be executed only using api_key belonging to user with admin rights.
 

	
 

	
 
INPUT::
 

	
 
    id : <id_for_response>
 
    api_key : "<api_key>"
 
    method :  "update_user"
 
    args :    {
 
                "userid" : "<user_id or username>",
 
                "username" :  "<username>",
 
                "password" :  "<password>",
 
                "email" :     "<useremail>",
 
                "firstname" : "<firstname>",
 
                "lastname" :  "<lastname>",
 
                "active" :    "<bool>",
 
                "admin" :     "<bool>",
 
                "ldap_dn" :   "<ldap_dn>"
 
              }
 

	
 
OUTPUT::
 

	
 
    result: {
 
              "id" : "<edited_user_id>",
 
              "msg" : "updated user ID:<userid> <username>"
 
              "msg" : "updated user ID:<userid> <username>",
 
              "user": {
 
                "id" :       "<id>",
 
                "username" : "<username>",
 
                "firstname": "<firstname>",
 
                "lastname" : "<lastname>",
 
                "email" :    "<email>",
 
                "active" :   "<bool>",
 
                "admin" :    "<bool>",
 
                "ldap_dn" :  "<ldap_dn>",
 
                "last_login": "<last_login>",
 
              },              
 
            }
 
    error:  null
 

	
 

	
 
delete_user
 
-----------
 

	
 

	
 
deletes givenuser if such user exists. This command can 
 
be executed only using api_key belonging to user with admin rights.
 

	
 

	
 
INPUT::
 

	
 
    id : <id_for_response>
 
    api_key : "<api_key>"
 
    method :  "delete_user"
 
    args :    {
 
                "userid" : "<user_id or username>",
 
              }
 

	
 
OUTPUT::
 

	
 
    result: {
rhodecode/controllers/api/api.py
Show inline comments
 
@@ -181,56 +181,67 @@ class ApiController(JSONRPCController):
 
            log.error(traceback.format_exc())
 
            raise JSONRPCError('failed to create user %s' % username)
 

	
 
    @HasPermissionAllDecorator('hg.admin')
 
    def update_user(self, apiuser, userid, username, password, email,
 
                    firstname, lastname, active, admin, ldap_dn):
 
        """
 
        Updates given user
 

	
 
        :param apiuser:
 
        :param username:
 
        :param password:
 
        :param email:
 
        :param name:
 
        :param lastname:
 
        :param active:
 
        :param admin:
 
        :param ldap_dn:
 
        """
 
        usr = UserModel().get_user(userid)
 
        if not usr:
 
            raise JSONRPCError("user ID:%s does not exist" % userid)
 

	
 
        try:
 
            usr = UserModel().create_or_update(
 
            user = UserModel().create_or_update(
 
                username, password, email, firstname,
 
                lastname, active, admin, ldap_dn
 
            )
 
            Session.commit()
 
            return dict(
 
                id=usr.user_id,
 
                msg='updated user ID:%s %s' % (usr.user_id, usr.username)
 
                msg='updated user ID:%s %s' % (user.user_id, user.username),
 
                user=dict(
 
                    id=user.user_id,
 
                    username=user.username,
 
                    firstname=user.name,
 
                    lastname=user.lastname,
 
                    email=user.email,
 
                    active=user.active,
 
                    admin=user.admin,
 
                    ldap_dn=user.ldap_dn,
 
                    last_login=user.last_login,
 
                )
 
            )
 
        except Exception:
 
            log.error(traceback.format_exc())
 
            raise JSONRPCError('failed to update user %s' % userid)
 

	
 
    @HasPermissionAllDecorator('hg.admin')
 
    def delete_user(self, apiuser, userid):
 
        """"
 
        Deletes an user
 

	
 
        :param apiuser:
 
        """
 
        usr = UserModel().get_user(userid)
 
        if not usr:
 
            raise JSONRPCError("user ID:%s does not exist" % userid)
 

	
 
        try:
 
            UserModel().delete(userid)
 
            Session.commit()
 
            return dict(
 
                id=usr.user_id,
 
                msg='deleted user ID:%s %s' % (usr.user_id, usr.username)
 
            )
 
        except Exception:
0 comments (0 inline, 0 general)