##// END OF EJS Templates
API added checks for a valid repository on pull command...
marcink -
r1508:4aba7be3 beta
parent child Browse files
Show More
@@ -30,6 +30,7 b' import json'
30 import logging
30 import logging
31 import types
31 import types
32 import urllib
32 import urllib
33 import traceback
33 from itertools import izip_longest
34 from itertools import izip_longest
34
35
35 from paste.response import replace_header
36 from paste.response import replace_header
@@ -135,8 +136,9 b' class JSONRPCController(WSGIController):'
135 # self.kargs and dispatch control to WGIController
136 # self.kargs and dispatch control to WGIController
136 argspec = inspect.getargspec(self._func)
137 argspec = inspect.getargspec(self._func)
137 arglist = argspec[0][1:]
138 arglist = argspec[0][1:]
138 defaults = argspec[3]
139 defaults = argspec[3] or []
139 default_empty = types.NotImplementedType
140 default_empty = types.NotImplementedType
141
140 kwarglist = list(izip_longest(reversed(arglist),reversed(defaults),
142 kwarglist = list(izip_longest(reversed(arglist),reversed(defaults),
141 fillvalue=default_empty))
143 fillvalue=default_empty))
142
144
@@ -202,7 +204,7 b' class JSONRPCController(WSGIController):'
202 except JSONRPCError as e:
204 except JSONRPCError as e:
203 self._error = str(e)
205 self._error = str(e)
204 except Exception as e:
206 except Exception as e:
205 log.debug('Encountered unhandled exception: %s', repr(e))
207 log.error('Encountered unhandled exception: %s' % traceback.format_exc())
206 json_exc = JSONRPCError('Internal server error')
208 json_exc = JSONRPCError('Internal server error')
207 self._error = str(json_exc)
209 self._error = str(json_exc)
208
210
@@ -5,7 +5,7 b' from rhodecode.controllers.api import JS'
5 from rhodecode.lib.auth import HasPermissionAllDecorator
5 from rhodecode.lib.auth import HasPermissionAllDecorator
6 from rhodecode.model.scm import ScmModel
6 from rhodecode.model.scm import ScmModel
7
7
8 from rhodecode.model.db import User, UsersGroup
8 from rhodecode.model.db import User, UsersGroup, Repository
9
9
10 log = logging.getLogger(__name__)
10 log = logging.getLogger(__name__)
11
11
@@ -36,6 +36,9 b' class ApiController(JSONRPCController):'
36 :param repo:
36 :param repo:
37 """
37 """
38
38
39 if Repository.is_valid(repo) is False:
40 raise JSONRPCError('Unknown repo "%s"' % repo)
41
39 try:
42 try:
40 ScmModel().pull_changes(repo, self.rhodecode_user.username)
43 ScmModel().pull_changes(repo, self.rhodecode_user.username)
41 return 'Pulled from %s' % repo
44 return 'Pulled from %s' % repo
@@ -499,6 +499,17 b' class Repository(Base, BaseModel):'
499 def get_repo_forks(cls, repo_id):
499 def get_repo_forks(cls, repo_id):
500 return Session.query(cls).filter(Repository.fork_id == repo_id)
500 return Session.query(cls).filter(Repository.fork_id == repo_id)
501
501
502 @classmethod
503 def base_path(cls):
504 """
505 Returns base path when all repos are stored
506
507 :param cls:
508 """
509 q = Session.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == '/')
510 q.options(FromCache("sql_cache_short", "repository_repo_path"))
511 return q.one().ui_value
512
502 @property
513 @property
503 def just_name(self):
514 def just_name(self):
504 return self.repo_name.split(os.sep)[-1]
515 return self.repo_name.split(os.sep)[-1]
@@ -570,6 +581,19 b' class Repository(Base, BaseModel):'
570
581
571 return baseui
582 return baseui
572
583
584 @classmethod
585 def is_valid(cls, repo_name):
586 """
587 returns True if given repo name is a valid filesystem repository
588
589 @param cls:
590 @param repo_name:
591 """
592 from rhodecode.lib.utils import is_valid_repo
593
594 return is_valid_repo(repo_name, cls.base_path())
595
596
573 #==========================================================================
597 #==========================================================================
574 # SCM PROPERTIES
598 # SCM PROPERTIES
575 #==========================================================================
599 #==========================================================================
@@ -307,6 +307,10 b' class ScmModel(BaseModel):'
307
307
308 def pull_changes(self, repo_name, username):
308 def pull_changes(self, repo_name, username):
309 dbrepo = Repository.by_repo_name(repo_name)
309 dbrepo = Repository.by_repo_name(repo_name)
310 clone_uri = dbrepo.clone_uri
311 if not clone_uri:
312 raise Exception("This repository doesn't have a clone uri")
313
310 repo = dbrepo.scm_instance
314 repo = dbrepo.scm_instance
311 try:
315 try:
312 extras = {'ip': '',
316 extras = {'ip': '',
@@ -318,13 +322,12 b' class ScmModel(BaseModel):'
318 for k, v in extras.items():
322 for k, v in extras.items():
319 repo._repo.ui.setconfig('rhodecode_extras', k, v)
323 repo._repo.ui.setconfig('rhodecode_extras', k, v)
320
324
321 repo.pull(dbrepo.clone_uri)
325 repo.pull(clone_uri)
322 self.mark_for_invalidation(repo_name)
326 self.mark_for_invalidation(repo_name)
323 except:
327 except:
324 log.error(traceback.format_exc())
328 log.error(traceback.format_exc())
325 raise
329 raise
326
330
327
328 def commit_change(self, repo, repo_name, cs, user, author, message, content,
331 def commit_change(self, repo, repo_name, cs, user, author, message, content,
329 f_path):
332 f_path):
330
333
General Comments 0
You need to be logged in to leave comments. Login now