diff --git a/pagure/lib/decorators.py b/pagure/lib/decorators.py new file mode 100644 index 0000000..e992d33 --- /dev/null +++ b/pagure/lib/decorators.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +""" + (c) 2017 - Copyright Red Hat Inc + + Authors: + Clement Verna + +""" +import flask +from functools import wraps + + +def has_issue_tracker(function): + """ + Decorator that checks if the current pagure project has the + issue tracker active + If not active returns a 404 page + """ + @wraps(function) + def check_issue_tracker(*args, **kwargs): + repo = flask.g.repo + if not repo.settings.get('issue_tracker', True): + flask.abort(404, 'No issue tracker found for this project') + return function(*args, **kwargs) + + return check_issue_tracker diff --git a/pagure/ui/issues.py b/pagure/ui/issues.py index dd30ab7..9390436 100644 --- a/pagure/ui/issues.py +++ b/pagure/ui/issues.py @@ -19,7 +19,6 @@ import logging import os import re from collections import defaultdict -from functools import wraps from math import ceil import flask @@ -32,6 +31,7 @@ import pagure.doc_utils import pagure.exceptions import pagure.lib import pagure.lib.mimetype +from pagure.lib.decorators import has_issue_tracker import pagure.forms from pagure.config import config as pagure_config from pagure.ui import UI_NS @@ -46,22 +46,6 @@ from pagure.utils import ( _log = logging.getLogger(__name__) -def has_issue_tracker(function): - """ - Decorator that checks if the current pagure project has the - issue tracker active - If not active returns a 404 page - """ - @wraps(function) - def check_issue_tracker(*args, **kwargs): - repo = flask.g.repo - if not repo.settings.get('issue_tracker', True): - flask.abort(404, 'No issue tracker found for this project') - return function(*args, **kwargs) - - return check_issue_tracker - - @UI_NS.route( '//issue//update/', methods=['GET', 'POST']) @@ -1368,9 +1352,6 @@ def view_issue_raw_file( repo = flask.g.repo - if not repo.settings.get('issue_tracker', True): - flask.abort(404, 'No issue tracker found for this project') - attachdir = os.path.join( pagure_config['ATTACHMENTS_FOLDER'], repo.fullname) attachpath = os.path.join(attachdir, filename)