This commit is contained in:
Timo Stollenwerk 2013-04-18 15:46:28 +02:00
parent 37faab444a
commit 0a8cd01922

View File

@ -46,19 +46,19 @@ from plone.z3cform.interfaces import IWrappedForm
COMMENT_DESCRIPTION_PLAIN_TEXT = _( COMMENT_DESCRIPTION_PLAIN_TEXT = _(
u"comment_description_plain_text", u"comment_description_plain_text",
default=u"You can add a comment by filling out the form below. " + default=u"You can add a comment by filling out the form below. " +
"Plain text formatting.") u"Plain text formatting.")
COMMENT_DESCRIPTION_MARKDOWN = _( COMMENT_DESCRIPTION_MARKDOWN = _(
u"comment_description_markdown", u"comment_description_markdown",
default=u"You can add a comment by filling out the form below. " + default=u"You can add a comment by filling out the form below. " +
"Plain text formatting. You can use the Markdown syntax for " + u"Plain text formatting. You can use the Markdown syntax for " +
"links and images.") u"links and images.")
COMMENT_DESCRIPTION_INTELLIGENT_TEXT = _( COMMENT_DESCRIPTION_INTELLIGENT_TEXT = _(
u"comment_description_intelligent_text", u"comment_description_intelligent_text",
default=u"You can add a comment by filling out the form below. " + default=u"You can add a comment by filling out the form below. " +
"Plain text formatting. Web and email addresses are " + u"Plain text formatting. Web and email addresses are " +
"transformed into clickable links.") u"transformed into clickable links.")
COMMENT_DESCRIPTION_MODERATION_ENABLED = _( COMMENT_DESCRIPTION_MODERATION_ENABLED = _(
u"comment_description_moderation_enabled", u"comment_description_moderation_enabled",
@ -117,10 +117,11 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
# Hide the user_notification checkbox if user notification is disabled # Hide the user_notification checkbox if user notification is disabled
# or the user is not logged in. Also check if the user has a valid # or the user is not logged in. Also check if the user has a valid
# email address # email address
if member_email == '' or \ member_email_is_empty = member_email == ''
not settings.user_notification_enabled or \ user_notification_disabled = not settings.user_notification_enabled
mtool.isAnonymousUser(): anon = mtool.isAnonymousUser()
self.widgets['user_notification'].mode = interfaces.HIDDEN_MODE if member_email_is_empty or user_notification_disabled or anon:
self.widgets['user_notification'].mode = interfaces.HIDDEN_MODE
def updateActions(self): def updateActions(self):
super(CommentForm, self).updateActions() super(CommentForm, self).updateActions()
@ -135,7 +136,8 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
# Check if conversation is enabled on this content object # Check if conversation is enabled on this content object
if not self.__parent__.restrictedTraverse( if not self.__parent__.restrictedTraverse(
'@@conversation_view').enabled(): '@@conversation_view'
).enabled():
raise Unauthorized("Discussion is not enabled for this content " raise Unauthorized("Discussion is not enabled for this content "
"object.") "object.")
@ -148,9 +150,10 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
registry = queryUtility(IRegistry) registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings, check=False) settings = registry.forInterface(IDiscussionSettings, check=False)
portal_membership = getToolByName(self.context, 'portal_membership') portal_membership = getToolByName(self.context, 'portal_membership')
if settings.captcha != 'disabled' and \ captcha_enabled = settings.captcha != 'disabled'
settings.anonymous_comments and \ anonymous_comments = settings.anonymous_comments
portal_membership.isAnonymousUser(): anon = portal_membership.isAnonymousUser()
if captcha_enabled and anonymous_comments and anon:
if not 'captcha' in data: if not 'captcha' in data:
data['captcha'] = u"" data['captcha'] = u""
captcha = CaptchaValidator(self.context, captcha = CaptchaValidator(self.context,
@ -182,8 +185,7 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
can_reply = getSecurityManager().checkPermission('Reply to item', can_reply = getSecurityManager().checkPermission('Reply to item',
context) context)
portal_membership = getToolByName(self.context, 'portal_membership') portal_membership = getToolByName(self.context, 'portal_membership')
if portal_membership.isAnonymousUser() and \ if anon and anonymous_comments:
settings.anonymous_comments:
# Anonymous Users # Anonymous Users
comment.author_name = author_name comment.author_name = author_name
comment.author_email = u"" comment.author_email = u""
@ -210,9 +212,11 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
comment.creation_date = datetime.utcnow() comment.creation_date = datetime.utcnow()
comment.modification_date = datetime.utcnow() comment.modification_date = datetime.utcnow()
else: # pragma: no cover else: # pragma: no cover
raise Unauthorized("Anonymous user tries to post a comment, but " raise Unauthorized(
"anonymous commenting is disabled. Or user does not have the " u"Anonymous user tries to post a comment, but anonymous "
"'reply to item' permission.") u"commenting is disabled. Or user does not have the "
u"'reply to item' permission."
)
# Add comment to conversation # Add comment to conversation
conversation = IConversation(self.__parent__) conversation = IConversation(self.__parent__)
@ -234,8 +238,8 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
context) context)
workflowTool = getToolByName(context, 'portal_workflow') workflowTool = getToolByName(context, 'portal_workflow')
comment_review_state = workflowTool.getInfoFor( comment_review_state = workflowTool.getInfoFor(
comment, comment,
'review_state', 'review_state',
None None
) )
if comment_review_state == 'pending' and not can_review: if comment_review_state == 'pending' and not can_review:
@ -262,9 +266,13 @@ class CommentsViewlet(ViewletBase):
def update(self): def update(self):
super(CommentsViewlet, self).update() super(CommentsViewlet, self).update()
if self.is_discussion_allowed() and \ discussion_allowed = self.is_discussion_allowed()
(self.is_anonymous() and self.anonymous_discussion_allowed() \ anonymous_allowed_or_can_reply = (
or self.can_reply()): self.is_anonymous()
and self.anonymous_discussion_allowed()
or self.can_reply()
)
if discussion_allowed and anonymous_allowed_or_can_reply:
z2.switch_on(self, request_layer=IFormLayer) z2.switch_on(self, request_layer=IFormLayer)
self.form = self.form(aq_inner(self.context), self.request) self.form = self.form(aq_inner(self.context), self.request)
alsoProvides(self.form, IWrappedForm) alsoProvides(self.form, IWrappedForm)
@ -362,8 +370,10 @@ class CommentsViewlet(ViewletBase):
for r in conversation.getThreads(): for r in conversation.getThreads():
comment_obj = r['comment'] comment_obj = r['comment']
# list all possible workflow actions # list all possible workflow actions
actions = [a for a in wf.listActionInfos(object=comment_obj) actions = [
if a['category'] == 'workflow' and a['allowed']] a for a in wf.listActionInfos(object=comment_obj)
if a['category'] == 'workflow' and a['allowed']
]
r = r.copy() r = r.copy()
r['actions'] = actions r['actions'] = actions
yield r yield r
@ -400,8 +410,9 @@ class CommentsViewlet(ViewletBase):
portal_membership = getToolByName(self.context, portal_membership = getToolByName(self.context,
'portal_membership', 'portal_membership',
None) None)
return portal_membership.getPersonalPortrait(username)\ return portal_membership\
.absolute_url() .getPersonalPortrait(username)\
.absolute_url()
def anonymous_discussion_allowed(self): def anonymous_discussion_allowed(self):
# Check if anonymous comments are allowed in the registry # Check if anonymous comments are allowed in the registry