From b597484fce9397d4e9d4436aed3a6f57aaf71fc3 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jun 17 2018 14:38:44 +0000 Subject: Add support for making the issue tracker read-only Fixes https://pagure.io/pagure/issue/3228 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/api/__init__.py b/pagure/api/__init__.py index 0f006fe..0540acd 100644 --- a/pagure/api/__init__.py +++ b/pagure/api/__init__.py @@ -103,6 +103,7 @@ class APIERROR(enum.Enum): 'this action' ENOSIGNEDOFF = 'This repo enforces that all commits are signed off ' \ 'by their author.' + ETRACKERREADONLY = 'The issue tracker of this project is read-only' def get_authorized_api_project(session, repo, user=None, namespace=None): diff --git a/pagure/api/issue.py b/pagure/api/issue.py index bf41220..765947e 100644 --- a/pagure/api/issue.py +++ b/pagure/api/issue.py @@ -64,6 +64,12 @@ def _check_issue_tracker(repo): raise pagure.exceptions.APIError( 404, error_code=APIERROR.ETRACKERDISABLED) + # forbid all POST requests if the issue tracker is made read-only + if flask.request.method == 'POST' and \ + repo.settings.get('issue_tracker_read_only', False): + raise pagure.exceptions.APIError( + 401, error_code=APIERROR.ETRACKERREADONLY) + def _check_token(repo, project_token=True): """Check if token is valid for the repo diff --git a/pagure/decorators.py b/pagure/decorators.py index a894eef..5e65215 100644 --- a/pagure/decorators.py +++ b/pagure/decorators.py @@ -26,6 +26,10 @@ def has_issue_tracker(function): repo = flask.g.repo if 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('issue_tracker_read_only', False): + flask.abort(401, 'The issue tracker for this project is read-only') return function(*args, **kwargs) return check_issue_tracker diff --git a/pagure/lib/model.py b/pagure/lib/model.py index 6d2de48..2d35c6c 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -546,6 +546,7 @@ class Project(BASE): 'roadmap_on_issues_page': False, 'notify_on_pull-request_flag': False, 'notify_on_commit_flag': False, + 'issue_tracker_read_only': False, } if self._settings: diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html index 1bfd757..d0dec58 100644 --- a/pagure/templates/issue.html +++ b/pagure/templates/issue.html @@ -80,7 +80,7 @@ namespace=repo.namespace, repo=repo.name, issueid=issueid)
- {% if g.authenticated and form %} + {% if g.authenticated and form and not repo.settings.get('issue_tracker_read_only', False) %} @@ -111,6 +111,10 @@ namespace=repo.namespace, repo=repo.name, issueid=issueid)
+ {% elif g.authenticated and form and repo.settings.get('issue_tracker_read_only', False) %} +

+ This issue tracker is read-only. +

{% else %}

Login @@ -203,7 +207,8 @@ namespace=repo.namespace, repo=repo.name, issueid=issueid) unassigned {% endif %} {% if g.authenticated and g.repo_user and issue.status|lower == 'open' - and (not issue.assignee or issue.assignee.username != g.fas_user.username) %} + and (not issue.assignee or issue.assignee.username != g.fas_user.username) + and not repo.settings.get('issue_tracker_read_only', False) %}