def get_required_perms(self): """ Returns empty list if request is identified as *mercurial request*. For mercurial requests lets underlying view to manage permissions checks. """ if is_mercurial(self.request): return [] return super(ProjectDetailView, self).get_required_perms()
def _project_detail_hg(request, project): """ Wrapper for vcs.web.simplevcs.views.hgserve view as before we go any further we need to check permissions. TODO: Should use higher level simplevcs method """ if not is_mercurial(request): msg = "_project_detail_hg called for non mercurial request" logging.error(msg) raise NotMercurialRequest(msg) if request.method not in ('GET', 'POST'): raise NotMercurialRequest("Only GET/POST methods are allowed, got %s" % request.method) PUSH_SSL = get_config_value('HG_PUSH_SSL') and 'true' or 'false' # Allow to read from public projects if project.is_public() and request.method == 'GET': mercurial_info = { 'repo_path': project._get_repo_path(), 'push_ssl': PUSH_SSL, } return get_mercurial_response(request, **mercurial_info) # Check if user have been already authorized or ask to request.user = basic_auth(request) if request.user is None: return ask_basic_auth(request, realm=project.config.basic_realm) if project.is_private() and request.method == 'GET' and\ not request.user.has_perm('can_read_repository', project): raise PermissionDenied("User %s cannot read repository for " "project %s" % (request.user, project)) elif request.method == 'POST' and\ not request.user.has_perm('can_write_to_repository',project): raise PermissionDenied("User %s cannot write to repository " "for project %s" % (request.user, project)) mercurial_info = { 'repo_path': project._get_repo_path(), 'push_ssl': PUSH_SSL, } if request.user and request.user.is_active: mercurial_info['allow_push'] = request.user.username response = get_mercurial_response(request, **mercurial_info) return response
def response(self, request, username, project_slug): try: if is_mercurial(request): return self.response_hg(request, self.project) last_part = request.path.split('/')[-1] if last_part and last_part != project_slug: raise Http404("Not a mercurial request and path longer than " " should be: %s" % request.path) # project is injected into the context at ProjectView constructor # so we do not need to add it here return self.context except Exception, err: dont_log_exceptions = (PermissionDenied, ) if not isinstance(err, dont_log_exceptions): log_error(err) raise err
def response(self, request, username, project_slug): try: if is_mercurial(request): return self.response_hg(request, self.project) last_part = request.path.split('/')[-1] if last_part and last_part != project_slug: raise Http404("Not a mercurial request and path longer than " " should be: %s" % request.path) # project is injected into the context at ProjectView constructor # so we do not need to add it here return self.context except Exception, err: dont_log_exceptions = (PermissionDenied,) if not isinstance(err, dont_log_exceptions): log_error(err) raise err