Override for comments_for_node

Make use of the render_comments_for_node function, and define custom logic to determine the value of can_post_comments.
This commit is contained in:
Francesco Siddi 2018-01-20 00:45:57 +01:00
parent 67ce16fc78
commit 06414ab0ed

View File

@ -16,6 +16,8 @@ from pillar.web.utils import system_util, get_file, current_user_is_authenticate
from pillar.web.utils import attach_project_pictures
from pillar.web.settings import blueprint as blueprint_settings
from pillar.web.nodes.routes import url_for_node
from pillar.web.nodes.custom.comments import render_comments_for_node
blueprint = Blueprint('cloud', __name__)
log = logging.getLogger(__name__)
@ -397,6 +399,26 @@ def emails_welcome_txt():
return flask.Response(txt, content_type='text/plain; charset=utf-8')
@blueprint.route('/nodes/<string(length=24):node_id>/comments')
def comments_for_node(node_id):
"""Overrides the default render_comments_for_node.
This is done in order to extend can_post_comments by requiring the
subscriber capability.
"""
api = system_util.pillar_api()
node = Node.find(node_id, api=api)
project = Project({'_id': node.project})
can_post_comments = project.node_type_has_method('comment', 'POST', api=api)
can_comment_override = flask.request.args.get('can_comment', 'True') == 'True'
can_post_comments = can_post_comments and can_comment_override and current_user.has_cap(
'subscriber')
return render_comments_for_node(node_id, can_post_comments=can_post_comments)
def setup_app(app):
global _homepage_context
cached = app.cache.cached(timeout=300)