##// END OF EJS Templates
added clone_uri to API method for creating users
added clone_uri to API method for creating users

File last commit:

r1978:164199e4 beta
r2006:34d009e5 beta
Show More
base.py
180 lines | 6.4 KiB | text/x-python | PythonLexer
renamed project to rhodecode
r547 """The base Controller API
Provides the BaseController class for subclassing.
"""
Fixes issue #201...
r1373 import logging
Added Request time tracking
r1601 import time
implements #285: Implemented non changeable urls for clone url, and web views
r1813 import traceback
Wrapped calls for git and hg middleware in extra block that clears db Session....
r1761
from paste.auth.basic import AuthBasicAuthenticator
Fixes issue #201...
r1373 from pylons import config, tmpl_context as c, request, session, url
renamed project to rhodecode
r547 from pylons.controllers import WSGIController
Fixes issue #201...
r1373 from pylons.controllers.util import redirect
renamed project to rhodecode
r547 from pylons.templating import render_mako as render
gui-improvments
r1304
reduce cookie size for better support of client side sessions
r1718 from rhodecode import __version__, BACKENDS
implements #293 gravatar link should be disabled when use_gravatar = false
r1629 from rhodecode.lib import str2bool
Wrapped calls for git and hg middleware in extra block that clears db Session....
r1761 from rhodecode.lib.auth import AuthUser, get_container_username, authfunc,\
HasPermissionAnyMiddleware
from rhodecode.lib.utils import get_repo_slug, invalidate_cache
renamed project to rhodecode
r547 from rhodecode.model import meta
reduce cookie size for better support of client side sessions
r1718
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached...
r1366 from rhodecode.model.db import Repository
#302 - basic notification system, models+tests
r1702 from rhodecode.model.notification import NotificationModel
reduce cookie size for better support of client side sessions
r1718 from rhodecode.model.scm import ScmModel
Moved out reposcan into hg Model....
r665
Fixes issue #201...
r1373 log = logging.getLogger(__name__)
pep8ify
r1307
implements #285: Implemented non changeable urls for clone url, and web views
r1813
Wrapped calls for git and hg middleware in extra block that clears db Session....
r1761 class BaseVCSController(object):
implements #285: Implemented non changeable urls for clone url, and web views
r1813
Wrapped calls for git and hg middleware in extra block that clears db Session....
r1761 def __init__(self, application, config):
self.application = application
self.config = config
# base path of repo locations
self.basepath = self.config['base_path']
#authenticate this mercurial request using authfunc
self.authenticate = AuthBasicAuthenticator('', authfunc)
self.ipaddr = '0.0.0.0'
implements #285: Implemented non changeable urls for clone url, and web views
r1813
code garden, pep8
r1978 def _handle_request(self, environ, start_response):
raise NotImplementedError()
implements #285: Implemented non changeable urls for clone url, and web views
r1813 def _get_by_id(self, repo_name):
"""
Get's a special pattern _<ID> from clone url and tries to replace it
with a repository_name for support of _<ID> non changable urls
:param repo_name:
"""
try:
data = repo_name.split('/')
if len(data) >= 2:
by_id = data[1].split('_')
if len(by_id) == 2 and by_id[1].isdigit():
_repo_name = Repository.get(by_id[1]).repo_name
data[1] = _repo_name
except:
log.debug('Failed to extract repo_name from id %s' % (
traceback.format_exc()
)
)
return '/'.join(data)
Wrapped calls for git and hg middleware in extra block that clears db Session....
r1761 def _invalidate_cache(self, repo_name):
"""
Set's cache for this repository for invalidation on next access
implements #285: Implemented non changeable urls for clone url, and web views
r1813
Wrapped calls for git and hg middleware in extra block that clears db Session....
r1761 :param repo_name: full repo name, also a cache key
"""
invalidate_cache('get_repo_cached_%s' % repo_name)
implements #285: Implemented non changeable urls for clone url, and web views
r1813
Wrapped calls for git and hg middleware in extra block that clears db Session....
r1761 def _check_permission(self, action, user, repo_name):
"""
Checks permissions using action (push/pull) user and repository
name
:param action: push or pull action
:param user: user instance
:param repo_name: repository name
"""
if action == 'push':
if not HasPermissionAnyMiddleware('repository.write',
'repository.admin')(user,
repo_name):
return False
else:
#any other action need at least read permission
if not HasPermissionAnyMiddleware('repository.read',
'repository.write',
'repository.admin')(user,
repo_name):
return False
implements #285: Implemented non changeable urls for clone url, and web views
r1813 return True
Wrapped calls for git and hg middleware in extra block that clears db Session....
r1761 def __call__(self, environ, start_response):
start = time.time()
try:
return self._handle_request(environ, start_response)
finally:
logger name update
r1763 log = logging.getLogger('rhodecode.' + self.__class__.__name__)
Wrapped calls for git and hg middleware in extra block that clears db Session....
r1761 log.debug('Request time: %.3fs' % (time.time() - start))
meta.Session.remove()
renamed project to rhodecode
r547 class BaseController(WSGIController):
extended repo creation by repo type. fixed fork creation to maintain repo type.
r659
renamed project to rhodecode
r547 def __before__(self):
renamed hg_app to rhodecode
r548 c.rhodecode_version = __version__
implemented #89 google analytics code
r890 c.rhodecode_name = config.get('rhodecode_title')
implements #293 gravatar link should be disabled when use_gravatar = false
r1629 c.use_gravatar = str2bool(config.get('use_gravatar'))
fixes for #89 ga code
r891 c.ga_code = config.get('rhodecode_ga_code')
renamed project to rhodecode
r547 c.repo_name = get_repo_slug(request)
extended repo creation by repo type. fixed fork creation to maintain repo type.
r659 c.backends = BACKENDS.keys()
#302 - basic notification system, models+tests
r1702 c.unread_notifications = NotificationModel()\
.get_unread_cnt_for_user(c.rhodecode_user.user_id)
implemented #89 google analytics code
r890 self.cut_off_limit = int(config.get('cut_off_limit'))
Major refactoring, removed when possible calls to app globals....
r1036
commit less models...
r1749 self.sa = meta.Session
another major codes rewrite:...
r1045 self.scm_model = ScmModel(self.sa)
fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached...
r1366
renamed project to rhodecode
r547 def __call__(self, environ, start_response):
"""Invoke the Controller"""
# WSGIController.__call__ dispatches to the Controller method
# the request is routed to. This routing information is
# available in environ['pylons.routes_dict']
Added Request time tracking
r1601 start = time.time()
renamed project to rhodecode
r547 try:
Some code cleanups and fixes
r1628 # make sure that we update permissions each time we call controller
Major rewrite of auth objects. Moved parts of filling user data into user model....
r1117 api_key = request.GET.get('api_key')
reduce cookie size for better support of client side sessions
r1718 cookie_store = session.get('rhodecode_user') or {}
user_id = cookie_store.get('user_id', None)
Liad Shani
Improved container-based auth support for middleware
r1630 username = get_container_username(environ, config)
Some code cleanups and fixes
r1628 auth_user = AuthUser(user_id, api_key, username)
- fixes celery sqlalchemy session issues for async forking...
r1728 request.user = auth_user
Some code cleanups and fixes
r1628 self.rhodecode_user = c.rhodecode_user = auth_user
Liad Shani
Added automatic logout of deactivated/deleted users
r1618 if not self.rhodecode_user.is_authenticated and \
self.rhodecode_user.user_id is not None:
reduce cookie size for better support of client side sessions
r1718 self.rhodecode_user\
.set_authenticated(cookie_store.get('is_authenticated'))
session['rhodecode_user'] = self.rhodecode_user.get_cookie_store()
Major rewrite of auth objects. Moved parts of filling user data into user model....
r1117 session.save()
renamed project to rhodecode
r547 return WSGIController.__call__(self, environ, start_response)
finally:
reduce cookie size for better support of client side sessions
r1718 log.debug('Request time: %.3fs' % (time.time() - start))
renamed project to rhodecode
r547 meta.Session.remove()
another major codes rewrite:...
r1045
class BaseRepoController(BaseController):
"""
Some code cleanups and fixes
r1628 Base class for controllers responsible for loading all needed data for
repository loaded items are
source code cleanup: remove trailing white space, normalize file endings
r1203
Some code cleanups and fixes
r1628 c.rhodecode_repo: instance of scm repository
c.rhodecode_db_repo: instance of db
c.repository_followers: number of followers
c.repository_forks: number of forks
another major codes rewrite:...
r1045 """
def __before__(self):
super(BaseRepoController, self).__before__()
if c.repo_name:
Refactoring of model get functions
r1530 c.rhodecode_db_repo = Repository.get_by_repo_name(c.repo_name)
Fixes issue #201...
r1373 c.rhodecode_repo = c.rhodecode_db_repo.scm_instance
if c.rhodecode_repo is None:
log.error('%s this repository is present in database but it '
'cannot be created as an scm instance', c.repo_name)
fixed condition evaluated for gitrepo that returned null, simplified scm functions
r1282
Fixes issue #201...
r1373 redirect(url('home'))
gui-improvments
r1304
Some code cleanups and fixes
r1628 c.repository_followers = self.scm_model.get_followers(c.repo_name)
Fixes issue #201...
r1373 c.repository_forks = self.scm_model.get_forks(c.repo_name)