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
|
2010-01-22 17:28:00 +01:00
|
|
|
from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile
|
2009-06-10 22:14:44 +02:00
|
|
|
|
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-08-31 19:33:22 +02:00
|
|
|
# Begin ugly hack. It works around a ContentProviderLookupError:
|
|
|
|
# plone.htmlhead error caused by Zope 2 permissions.
|
2010-01-22 17:28:00 +01:00
|
|
|
# This error occured on Plone 3.3.x only!
|
|
|
|
#
|
2010-08-31 19:33:22 +02:00
|
|
|
# Source:
|
|
|
|
# http://athenageek.wordpress.com/2008/01/08/
|
|
|
|
# contentproviderlookuperror-plonehtmlhead/
|
|
|
|
#
|
2010-01-22 17:28:00 +01:00
|
|
|
# Bug report: https://bugs.launchpad.net/zope2/+bug/176566
|
|
|
|
#
|
|
|
|
|
2010-09-16 16:58:11 +02:00
|
|
|
def _getContext(self): # pragma: no cover
|
2010-01-22 17:28:00 +01:00
|
|
|
self = self.aq_parent
|
|
|
|
while getattr(self, '_is_wrapperish', None):
|
|
|
|
self = self.aq_parent
|
|
|
|
return self
|
|
|
|
|
|
|
|
ZopeTwoPageTemplateFile._getContext = _getContext
|
|
|
|
# End ugly hack.
|
|
|
|
|
|
|
|
|
2009-06-10 22:14:44 +02:00
|
|
|
class View(BrowserView):
|
2009-06-29 15:38:00 +02:00
|
|
|
"""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
|
2009-06-10 22:14:44 +02:00
|
|
|
|
|
|
|
def __call__(self):
|
2009-10-07 13:52:44 +02:00
|
|
|
# Hide the editable-object border
|
|
|
|
self.request.set('disable_border', True)
|
2009-06-26 16:57:45 +02:00
|
|
|
|
|
|
|
context = aq_inner(self.context)
|
2010-04-01 15:48:03 +02:00
|
|
|
|
|
|
|
# Help for path mangling
|
|
|
|
portal_url = getToolByName(context, 'portal_url')
|
|
|
|
self.portal_url = portal_url()
|
|
|
|
self.portal_path = portal_url.getPortalPath()
|
2009-06-26 16:57:45 +02:00
|
|
|
|
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()
|
|
|
|
|
2009-06-28 20:38:25 +02:00
|
|
|
def cook(self, text):
|
|
|
|
return text
|
|
|
|
|
2009-10-18 15:12:52 +02:00
|
|
|
def moderation_enabled(self):
|
|
|
|
"""Returns true if comment moderation workflow is
|
|
|
|
enabled on 'Discussion Item' content type.
|
|
|
|
"""
|
|
|
|
context = aq_inner(self.context)
|
|
|
|
wf_tool = getToolByName(context, 'portal_workflow')
|
|
|
|
if wf_tool.getChainForPortalType('Discussion Item') \
|
|
|
|
== ('comment_review_workflow',):
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2010-04-01 15:48:03 +02:00
|
|
|
|
|
|
|
def item_path(self, item):
|
|
|
|
# Path mangling to support virtual hosting
|
|
|
|
path = item.getPath()[len(self.portal_path):]
|
|
|
|
return self.portal_url + path
|
2009-06-10 22:14:44 +02:00
|
|
|
|
2009-10-18 15:12:52 +02:00
|
|
|
|
2009-06-26 16:57:45 +02:00
|
|
|
class DeleteComment(BrowserView):
|
|
|
|
"""Delete a comment from a conversation
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __call__(self):
|
|
|
|
|
|
|
|
context = aq_inner(self.context)
|
|
|
|
comment_id = self.context.id
|
|
|
|
|
|
|
|
conversation = aq_parent(context)
|
|
|
|
|
|
|
|
del conversation[comment_id]
|
|
|
|
|
2009-07-07 10:00:41 +02:00
|
|
|
IStatusMessage(self.context.REQUEST).addStatusMessage(
|
|
|
|
_("Comment deleted."),
|
|
|
|
type="info")
|
|
|
|
|
2010-08-31 19:33:22 +02:00
|
|
|
return self.context.REQUEST.RESPONSE.redirect(
|
|
|
|
self.context.REQUEST.HTTP_REFERER)
|
2009-07-07 10:00:41 +02:00
|
|
|
|
2009-06-26 16:57:45 +02:00
|
|
|
class PublishComment(BrowserView):
|
|
|
|
"""Publish a comment
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __call__(self):
|
|
|
|
|
|
|
|
comment = aq_inner(self.context)
|
2009-10-17 18:14:44 +02:00
|
|
|
workflow_action = self.request.form['workflow_action']
|
2009-06-26 16:57:45 +02:00
|
|
|
portal_workflow = getToolByName(comment, 'portal_workflow')
|
|
|
|
portal_workflow.doActionFor(comment, workflow_action)
|
|
|
|
|
|
|
|
catalog = getToolByName(comment, 'portal_catalog')
|
|
|
|
catalog.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")
|
|
|
|
|
2010-08-31 19:33:22 +02:00
|
|
|
return self.context.REQUEST.RESPONSE.redirect(
|
|
|
|
self.context.REQUEST.HTTP_REFERER)
|
|
|
|
|
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).
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __call__(self):
|
|
|
|
|
2009-06-29 15:38:00 +02:00
|
|
|
if self.request.has_key('form.select.BulkAction'):
|
2009-06-26 16:57:45 +02:00
|
|
|
|
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:
|
|
|
|
raise KeyError
|
2009-06-26 20:59:37 +02:00
|
|
|
|
2009-06-29 15:44:46 +02:00
|
|
|
def retract(self):
|
2009-06-26 20:59:37 +02:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2009-06-29 15:44:46 +02:00
|
|
|
def publish(self):
|
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)
|
|
|
|
portal_workflow = getToolByName(comment, 'portal_workflow')
|
2009-06-29 15:52:51 +02:00
|
|
|
current_state = portal_workflow.getInfoFor(comment, 'review_state')
|
|
|
|
if current_state != 'published':
|
|
|
|
portal_workflow.doActionFor(comment, 'publish')
|
2009-06-26 20:59:37 +02:00
|
|
|
catalog = getToolByName(comment, 'portal_catalog')
|
|
|
|
catalog.reindexObject(comment)
|
|
|
|
|
2009-06-29 15:44:46 +02:00
|
|
|
def mark_as_spam(self):
|
2009-06-26 20:59:37 +02:00
|
|
|
raise NotImplementedError
|
|
|
|
|
2009-06-29 15:44:46 +02:00
|
|
|
def delete(self):
|
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]
|