示例#1
0
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
示例#2
0
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
示例#3
0
    def check_auth(self):
        if self.project.is_public() and not self.is_write():
            return None
        # Check if user have been already authorized or ask to
        self.request.user = basic_auth(self.request)
        if self.request.user is None:
            return ask_basic_auth(self.request,
                realm=self.project.config.basic_realm)

        if self.project.is_public() and self.is_write() and not\
            self.request.user.has_perm('can_write_to_repository', self.project):
            raise PermissionDenied

        if self.project.is_private() and not\
            self.request.user.has_perm('can_read_repository', self.project):
            raise PermissionDenied
        if self.project.is_private() and self.is_write() and not\
            self.request.user.has_perm('can_write_to_repository', self.project):
            raise PermissionDenied
        return
示例#4
0
    def check_auth(self):
        if self.project.is_public() and not self.is_write():
            return None
        # Check if user have been already authorized or ask to
        self.request.user = basic_auth(self.request)
        if self.request.user is None:
            return ask_basic_auth(self.request,
                                  realm=self.project.config.basic_realm)

        if self.project.is_public() and self.is_write() and not\
            self.request.user.has_perm('can_write_to_repository', self.project):
            raise PermissionDenied

        if self.project.is_private() and not\
            self.request.user.has_perm('can_read_repository', self.project):
            raise PermissionDenied
        if self.project.is_private() and self.is_write() and not\
            self.request.user.has_perm('can_write_to_repository', self.project):
            raise PermissionDenied
        return