Commits

Marcin Kuzminski committed 14dffcf

API get_user and get_repo methods can fetch by id or names

Comments (0)

Files changed (3)

 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.
 
     api_key : "<api_key>"
     method :  "get_user"
     args :    { 
-                "username" : "<username>"
+                "userid" : "<username or user_id>"
               }
 
 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::
     api_key : "<api_key>"
     method :  "get_repo"
     args:     {
-                "repo_name" : "<reponame>"
+                "repoid" : "<reponame or repo_id>"
               }
 
 OUTPUT::

rhodecode/controllers/api/api.py

             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
 
         :param username:
         """
 
-        user = User.get_by_username(username)
+        user = UserModel().get_user(userid)
         if user is None:
             return user
 
             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
 
         :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

                                           "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)