+def allow_reporting(controller):
+ """ Decorator for if reporting is enabled"""
+ @wraps(controller)
+ def wrapper(request, *args, **kwargs):
+ if not mgg.app_config["allow_reporting"]:
+ messages.add_message(
+ request,
+ messages.WARNING,
+ _('Sorry, reporting is disabled on this instance.'))
+ return redirect(request, 'index')
+
+ return controller(request, *args, **kwargs)
+
+ return wrapper
+
+def get_optional_media_comment_by_id(controller):
+ """
+ Pass in a Comment based off of a url component. Because of this decor-
+ -ator's use in filing Reports, it has two valid outcomes.
+
+ :returns The view function being wrapped with kwarg `comment` set to
+ the Comment who's id is in the URL. If there is a
+ comment id in the URL and if it is valid.
+ :returns The view function being wrapped with kwarg `comment` set to
+ None. If there is no comment id in the URL.
+ :returns A 404 Error page, if there is a comment if in the URL and it
+ is invalid.
+ """
+ @wraps(controller)
+ def wrapper(request, *args, **kwargs):
+ if 'comment' in request.matchdict:
+ comment = Comment.query.filter_by(
+ id=request.matchdict['comment']
+ ).first()
+
+ if comment is None:
+ return render_404(request)
+
+ return controller(request, comment=comment, *args, **kwargs)
+ else:
+ return controller(request, comment=None, *args, **kwargs)
+ return wrapper
+