示例#1
0
    def show_my(self):
        c.closed = request.GET.get('closed') or ''

        c.my_pull_requests = PullRequest.query(
            include_closed=c.closed,
            sorted=True,
        ).filter_by(owner_id=request.authuser.user_id).all()

        c.participate_in_pull_requests = []
        c.participate_in_pull_requests_todo = []
        done_status = set(
            [ChangesetStatus.STATUS_APPROVED, ChangesetStatus.STATUS_REJECTED])
        for pr in PullRequest.query(
                include_closed=c.closed,
                reviewer_id=request.authuser.user_id,
                sorted=True,
        ):
            status = pr.user_review_status(
                request.authuser.user_id)  # very inefficient!!!
            if status in done_status:
                c.participate_in_pull_requests.append(pr)
            else:
                c.participate_in_pull_requests_todo.append(pr)

        return render('/pullrequests/pullrequest_show_my.html')
示例#2
0
    def _before(self, *args, **kwargs):
        """
        _before is called before controller methods and after __call__
        """
        c.kallithea_version = __version__
        rc_config = Setting.get_app_settings()

        # Visual options
        c.visual = AttributeDict({})

        ## DB stored
        c.visual.show_public_icon = str2bool(rc_config.get('show_public_icon'))
        c.visual.show_private_icon = str2bool(rc_config.get('show_private_icon'))
        c.visual.stylify_metatags = str2bool(rc_config.get('stylify_metatags'))
        c.visual.page_size = safe_int(rc_config.get('dashboard_items', 100))
        c.visual.admin_grid_items = safe_int(rc_config.get('admin_grid_items', 100))
        c.visual.repository_fields = str2bool(rc_config.get('repository_fields'))
        c.visual.show_version = str2bool(rc_config.get('show_version'))
        c.visual.use_gravatar = str2bool(rc_config.get('use_gravatar'))
        c.visual.gravatar_url = rc_config.get('gravatar_url')

        c.ga_code = rc_config.get('ga_code')
        # TODO: replace undocumented backwards compatibility hack with db upgrade and rename ga_code
        if c.ga_code and '<' not in c.ga_code:
            c.ga_code = '''<script type="text/javascript">
                var _gaq = _gaq || [];
                _gaq.push(['_setAccount', '%s']);
                _gaq.push(['_trackPageview']);

                (function() {
                    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
                    })();
            </script>''' % c.ga_code
        c.site_name = rc_config.get('title')
        c.clone_uri_tmpl = rc_config.get('clone_uri_tmpl')

        ## INI stored
        c.visual.allow_repo_location_change = str2bool(config.get('allow_repo_location_change', True))
        c.visual.allow_custom_hooks_settings = str2bool(config.get('allow_custom_hooks_settings', True))

        c.instance_id = config.get('instance_id')
        c.issues_url = config.get('bugtracker', url('issues_url'))
        # END CONFIG VARS

        c.repo_name = get_repo_slug(request)  # can be empty
        c.backends = BACKENDS.keys()
        c.unread_notifications = NotificationModel() \
                        .get_unread_cnt_for_user(request.authuser.user_id)

        self.cut_off_limit = safe_int(config.get('cut_off_limit'))

        c.my_pr_count = PullRequest.query(reviewer_id=request.authuser.user_id, include_closed=False).count()

        self.scm_model = ScmModel()
示例#3
0
    def show_my(self):
        c.closed = request.GET.get('closed') or ''

        def _filter(pr):
            s = sorted(pr, key=lambda o: o.created_on, reverse=True)
            if not c.closed:
                s = filter(lambda p: p.status != PullRequest.STATUS_CLOSED, s)
            return s

        c.my_pull_requests = _filter(PullRequest.query() \
                                .filter(PullRequest.user_id ==
                                        self.authuser.user_id) \
                                .all())

        c.participate_in_pull_requests = _filter(PullRequest.query() \
                                .join(PullRequestReviewers) \
                                .filter(PullRequestReviewers.user_id ==
                                        self.authuser.user_id) \
                                                 )

        return render('/pullrequests/pullrequest_show_my.html')
示例#4
0
    def show_my(self):
        c.closed = request.GET.get('closed') or ''

        def _filter(pr):
            s = sorted(pr, key=lambda o: o.created_on, reverse=True)
            if not c.closed:
                s = filter(lambda p: p.status != PullRequest.STATUS_CLOSED, s)
            return s

        c.my_pull_requests = _filter(PullRequest.query()\
                                .filter(PullRequest.user_id ==
                                        self.authuser.user_id)\
                                .all())

        c.participate_in_pull_requests = _filter(PullRequest.query()\
                                .join(PullRequestReviewers)\
                                .filter(PullRequestReviewers.user_id ==
                                        self.authuser.user_id)\
                                                 )

        return render('/pullrequests/pullrequest_show_my.html')
示例#5
0
 def get_all(self, repo_name, from_=False, closed=False):
     """Get all PRs for repo.
     Default is all PRs to the repo, PRs from the repo if from_.
     Closed PRs are only included if closed is true."""
     repo = self._get_repo(repo_name)
     q = PullRequest.query()
     if from_:
         q = q.filter(PullRequest.org_repo == repo)
     else:
         q = q.filter(PullRequest.other_repo == repo)
     if not closed:
         q = q.filter(PullRequest.status != PullRequest.STATUS_CLOSED)
     return q.order_by(PullRequest.created_on.desc()).all()
示例#6
0
    def show_my(self):
        c.closed = request.GET.get('closed') or ''

        c.my_pull_requests = PullRequest.query(
            include_closed=c.closed,
            sorted=True,
        ).filter_by(owner_id=request.authuser.user_id).all()

        c.participate_in_pull_requests = []
        c.participate_in_pull_requests_todo = []
        done_status = set([ChangesetStatus.STATUS_APPROVED, ChangesetStatus.STATUS_REJECTED])
        for pr in PullRequest.query(
            include_closed=c.closed,
            reviewer_id=request.authuser.user_id,
            sorted=True,
        ):
            status = pr.user_review_status(request.authuser.user_id) # very inefficient!!!
            if status in done_status:
                c.participate_in_pull_requests.append(pr)
            else:
                c.participate_in_pull_requests_todo.append(pr)

        return render('/pullrequests/pullrequest_show_my.html')
示例#7
0
    def show_all(self, repo_name):
        c.from_ = request.GET.get('from_') or ''
        c.closed = request.GET.get('closed') or ''
        p = safe_int(request.GET.get('page'), 1)

        q = PullRequest.query(include_closed=c.closed, sorted=True)
        if c.from_:
            q = q.filter_by(org_repo=c.db_repo)
        else:
            q = q.filter_by(other_repo=c.db_repo)
        c.pull_requests = q.all()

        c.pullrequests_pager = Page(c.pull_requests, page=p, items_per_page=100)

        return render('/pullrequests/pullrequest_show_all.html')
示例#8
0
 def get_pullrequest_cnt_for_user(self, user):
     return PullRequest.query()\
                             .join(PullRequestReviewers)\
                             .filter(PullRequestReviewers.user_id == user)\
                             .filter(PullRequest.status != PullRequest.STATUS_CLOSED)\
                             .count()
示例#9
0
 def get_pull_requests(self, repo):
     repo = Repository.guess_instance(repo)
     return PullRequest.query() \
             .filter(PullRequest.other_repo == repo) \
             .filter(PullRequest.status != PullRequest.STATUS_CLOSED).count()
示例#10
0
    def _before(self, *args, **kwargs):
        """
        _before is called before controller methods and after __call__
        """
        if request.needs_csrf_check:
            # CSRF protection: Whenever a request has ambient authority (whether
            # through a session cookie or its origin IP address), it must include
            # the correct token, unless the HTTP method is GET or HEAD (and thus
            # guaranteed to be side effect free. In practice, the only situation
            # where we allow side effects without ambient authority is when the
            # authority comes from an API key; and that is handled above.
            from kallithea.lib import helpers as h
            token = request.POST.get(h.session_csrf_secret_name)
            if not token or token != h.session_csrf_secret_token():
                log.error('CSRF check failed')
                raise webob.exc.HTTPForbidden()

        c.kallithea_version = __version__
        rc_config = Setting.get_app_settings()

        # Visual options
        c.visual = AttributeDict({})

        ## DB stored
        c.visual.show_public_icon = str2bool(rc_config.get('show_public_icon'))
        c.visual.show_private_icon = str2bool(
            rc_config.get('show_private_icon'))
        c.visual.stylify_metalabels = str2bool(
            rc_config.get('stylify_metalabels'))
        c.visual.page_size = safe_int(rc_config.get('dashboard_items', 100))
        c.visual.admin_grid_items = safe_int(
            rc_config.get('admin_grid_items', 100))
        c.visual.repository_fields = str2bool(
            rc_config.get('repository_fields'))
        c.visual.show_version = str2bool(rc_config.get('show_version'))
        c.visual.use_gravatar = str2bool(rc_config.get('use_gravatar'))
        c.visual.gravatar_url = rc_config.get('gravatar_url')

        c.ga_code = rc_config.get('ga_code')
        # TODO: replace undocumented backwards compatibility hack with db upgrade and rename ga_code
        if c.ga_code and '<' not in c.ga_code:
            c.ga_code = '''<script type="text/javascript">
                var _gaq = _gaq || [];
                _gaq.push(['_setAccount', '%s']);
                _gaq.push(['_trackPageview']);

                (function() {
                    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
                    })();
            </script>''' % c.ga_code
        c.site_name = rc_config.get('title')
        c.clone_uri_tmpl = rc_config.get(
            'clone_uri_tmpl') or Repository.DEFAULT_CLONE_URI
        c.clone_ssh_tmpl = rc_config.get(
            'clone_ssh_tmpl') or Repository.DEFAULT_CLONE_SSH

        ## INI stored
        c.visual.allow_repo_location_change = str2bool(
            config.get('allow_repo_location_change', True))
        c.visual.allow_custom_hooks_settings = str2bool(
            config.get('allow_custom_hooks_settings', True))
        c.ssh_enabled = str2bool(config.get('ssh_enabled', False))

        c.instance_id = config.get('instance_id')
        c.issues_url = config.get('bugtracker', url('issues_url'))
        # END CONFIG VARS

        c.repo_name = get_repo_slug(request)  # can be empty
        c.backends = list(BACKENDS)

        self.cut_off_limit = safe_int(config.get('cut_off_limit'))

        c.my_pr_count = PullRequest.query(reviewer_id=request.authuser.user_id,
                                          include_closed=False).count()

        self.scm_model = ScmModel()