Show a 'Comments are moderated.' message next to the comment form if comments are moderated.

svn path=/plone.app.discussion/trunk/; revision=46782
This commit is contained in:
Timo Stollenwerk 2011-01-07 10:20:24 +00:00
parent b18469e5fd
commit c438743a3b
3 changed files with 38 additions and 4 deletions

View File

@ -4,6 +4,10 @@ Changelog
1.0RC1 (unreleased) 1.0RC1 (unreleased)
------------------- -------------------
- Show a 'Comments are moderated.' message next to the comment form if comments
are moderated.
[timo]
- Make sure plone.app.registry's ZCML is loaded, so that its import step will run - Make sure plone.app.registry's ZCML is loaded, so that its import step will run
when plone.app.discussion is installed. when plone.app.discussion is installed.
[davisagli] [davisagli]

View File

@ -59,6 +59,10 @@ COMMENT_DESCRIPTION_INTELLIGENT_TEXT = _(
"Plain text formatting. Web and email addresses are transformed " + "Plain text formatting. Web and email addresses are transformed " +
"into clickable links.") "into clickable links.")
COMMENT_DESCRIPTION_MODERATION_ENABLED = _(
u"comment_description_moderation_enabled",
default=u"Comments are moderated.")
class CommentForm(extensible.ExtensibleForm, form.Form): class CommentForm(extensible.ExtensibleForm, form.Form):
@ -296,16 +300,29 @@ class CommentsViewlet(ViewletBase):
def comment_transform_message(self): def comment_transform_message(self):
"""Returns the description that shows up above the comment text, """Returns the description that shows up above the comment text,
dependent on the text_transform setting of the discussion control dependent on the text_transform setting and the comment moderation
panel. workflow in the discussion control panel.
""" """
context = aq_inner(self.context)
registry = queryUtility(IRegistry) registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings, check=False) settings = registry.forInterface(IDiscussionSettings, check=False)
# text transform setting
if settings.text_transform == "text/x-web-intelligent": if settings.text_transform == "text/x-web-intelligent":
message = translate(Message(COMMENT_DESCRIPTION_INTELLIGENT_TEXT)) message = translate(Message(COMMENT_DESCRIPTION_INTELLIGENT_TEXT))
else: else:
message = translate(Message(COMMENT_DESCRIPTION_PLAIN_TEXT)) message = translate(Message(COMMENT_DESCRIPTION_PLAIN_TEXT))
# comment workflow
wftool = getToolByName(context, "portal_workflow", None)
comment_workflow = wftool.getChainForPortalType('Discussion Item')[0]
comment_workflow = wftool[comment_workflow]
# check if the current workflow implements a pending state. If this is
# true comments are moderated
if 'pending' in comment_workflow.states:
message = message + " " + \
translate(Message(COMMENT_DESCRIPTION_MODERATION_ENABLED))
return message return message
def has_replies(self, workflow_actions=False): def has_replies(self, workflow_actions=False):

View File

@ -295,7 +295,8 @@ class TestCommentsViewlet(PloneTestCase):
self.failUnless(self.viewlet.is_discussion_allowed()) self.failUnless(self.viewlet.is_discussion_allowed())
def test_comment_transform_message(self): def test_comment_transform_message(self):
# Default transform is plain/text
# Default transform is plain/text and comment moderation disabled
self.failUnless(self.viewlet.comment_transform_message()) self.failUnless(self.viewlet.comment_transform_message())
self.assertEquals( self.assertEquals(
self.viewlet.comment_transform_message(), self.viewlet.comment_transform_message(),
@ -307,13 +308,25 @@ class TestCommentsViewlet(PloneTestCase):
settings = registry.forInterface(IDiscussionSettings, check=False) settings = registry.forInterface(IDiscussionSettings, check=False)
settings.text_transform = "text/x-web-intelligent" settings.text_transform = "text/x-web-intelligent"
# Make sure the comment description is changes accordingly # Make sure the comment description changes accordingly
self.assertEquals( self.assertEquals(
self.viewlet.comment_transform_message(), self.viewlet.comment_transform_message(),
"You can add a comment by filling out the form below. " + "You can add a comment by filling out the form below. " +
"Plain text formatting. Web and email addresses are transformed " + "Plain text formatting. Web and email addresses are transformed " +
"into clickable links.") "into clickable links.")
# Enable moderation workflow
self.portal.portal_workflow.setChainForPortalTypes(
('Discussion Item',),
('comment_review_workflow,'))
# Make sure the comment description shows that comments are moderated
self.assertEquals(
self.viewlet.comment_transform_message(),
"You can add a comment by filling out the form below. " +
"Plain text formatting. Web and email addresses are transformed " +
"into clickable links. Comments are moderated.")
def test_has_replies(self): def test_has_replies(self):
self.assertEquals(self.viewlet.has_replies(), False) self.assertEquals(self.viewlet.has_replies(), False)
comment = createObject('plone.Comment') comment = createObject('plone.Comment')