2011-04-22 19:09:09 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2009-06-10 22:14:44 +02:00
|
|
|
from Acquisition import aq_inner, aq_parent
|
|
|
|
|
|
|
|
from Products.Five.browser import BrowserView
|
|
|
|
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
|
|
|
|
|
2009-06-28 13:49:00 +02:00
|
|
|
from Products.CMFCore.utils import getToolByName
|
|
|
|
|
2009-07-07 10:00:41 +02:00
|
|
|
from Products.statusmessages.interfaces import IStatusMessage
|
|
|
|
|
2010-03-17 13:34:38 +01:00
|
|
|
from plone.app.discussion.interfaces import _
|
2009-12-19 16:03:12 +01:00
|
|
|
from plone.app.discussion.interfaces import IComment
|
|
|
|
|
2010-01-22 17:28:00 +01:00
|
|
|
|
2009-06-10 22:14:44 +02:00
|
|
|
class View(BrowserView):
|
2011-04-22 19:09:09 +02:00
|
|
|
"""Comment moderation view.
|
2009-06-10 22:14:44 +02:00
|
|
|
"""
|
|
|
|
template = ViewPageTemplateFile('moderation.pt')
|
2009-08-20 04:11:57 +02:00
|
|
|
try:
|
|
|
|
template.id = '@@moderate-comments'
|
|
|
|
except AttributeError:
|
|
|
|
# id is not writeable in Zope 2.12
|
|
|
|
pass
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2009-06-10 22:14:44 +02:00
|
|
|
def __call__(self):
|
2009-10-07 13:52:44 +02:00
|
|
|
self.request.set('disable_border', True)
|
2009-06-26 16:57:45 +02:00
|
|
|
context = aq_inner(self.context)
|
2009-12-08 12:19:26 +01:00
|
|
|
catalog = getToolByName(context, 'portal_catalog')
|
2009-12-19 16:03:12 +01:00
|
|
|
self.comments = catalog(object_provides=IComment.__identifier__,
|
2009-12-08 12:19:26 +01:00
|
|
|
review_state='pending',
|
|
|
|
sort_on='created',
|
|
|
|
sort_order='reverse')
|
2009-06-10 22:14:44 +02:00
|
|
|
return self.template()
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2009-10-18 15:12:52 +02:00
|
|
|
def moderation_enabled(self):
|
2010-12-16 00:52:56 +01:00
|
|
|
"""Returns true if a 'review workflow' is enabled on 'Discussion Item'
|
2010-10-08 12:22:40 +02:00
|
|
|
content type. A 'review workflow' is characterized by implementing
|
|
|
|
a 'pending' workflow state.
|
2009-10-18 15:12:52 +02:00
|
|
|
"""
|
|
|
|
context = aq_inner(self.context)
|
2011-04-22 19:09:09 +02:00
|
|
|
workflowTool = getToolByName(context, 'portal_workflow')
|
2011-04-27 19:41:07 +02:00
|
|
|
comment_workflow = workflowTool.getChainForPortalType('Discussion Item')
|
|
|
|
if comment_workflow:
|
|
|
|
comment_workflow = comment_workflow[0]
|
|
|
|
comment_workflow = workflowTool[comment_workflow]
|
|
|
|
if 'pending' in comment_workflow.states:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return
|
2009-06-10 22:14:44 +02:00
|
|
|
|
2009-10-18 15:12:52 +02:00
|
|
|
|
2010-12-08 18:45:11 +01:00
|
|
|
class ModerateCommentsEnabled(BrowserView):
|
|
|
|
|
|
|
|
def __call__(self):
|
2010-12-16 00:52:56 +01:00
|
|
|
"""Returns true if a 'review workflow' is enabled on 'Discussion Item'
|
2010-12-08 18:45:11 +01:00
|
|
|
content type. A 'review workflow' is characterized by implementing
|
|
|
|
a 'pending' workflow state.
|
|
|
|
"""
|
|
|
|
context = aq_inner(self.context)
|
2011-04-22 19:09:09 +02:00
|
|
|
workflowTool = getToolByName(context, 'portal_workflow', None)
|
2011-04-27 19:41:07 +02:00
|
|
|
comment_workflow = workflowTool.getChainForPortalType('Discussion Item')
|
|
|
|
if comment_workflow:
|
|
|
|
comment_workflow = comment_workflow[0]
|
|
|
|
comment_workflow = workflowTool[comment_workflow]
|
|
|
|
if 'pending' in comment_workflow.states:
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return
|
2010-12-08 18:45:11 +01:00
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
|
2009-06-26 16:57:45 +02:00
|
|
|
class DeleteComment(BrowserView):
|
2010-10-05 17:14:12 +02:00
|
|
|
"""Delete a comment from a conversation.
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-10-05 17:14:12 +02:00
|
|
|
This view is always called directly on the comment object:
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-10-05 17:14:12 +02:00
|
|
|
http://nohost/front-page/++conversation++default/1286289644723317/\
|
|
|
|
@@moderate-delete-comment
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-10-05 17:14:12 +02:00
|
|
|
Each table row (comment) in the moderation view contains a hidden input
|
|
|
|
field with the absolute URL of the content object:
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
<input type="hidden"
|
2010-10-05 17:14:12 +02:00
|
|
|
value="http://nohost/front-page/++conversation++default/\
|
2010-12-16 00:52:56 +01:00
|
|
|
1286289644723317"
|
2010-10-05 17:14:12 +02:00
|
|
|
name="selected_obj_paths:list">
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-10-05 17:14:12 +02:00
|
|
|
This absolute URL is called from a jQuery method that is bind to the
|
|
|
|
'delete' button of the table row. See javascripts/moderation.js for more
|
2010-12-16 00:52:56 +01:00
|
|
|
details.
|
2009-06-26 16:57:45 +02:00
|
|
|
"""
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2009-06-26 16:57:45 +02:00
|
|
|
def __call__(self):
|
2011-04-22 19:09:09 +02:00
|
|
|
comment = aq_inner(self.context)
|
|
|
|
conversation = aq_parent(comment)
|
|
|
|
content_object = aq_parent(conversation)
|
|
|
|
del conversation[comment.id]
|
2009-07-07 10:00:41 +02:00
|
|
|
IStatusMessage(self.context.REQUEST).addStatusMessage(
|
|
|
|
_("Comment deleted."),
|
|
|
|
type="info")
|
2011-04-22 19:09:09 +02:00
|
|
|
came_from = self.context.REQUEST.HTTP_REFERER
|
|
|
|
if len(came_from) == 0:
|
|
|
|
came_from = content_object.absolute_url()
|
|
|
|
return self.context.REQUEST.RESPONSE.redirect(came_from)
|
2009-07-07 10:00:41 +02:00
|
|
|
|
2010-10-05 17:14:12 +02:00
|
|
|
|
2009-06-26 16:57:45 +02:00
|
|
|
class PublishComment(BrowserView):
|
2010-10-05 17:14:12 +02:00
|
|
|
"""Publish a comment.
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-10-05 17:14:12 +02:00
|
|
|
This view is always called directly on the comment object:
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-10-05 17:14:12 +02:00
|
|
|
http://nohost/front-page/++conversation++default/1286289644723317/\
|
|
|
|
@@moderate-publish-comment
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-10-05 17:14:12 +02:00
|
|
|
Each table row (comment) in the moderation view contains a hidden input
|
|
|
|
field with the absolute URL of the content object:
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
<input type="hidden"
|
2010-10-05 17:14:12 +02:00
|
|
|
value="http://nohost/front-page/++conversation++default/\
|
2010-12-16 00:52:56 +01:00
|
|
|
1286289644723317"
|
2010-10-05 17:14:12 +02:00
|
|
|
name="selected_obj_paths:list">
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-10-05 17:14:12 +02:00
|
|
|
This absolute URL is called from a jQuery method that is bind to the
|
|
|
|
'delete' button of the table row. See javascripts/moderation.js for more
|
2010-12-16 00:52:56 +01:00
|
|
|
details.
|
2009-06-26 16:57:45 +02:00
|
|
|
"""
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2009-06-26 16:57:45 +02:00
|
|
|
def __call__(self):
|
|
|
|
comment = aq_inner(self.context)
|
2011-04-22 19:09:09 +02:00
|
|
|
content_object = aq_parent(aq_parent(comment))
|
|
|
|
workflowTool = getToolByName(comment, 'portal_workflow', None)
|
|
|
|
current_state = workflowTool.getInfoFor(comment, 'review_state')
|
|
|
|
if current_state != 'published':
|
|
|
|
workflowTool.doActionFor(comment, 'publish')
|
|
|
|
catalogTool = getToolByName(comment, 'portal_catalog')
|
|
|
|
catalogTool.reindexObject(comment)
|
2009-07-07 10:00:41 +02:00
|
|
|
IStatusMessage(self.context.REQUEST).addStatusMessage(
|
2010-03-19 10:58:35 +01:00
|
|
|
_("Comment approved."),
|
2009-07-07 10:00:41 +02:00
|
|
|
type="info")
|
2011-04-22 19:09:09 +02:00
|
|
|
came_from = self.context.REQUEST.HTTP_REFERER
|
|
|
|
if len(came_from) == 0:
|
|
|
|
came_from = content_object.absolute_url()
|
|
|
|
return self.context.REQUEST.RESPONSE.redirect(came_from)
|
2009-07-07 10:00:41 +02:00
|
|
|
|
2009-06-26 16:57:45 +02:00
|
|
|
class BulkActionsView(BrowserView):
|
|
|
|
"""Bulk actions (unapprove, approve, delete, mark as spam).
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
Each table row of the moderation view has a checkbox with the absolute
|
2010-10-05 17:14:12 +02:00
|
|
|
path (without host and port) of the comment objects:
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-10-05 17:14:12 +02:00
|
|
|
<input type="checkbox"
|
|
|
|
name="paths:list"
|
|
|
|
value="/plone/front-page/++conversation++default/\
|
2010-12-16 00:52:56 +01:00
|
|
|
1286289644723317"
|
2010-10-05 17:14:12 +02:00
|
|
|
id="cb_1286289644723317" />
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
If checked, the comment path will occur in the 'paths' variable of
|
|
|
|
the request when the bulk actions view is called. The bulk action
|
|
|
|
(delete, publish, etc.) will be applied to all comments that are
|
2010-10-05 17:14:12 +02:00
|
|
|
included.
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-10-05 17:14:12 +02:00
|
|
|
The paths have to be 'traversable':
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
/plone/front-page/++conversation++default/1286289644723317
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2009-06-26 16:57:45 +02:00
|
|
|
"""
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2009-06-26 16:57:45 +02:00
|
|
|
def __call__(self):
|
2010-10-06 16:12:30 +02:00
|
|
|
if 'form.select.BulkAction' in self.request:
|
2009-06-26 20:59:37 +02:00
|
|
|
bulkaction = self.request.get('form.select.BulkAction')
|
2009-06-29 15:44:46 +02:00
|
|
|
self.paths = self.request.get('paths')
|
2009-06-29 17:09:41 +02:00
|
|
|
if self.paths:
|
|
|
|
if bulkaction == '-1':
|
|
|
|
# no bulk action was selected
|
|
|
|
pass
|
|
|
|
elif bulkaction == 'retract':
|
|
|
|
self.retract()
|
|
|
|
elif bulkaction == 'publish':
|
|
|
|
self.publish()
|
|
|
|
elif bulkaction == 'mark_as_spam':
|
|
|
|
self.mark_as_spam()
|
|
|
|
elif bulkaction == 'delete':
|
|
|
|
self.delete()
|
|
|
|
else:
|
2010-09-20 12:03:55 +02:00
|
|
|
raise KeyError # pragma: no cover
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2009-06-29 15:44:46 +02:00
|
|
|
def retract(self):
|
2009-06-26 20:59:37 +02:00
|
|
|
raise NotImplementedError
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2009-06-29 15:44:46 +02:00
|
|
|
def publish(self):
|
2010-10-05 17:14:12 +02:00
|
|
|
"""Publishes all comments in the paths variable.
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-10-05 17:14:12 +02:00
|
|
|
Expects a list of absolute paths (without host and port):
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-10-05 17:14:12 +02:00
|
|
|
/Plone/startseite/++conversation++default/1286200010610352
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-10-05 17:14:12 +02:00
|
|
|
"""
|
2009-06-26 20:59:37 +02:00
|
|
|
context = aq_inner(self.context)
|
2009-06-29 15:44:46 +02:00
|
|
|
for path in self.paths:
|
2009-06-26 20:59:37 +02:00
|
|
|
comment = context.restrictedTraverse(path)
|
2011-04-22 19:09:09 +02:00
|
|
|
workflowTool = getToolByName(comment, 'portal_workflow')
|
|
|
|
current_state = workflowTool.getInfoFor(comment, 'review_state')
|
2009-06-29 15:52:51 +02:00
|
|
|
if current_state != 'published':
|
2011-04-22 19:09:09 +02:00
|
|
|
workflowTool.doActionFor(comment, 'publish')
|
2009-06-26 20:59:37 +02:00
|
|
|
catalog = getToolByName(comment, 'portal_catalog')
|
|
|
|
catalog.reindexObject(comment)
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2009-06-29 15:44:46 +02:00
|
|
|
def mark_as_spam(self):
|
2009-06-26 20:59:37 +02:00
|
|
|
raise NotImplementedError
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2009-06-29 15:44:46 +02:00
|
|
|
def delete(self):
|
2010-10-05 17:14:12 +02:00
|
|
|
"""Deletes all comments in the paths variable.
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-10-05 17:14:12 +02:00
|
|
|
Expects a list of absolute paths (without host and port):
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-10-05 17:14:12 +02:00
|
|
|
/Plone/startseite/++conversation++default/1286200010610352
|
2011-04-22 19:09:09 +02:00
|
|
|
|
2010-12-16 00:52:56 +01:00
|
|
|
"""
|
2009-06-26 20:59:37 +02:00
|
|
|
context = aq_inner(self.context)
|
2009-06-29 15:44:46 +02:00
|
|
|
for path in self.paths:
|
2009-06-26 20:59:37 +02:00
|
|
|
comment = context.restrictedTraverse(path)
|
|
|
|
conversation = aq_parent(comment)
|
|
|
|
del conversation[comment.id]
|