diff --git a/rhodecode/controllers/api/__init__.py b/rhodecode/controllers/api/__init__.py --- a/rhodecode/controllers/api/__init__.py +++ b/rhodecode/controllers/api/__init__.py @@ -30,6 +30,7 @@ import json import logging import types import urllib +import traceback from itertools import izip_longest from paste.response import replace_header @@ -135,8 +136,9 @@ class JSONRPCController(WSGIController): # self.kargs and dispatch control to WGIController argspec = inspect.getargspec(self._func) arglist = argspec[0][1:] - defaults = argspec[3] + defaults = argspec[3] or [] default_empty = types.NotImplementedType + kwarglist = list(izip_longest(reversed(arglist),reversed(defaults), fillvalue=default_empty)) @@ -202,7 +204,7 @@ class JSONRPCController(WSGIController): except JSONRPCError as e: self._error = str(e) except Exception as e: - log.debug('Encountered unhandled exception: %s', repr(e)) + log.error('Encountered unhandled exception: %s' % traceback.format_exc()) json_exc = JSONRPCError('Internal server error') self._error = str(json_exc) diff --git a/rhodecode/controllers/api/api.py b/rhodecode/controllers/api/api.py --- a/rhodecode/controllers/api/api.py +++ b/rhodecode/controllers/api/api.py @@ -5,7 +5,7 @@ from rhodecode.controllers.api import JS from rhodecode.lib.auth import HasPermissionAllDecorator from rhodecode.model.scm import ScmModel -from rhodecode.model.db import User, UsersGroup +from rhodecode.model.db import User, UsersGroup, Repository log = logging.getLogger(__name__) @@ -36,6 +36,9 @@ class ApiController(JSONRPCController): :param repo: """ + if Repository.is_valid(repo) is False: + raise JSONRPCError('Unknown repo "%s"' % repo) + try: ScmModel().pull_changes(repo, self.rhodecode_user.username) return 'Pulled from %s' % repo diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -499,6 +499,17 @@ class Repository(Base, BaseModel): def get_repo_forks(cls, repo_id): return Session.query(cls).filter(Repository.fork_id == repo_id) + @classmethod + def base_path(cls): + """ + Returns base path when all repos are stored + + :param cls: + """ + q = Session.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == '/') + q.options(FromCache("sql_cache_short", "repository_repo_path")) + return q.one().ui_value + @property def just_name(self): return self.repo_name.split(os.sep)[-1] @@ -570,6 +581,19 @@ class Repository(Base, BaseModel): return baseui + @classmethod + def is_valid(cls, repo_name): + """ + returns True if given repo name is a valid filesystem repository + + @param cls: + @param repo_name: + """ + from rhodecode.lib.utils import is_valid_repo + + return is_valid_repo(repo_name, cls.base_path()) + + #========================================================================== # SCM PROPERTIES #========================================================================== diff --git a/rhodecode/model/scm.py b/rhodecode/model/scm.py --- a/rhodecode/model/scm.py +++ b/rhodecode/model/scm.py @@ -307,6 +307,10 @@ class ScmModel(BaseModel): def pull_changes(self, repo_name, username): dbrepo = Repository.by_repo_name(repo_name) + clone_uri = dbrepo.clone_uri + if not clone_uri: + raise Exception("This repository doesn't have a clone uri") + repo = dbrepo.scm_instance try: extras = {'ip': '', @@ -318,13 +322,12 @@ class ScmModel(BaseModel): for k, v in extras.items(): repo._repo.ui.setconfig('rhodecode_extras', k, v) - repo.pull(dbrepo.clone_uri) + repo.pull(clone_uri) self.mark_for_invalidation(repo_name) except: log.error(traceback.format_exc()) raise - def commit_change(self, repo, repo_name, cs, user, author, message, content, f_path):