bugfix 1: according to IDiscussionSettings.anonymous_email_enabled (cite):

If selected, anonymous user will have to give their email. - But field
was not required. Now it is.

bugfix 2: anonymous email field was never saved.
This commit is contained in:
Jens W. Klein 2014-03-25 21:30:50 +01:00
parent 996592835b
commit 6bfa19411d
2 changed files with 32 additions and 9 deletions

View File

@ -4,6 +4,14 @@ Changelog
2.3.2 (unreleased) 2.3.2 (unreleased)
------------------ ------------------
- bugfix: according to IDiscussionSettings.anonymous_email_enabled (cite):
"If selected, anonymous user will have to give their email." - But field
was not required. Now it is.
[jensens]
- bugfix: anonymous email field was never saved.
[jensens]
- updated german translations: added some missing msgstr. - updated german translations: added some missing msgstr.
[jensens] [jensens]
@ -12,7 +20,7 @@ Changelog
[jensens] [jensens]
- Fix reindexObject for content_object in moderation views. - Fix reindexObject for content_object in moderation views.
Now reindex only "total_comments" index and not all the indexes Now reindex only "total_comments" index and not all the indexes
[cekk] [cekk]
- Fix comments Title if utf-8 characters in author_name - Fix comments Title if utf-8 characters in author_name
@ -56,7 +64,7 @@ Changelog
PLONE_FIXTURE. PLONE_FIXTURE.
[timo] [timo]
- Fix ownership of comments. - Fix ownership of comments.
[toutpt] [toutpt]

View File

@ -101,14 +101,20 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
# Anonymous / Logged-in # Anonymous / Logged-in
mtool = getToolByName(self.context, 'portal_membership') mtool = getToolByName(self.context, 'portal_membership')
if not mtool.isAnonymousUser(): anon = mtool.isAnonymousUser()
self.widgets['author_name'].mode = interfaces.HIDDEN_MODE
self.widgets['author_email'].mode = interfaces.HIDDEN_MODE
registry = queryUtility(IRegistry) registry = queryUtility(IRegistry)
settings = registry.forInterface(IDiscussionSettings, check=False) settings = registry.forInterface(IDiscussionSettings, check=False)
if mtool.isAnonymousUser() and not settings.anonymous_email_enabled: if anon:
if settings.anonymous_email_enabled:
# according to IDiscussionSettings.anonymous_email_enabled:
# "If selected, anonymous user will have to give their email."
self.widgets['author_email'].required = True
else:
self.widgets['author_email'].mode = interfaces.HIDDEN_MODE
else:
self.widgets['author_name'].mode = interfaces.HIDDEN_MODE
self.widgets['author_email'].mode = interfaces.HIDDEN_MODE self.widgets['author_email'].mode = interfaces.HIDDEN_MODE
member = mtool.getAuthenticatedMember() member = mtool.getAuthenticatedMember()
@ -119,7 +125,6 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
# email address # email address
member_email_is_empty = member_email == '' member_email_is_empty = member_email == ''
user_notification_disabled = not settings.user_notification_enabled user_notification_disabled = not settings.user_notification_enabled
anon = mtool.isAnonymousUser()
if member_email_is_empty or user_notification_disabled or anon: if member_email_is_empty or user_notification_disabled or anon:
self.widgets['user_notification'].mode = interfaces.HIDDEN_MODE self.widgets['user_notification'].mode = interfaces.HIDDEN_MODE
@ -175,11 +180,15 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
# Set comment attributes (including extended comment form attributes) # Set comment attributes (including extended comment form attributes)
for attribute in self.fields.keys(): for attribute in self.fields.keys():
setattr(comment, attribute, data[attribute]) setattr(comment, attribute, data[attribute])
# Make sure author_name is properly encoded # Make sure author_name/ author_email is properly encoded
if 'author_name' in data: if 'author_name' in data:
author_name = data['author_name'] author_name = data['author_name']
if isinstance(author_name, str): if isinstance(author_name, str):
author_name = unicode(author_name, 'utf-8') author_name = unicode(author_name, 'utf-8')
if 'author_email' in data:
author_email = data['author_email']
if isinstance(author_email, str):
author_email = unicode(author_email, 'utf-8')
# Set comment author properties for anonymous users or members # Set comment author properties for anonymous users or members
can_reply = getSecurityManager().checkPermission('Reply to item', can_reply = getSecurityManager().checkPermission('Reply to item',
@ -188,7 +197,7 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
if anon and anonymous_comments: if anon and anonymous_comments:
# Anonymous Users # Anonymous Users
comment.author_name = author_name comment.author_name = author_name
comment.author_email = u"" comment.author_email = author_email
comment.user_notification = None comment.user_notification = None
comment.creation_date = datetime.utcnow() comment.creation_date = datetime.utcnow()
comment.modification_date = datetime.utcnow() comment.modification_date = datetime.utcnow()
@ -211,7 +220,13 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
comment.creator = memberid comment.creator = memberid
comment.author_username = memberid comment.author_username = memberid
comment.author_name = fullname comment.author_name = fullname
# XXX: according to IComment interface author_email must not be
# set for logged in users, cite:
# "for anonymous comments only, set to None for logged in comments"
comment.author_email = email comment.author_email = email
# /XXX
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