From 22a7152e92d958dae7ad759f11fb6b02b6ab3258 Mon Sep 17 00:00:00 2001 From: Katja Suess Date: Mon, 30 Sep 2019 10:34:49 +0200 Subject: [PATCH] publish only pending comment, else show status message --- plone/app/discussion/browser/moderation.py | 23 +++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/plone/app/discussion/browser/moderation.py b/plone/app/discussion/browser/moderation.py index 556b604..075ee8a 100644 --- a/plone/app/discussion/browser/moderation.py +++ b/plone/app/discussion/browser/moderation.py @@ -8,11 +8,13 @@ from plone.app.discussion.events import CommentDeletedEvent from plone.app.discussion.interfaces import _ from plone.app.discussion.interfaces import IComment from plone.app.discussion.interfaces import IReplies +from plone.protect.interfaces import IDisableCSRFProtection from Products.CMFCore.utils import getToolByName from Products.Five.browser import BrowserView from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile from Products.statusmessages.interfaces import IStatusMessage from zope.event import notify +from zope.interface import alsoProvides class View(BrowserView): @@ -205,17 +207,24 @@ class PublishComment(BrowserView): """ def __call__(self): + alsoProvides(self.request, IDisableCSRFProtection) comment = aq_inner(self.context) content_object = aq_parent(aq_parent(comment)) workflowTool = getToolByName(comment, 'portal_workflow', None) workflow_action = self.request.form.get('workflow_action', 'publish') - workflowTool.doActionFor(comment, workflow_action) - comment.reindexObject() - content_object.reindexObject(idxs=['total_comments']) - notify(CommentPublishedEvent(self.context, comment)) - IStatusMessage(self.context.REQUEST).addStatusMessage( - _('Comment approved.'), - type='info') + review_state = workflowTool.getInfoFor(comment, 'review_state', '') + if review_state == "pending": + workflowTool.doActionFor(comment, workflow_action) + comment.reindexObject() + content_object.reindexObject(idxs=['total_comments']) + notify(CommentPublishedEvent(self.context, comment)) + IStatusMessage(self.context.REQUEST).addStatusMessage( + _('Comment approved.'), + type='info') + else: + IStatusMessage(self.context.REQUEST).addStatusMessage( + _('Comment already approved.'), + type='info') came_from = self.context.REQUEST.HTTP_REFERER # if the referrer already has a came_from in it, don't redirect back if (len(came_from) == 0 or 'came_from=' in came_from or