diff --git a/doc/configuration.rst b/doc/configuration.rst index c8009c6..9961ac0 100644 --- a/doc/configuration.rst +++ b/doc/configuration.rst @@ -999,6 +999,20 @@ for all the projects hosted on this pagure instance. Defaults to: ``True`` +ENABLE_TICKETS_NAMESPACE +~~~~~~~~~~~~~~~~~~~~~~~~ + +This configuration key allows to restrict the namespace in which the ticketing +system is enabled. +So if your pagure instance has ``ENABLE_TICKETS`` as ``True`` and sets +``ENABLE_TICKETS_NAMESPACE`` to ``['tests', 'infra']`` only the projects opened +in these two namespaces will have the ticketing system enabled. All the other +namespaces will not. + + +Defaults to: ``[]`` + + ENABLE_DOCS ~~~~~~~~~~~ diff --git a/pagure/api/issue.py b/pagure/api/issue.py index e9d5200..7835460 100644 --- a/pagure/api/issue.py +++ b/pagure/api/issue.py @@ -67,7 +67,12 @@ def _check_issue_tracker(repo): :param repo: repository :raises pagure.exceptions.APIError: when issue tracker is disabled """ - if not repo.settings.get("issue_tracker", True): + ticket_namespaces = pagure_config.get("ENABLE_TICKETS_NAMESPACE") + if ( + ticket_namespaces + and repo.namespace + and repo.namespace not in ticket_namespaces + ) or not repo.settings.get("issue_tracker", True): raise pagure.exceptions.APIError( 404, error_code=APIERROR.ETRACKERDISABLED ) diff --git a/pagure/decorators.py b/pagure/decorators.py index bca63bf..3e6e329 100644 --- a/pagure/decorators.py +++ b/pagure/decorators.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- """ - (c) 2018 - Copyright Red Hat Inc + (c) 2018-2019 - Copyright Red Hat Inc Authors: Clement Verna + Pierre-Yves Chibon """ @@ -25,7 +26,9 @@ def has_issue_tracker(function): @wraps(function) def check_issue_tracker(*args, **kwargs): repo = flask.g.repo - if not repo.settings.get("issue_tracker", True): + if not flask.g.issues_enabled or not repo.settings.get( + "issue_tracker", True + ): flask.abort(404, "No issue tracker found for this project") # forbid all POST requests if the issue tracker is made read-only if flask.request.method == "POST" and repo.settings.get( diff --git a/pagure/flask_app.py b/pagure/flask_app.py index 3f24e46..df9d687 100644 --- a/pagure/flask_app.py +++ b/pagure/flask_app.py @@ -244,6 +244,8 @@ def set_request(): flask.g.version = pagure.__version__ flask.g.confirmationform = pagure.forms.ConfirmationForm() + flask.g.issues_enabled = pagure_config.get("ENABLE_TICKETS", True) + # The API namespace has its own way of getting repo and username and # of handling errors if flask.request.blueprint == "api_ns": @@ -322,6 +324,28 @@ def set_request(): if flask.g.repo is None: flask.abort(404, "Project not found") + # If issues are not globally enabled, there is no point in continuing + if flask.g.issues_enabled: + + ticket_namespaces = pagure_config.get("ENABLE_TICKETS_NAMESPACE") + + if ticket_namespaces and flask.g.repo.namespace: + if flask.g.repo.namespace in (ticket_namespaces or []): + # If the namespace is in the allowed list + # issues are enabled + flask.g.issues_enabled = True + else: + # If the namespace isn't in the list of namespaces + # issues are disabled + flask.g.issues_enabled = False + + flask.g.issues_project_disabled = False + if not flask.g.repo.settings.get("issue_tracker", True): + # If the project specifically disabled its issue tracker, + # disable issues + flask.g.issues_project_disabled = True + flask.g.issues_enabled = False + flask.g.reponame = get_repo_path(flask.g.repo) flask.g.repo_obj = pygit2.Repository(flask.g.reponame) flask.g.repo_admin = pagure.utils.is_repo_admin(flask.g.repo) diff --git a/pagure/templates/comment_update.html b/pagure/templates/comment_update.html index e5ac679..cd15c51 100644 --- a/pagure/templates/comment_update.html +++ b/pagure/templates/comment_update.html @@ -89,7 +89,7 @@ $("#update_comment").atwho(userConfig); }); $.when( - {% if config.get('ENABLE_TICKETS', True) %} + {% if g.issues_enabled %} $.get("{{ url_for('api_ns.api_view_issues', namespace=repo.namespace, repo=repo.name, username=username, status='all') }}"), {% endif %} $.get("{{ url_for('api_ns.api_pull_request_views', namespace=repo.namespace, repo=repo.name, username=username, status='all') }}") diff --git a/pagure/templates/repo_master.html b/pagure/templates/repo_master.html index 294beaa..8b1db30 100644 --- a/pagure/templates/repo_master.html +++ b/pagure/templates/repo_master.html @@ -82,8 +82,7 @@
{% if g.authenticated %} - {% if repo.settings.get('issue_tracker', True) - and config.get('ENABLE_TICKETS', True) + {% if g.issues_enabled and not repo.settings.get('issue_tracker_read_only', False) %} {% endif %} - {% if config.get('ENABLE_TICKETS', True) and repo - and repo.settings.get('issue_tracker', True) %} + {% if g.issues_enabled %}