publish only pending comment, else show status message
This commit is contained in:
parent
3fe04f9133
commit
22a7152e92
@ -8,11 +8,13 @@ from plone.app.discussion.events import CommentDeletedEvent
|
|||||||
from plone.app.discussion.interfaces import _
|
from plone.app.discussion.interfaces import _
|
||||||
from plone.app.discussion.interfaces import IComment
|
from plone.app.discussion.interfaces import IComment
|
||||||
from plone.app.discussion.interfaces import IReplies
|
from plone.app.discussion.interfaces import IReplies
|
||||||
|
from plone.protect.interfaces import IDisableCSRFProtection
|
||||||
from Products.CMFCore.utils import getToolByName
|
from Products.CMFCore.utils import getToolByName
|
||||||
from Products.Five.browser import BrowserView
|
from Products.Five.browser import BrowserView
|
||||||
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
|
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
|
||||||
from Products.statusmessages.interfaces import IStatusMessage
|
from Products.statusmessages.interfaces import IStatusMessage
|
||||||
from zope.event import notify
|
from zope.event import notify
|
||||||
|
from zope.interface import alsoProvides
|
||||||
|
|
||||||
|
|
||||||
class View(BrowserView):
|
class View(BrowserView):
|
||||||
@ -205,17 +207,24 @@ class PublishComment(BrowserView):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
|
alsoProvides(self.request, IDisableCSRFProtection)
|
||||||
comment = aq_inner(self.context)
|
comment = aq_inner(self.context)
|
||||||
content_object = aq_parent(aq_parent(comment))
|
content_object = aq_parent(aq_parent(comment))
|
||||||
workflowTool = getToolByName(comment, 'portal_workflow', None)
|
workflowTool = getToolByName(comment, 'portal_workflow', None)
|
||||||
workflow_action = self.request.form.get('workflow_action', 'publish')
|
workflow_action = self.request.form.get('workflow_action', 'publish')
|
||||||
workflowTool.doActionFor(comment, workflow_action)
|
review_state = workflowTool.getInfoFor(comment, 'review_state', '')
|
||||||
comment.reindexObject()
|
if review_state == "pending":
|
||||||
content_object.reindexObject(idxs=['total_comments'])
|
workflowTool.doActionFor(comment, workflow_action)
|
||||||
notify(CommentPublishedEvent(self.context, comment))
|
comment.reindexObject()
|
||||||
IStatusMessage(self.context.REQUEST).addStatusMessage(
|
content_object.reindexObject(idxs=['total_comments'])
|
||||||
_('Comment approved.'),
|
notify(CommentPublishedEvent(self.context, comment))
|
||||||
type='info')
|
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
|
came_from = self.context.REQUEST.HTTP_REFERER
|
||||||
# if the referrer already has a came_from in it, don't redirect back
|
# 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
|
if (len(came_from) == 0 or 'came_from=' in came_from or
|
||||||
|
Loading…
Reference in New Issue
Block a user