Changeset - bdc0ad168006
[Not reviewed]
beta
0 2 0
Marcin Kuzminski - 14 years ago 2012-02-19 19:00:18
marcin@python-works.com
API added explicit method for updating user account
2 files changed with 66 insertions and 3 deletions:
0 comments (0 inline, 0 general)
docs/api/api.rst
Show inline comments
 
@@ -151,7 +151,7 @@ OUTPUT::
 
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 @@ OUTPUT::
 
    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
 
---------------
 

	
rhodecode/controllers/api/api.py
Show inline comments
 
@@ -134,7 +134,7 @@ class ApiController(JSONRPCController):
 
    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 @@ class ApiController(JSONRPCController):
 
        :param admin:
 
        :param ldap_dn:
 
        """
 

	
 
        if User.get_by_username(username):
 
            raise JSONRPCError("user %s already exist" % username)
 

	
 
@@ -165,6 +164,39 @@ class ApiController(JSONRPCController):
 
            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
0 comments (0 inline, 0 general)