Changeset - 14dffcfebb02
[Not reviewed]
beta
0 3 0
Marcin Kuzminski - 14 years ago 2012-02-21 01:51:28
marcin@python-works.com
API get_user and get_repo methods can fetch by id or names
3 files changed with 12 insertions and 9 deletions:
0 comments (0 inline, 0 general)
docs/api/api.rst
Show inline comments
 
@@ -87,7 +87,7 @@ OUTPUT::
 
get_user
 
--------
 

	
 
Get's an user by username, Returns empty result if user is not found.
 
Get's an user by username or user_id, Returns empty result if user is not found.
 
This command can be executed only using api_key belonging to user with admin 
 
rights.
 

	
 
@@ -97,7 +97,7 @@ INPUT::
 
    api_key : "<api_key>"
 
    method :  "get_user"
 
    args :    { 
 
                "username" : "<username>"
 
                "userid" : "<username or user_id>"
 
              }
 

	
 
OUTPUT::
 
@@ -370,8 +370,8 @@ OUTPUT::
 
get_repo
 
--------
 

	
 
Gets an existing repository. This command can be executed only using api_key
 
belonging to user with admin rights
 
Gets an existing repository by it's name or repository_id. This command can 
 
be executed only using api_key belonging to user with admin rights.
 

	
 

	
 
INPUT::
 
@@ -379,7 +379,7 @@ INPUT::
 
    api_key : "<api_key>"
 
    method :  "get_repo"
 
    args:     {
 
                "repo_name" : "<reponame>"
 
                "repoid" : "<reponame or repo_id>"
 
              }
 

	
 
OUTPUT::
rhodecode/controllers/api/api.py
Show inline comments
 
@@ -80,7 +80,7 @@ class ApiController(JSONRPCController):
 
            raise JSONRPCError('Unable to pull changes from "%s"' % repo_name)
 

	
 
    @HasPermissionAllDecorator('hg.admin')
 
    def get_user(self, apiuser, username):
 
    def get_user(self, apiuser, userid):
 
        """"
 
        Get a user by username
 

	
 
@@ -88,7 +88,7 @@ class ApiController(JSONRPCController):
 
        :param username:
 
        """
 

	
 
        user = User.get_by_username(username)
 
        user = UserModel().get_user(userid)
 
        if user is None:
 
            return user
 

	
 
@@ -342,7 +342,7 @@ class ApiController(JSONRPCController):
 
            raise JSONRPCError('failed to remove user from group')
 

	
 
    @HasPermissionAnyDecorator('hg.admin')
 
    def get_repo(self, apiuser, repo_name):
 
    def get_repo(self, apiuser, repoid):
 
        """"
 
        Get repository by name
 

	
 
@@ -350,7 +350,7 @@ class ApiController(JSONRPCController):
 
        :param repo_name:
 
        """
 

	
 
        repo = Repository.get_by_repo_name(repo_name)
 
        repo = RepoModel().get_repo(repoid)
 
        if repo is None:
 
            raise JSONRPCError('unknown repository %s' % repo)
 

	
rhodecode/model/repo.py
Show inline comments
 
@@ -82,6 +82,9 @@ class RepoModel(BaseModel):
 
                                          "get_repo_%s" % repo_id))
 
        return repo.scalar()
 

	
 
    def get_repo(self, repository):
 
        return self.__get_repo(repository)
 

	
 
    def get_by_repo_name(self, repo_name, cache=False):
 
        repo = self.sa.query(Repository)\
 
            .filter(Repository.repo_name == repo_name)
0 comments (0 inline, 0 general)