Skip to content

Commit

Permalink
merge master in filippo_moderation_js
Browse files Browse the repository at this point in the history
  • Loading branch information
eikichi18 committed Sep 25, 2018
2 parents dfc6d06 + 9e7448a commit 3648c33
Show file tree
Hide file tree
Showing 25 changed files with 541 additions and 445 deletions.
20 changes: 18 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Changelog
=========

3.0.6 (unreleased)
3.0.7 (unreleased)
------------------

Breaking changes:
Expand All @@ -14,11 +14,27 @@ New features:

Bug fixes:

- Fix location of controlpanel events.
[jensens]

- Fixed tests when IRichText behavior is used.
IRichText -> IRichTextBehavior
This is a follow up to `issue 476 <https://github.com/plone/plone.app.contenttypes/issues/476>`_.
[iham]

- Fix commenting and tests in python 3.
[pbauer]

3.0.6 (2018-06-18)
------------------

Bug fixes:

- Fix tests to work with merges plone.login.
[jensens]

- More Python 2 / 3 compatibility.
[pbauer]
[pbauer, hvelarde]


3.0.5 (2018-02-04)
Expand Down
1 change: 1 addition & 0 deletions plone/app/discussion/browser/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from zope.component import getUtility
from zope.event import notify
from zope.lifecycleevent import ObjectModifiedEvent
from .comments import CommentForm


class View(BrowserView):
Expand Down
40 changes: 16 additions & 24 deletions plone/app/discussion/browser/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from plone.z3cform.fieldsets import extensible
from plone.z3cform.interfaces import IWrappedForm
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.utils import safe_unicode
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.statusmessages.interfaces import IStatusMessage
from six.moves.urllib.parse import quote
Expand All @@ -32,32 +33,30 @@
from zope.i18nmessageid import Message
from zope.interface import alsoProvides

import six


COMMENT_DESCRIPTION_PLAIN_TEXT = _(
u'comment_description_plain_text',
default=u'You can add a comment by filling out the form below. '
u'Plain text formatting.'
u'Plain text formatting.',
)

COMMENT_DESCRIPTION_MARKDOWN = _(
u'comment_description_markdown',
default=u'You can add a comment by filling out the form below. '
u'Plain text formatting. You can use the Markdown syntax for '
u'links and images.'
u'links and images.',
)

COMMENT_DESCRIPTION_INTELLIGENT_TEXT = _(
u'comment_description_intelligent_text',
default=u'You can add a comment by filling out the form below. '
u'Plain text formatting. Web and email addresses are '
u'transformed into clickable links.'
u'transformed into clickable links.',
)

COMMENT_DESCRIPTION_MODERATION_ENABLED = _(
u'comment_description_moderation_enabled',
default=u'Comments are moderated.'
default=u'Comments are moderated.',
)


Expand Down Expand Up @@ -152,13 +151,9 @@ def get_author(self, data):

# Make sure author_name/ author_email is properly encoded
if 'author_name' in data:
author_name = data['author_name']
if isinstance(author_name, str):
author_name = six.text_type(author_name, 'utf-8')
author_name = safe_unicode(data['author_name'])
if 'author_email' in data:
author_email = data['author_email']
if isinstance(author_email, str):
author_email = six.text_type(author_email, 'utf-8')
author_email = safe_unicode(data['author_email'])

# Set comment author properties for anonymous users or members
portal_membership = getToolByName(context, 'portal_membership')
Expand All @@ -167,21 +162,18 @@ def get_author(self, data):
'Reply to item', context):
# Member
member = portal_membership.getAuthenticatedMember()
# memberdata is stored as utf-8 encoded strings
email = member.getProperty('email')
email = safe_unicode(member.getProperty('email'))
fullname = member.getProperty('fullname')
if not fullname or fullname == '':
fullname = member.getUserName()
elif isinstance(fullname, str):
fullname = six.text_type(fullname, 'utf-8')
fullname = safe_unicode(fullname)
author_name = fullname
if email and isinstance(email, str):
email = six.text_type(email, 'utf-8')
# XXX: according to IComment interface author_email must not be
email = safe_unicode(email)
# XXX: according to IComment interface author_email must not be # noqa T000
# set for logged in users, cite:
# 'for anonymous comments only, set to None for logged in comments'
author_email = email
# /XXX
# /XXX # noqa T000

return author_name, author_email

Expand Down Expand Up @@ -228,7 +220,7 @@ def create_comment(self, data):
raise Unauthorized(
u'Anonymous user tries to post a comment, but anonymous '
u'commenting is disabled. Or user does not have the '
u"'reply to item' permission."
u"'reply to item' permission.",
)

return comment
Expand All @@ -240,10 +232,10 @@ def handleComment(self, action):

# Check if conversation is enabled on this content object
if not self.__parent__.restrictedTraverse(
'@@conversation_view'
'@@conversation_view',
).enabled():
raise Unauthorized(
'Discussion is not enabled for this content object.'
'Discussion is not enabled for this content object.',
)

# Validation form
Expand Down Expand Up @@ -293,7 +285,7 @@ def handleComment(self, action):
comment_review_state = workflowTool.getInfoFor(
comment,
'review_state',
None
None,
)
if comment_review_state == 'pending' and not can_review:
# Show info message when comment moderation is enabled
Expand Down
12 changes: 6 additions & 6 deletions plone/app/discussion/browser/controlpanel.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-
from plone.app.controlpanel.interfaces import IConfigurationChangedEvent
from plone.app.discussion.interfaces import _
from plone.app.discussion.interfaces import IDiscussionSettings
from plone.app.discussion.upgrades import update_registry
from plone.app.registry.browser import controlpanel
from plone.registry.interfaces import IRecordModifiedEvent
from plone.registry.interfaces import IRegistry
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone.interfaces.controlpanel import IConfigurationChangedEvent # noqa: E501
from Products.CMFPlone.interfaces.controlpanel import IMailSchema
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.statusmessages.interfaces import IStatusMessage
Expand Down Expand Up @@ -34,7 +34,7 @@ class DiscussionSettingsEditForm(controlpanel.RegistryEditForm):
u'To enable the moderation workflow for comments, '
u'go to the Types Control Panel, choose '
u'"Comment" and set workflow to '
u'"Comment Review Workflow".'
u'"Comment Review Workflow".',
)

def updateFields(self):
Expand Down Expand Up @@ -68,10 +68,10 @@ def updateWidgets(self):
self.widgets['anonymous_comments'].label = _(u'Anonymous Comments')
self.widgets['show_commenter_image'].label = _(u'Commenter Image')
self.widgets['moderator_notification_enabled'].label = _(
u'Moderator Email Notification'
u'Moderator Email Notification',
)
self.widgets['user_notification_enabled'].label = _(
u'User Email Notification'
u'User Email Notification',
)

@button.buttonAndHandler(_('Save'), name=None)
Expand All @@ -92,8 +92,8 @@ def handleCancel(self, action):
self.request.response.redirect(
'{0}/{1}'.format(
self.context.absolute_url(),
self.control_panel_view
)
self.control_panel_view,
),
)


Expand Down
12 changes: 10 additions & 2 deletions plone/app/discussion/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from Products.CMFPlone.utils import safe_unicode
from Products.ZCatalog.interfaces import IZCatalog

import six

MAX_DESCRIPTION = 25

Expand Down Expand Up @@ -70,13 +71,20 @@ def title(object):

@indexer(IComment)
def creator(object):
return object.creator and safe_unicode(object.creator).encode('utf-8')
if not object.creator:
return
value = safe_unicode(object.creator)
if six.PY2:
return value.encode('utf8')
return value


@indexer(IComment)
def description(object):
# Return the first 25 words of the comment text and append ' [...]'
text = ' '.join(object.getText(targetMimetype='text/plain').split()[:MAX_DESCRIPTION])
text = ' '.join(
object.getText(targetMimetype='text/plain').split()[:MAX_DESCRIPTION],
)
if len(object.getText().split()) > 25:
text += ' [...]'
return text
Expand Down
72 changes: 42 additions & 30 deletions plone/app/discussion/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def __init__(self):
aclpath = [x for x in user.getPhysicalPath() if x]
self._owner = (aclpath, user.getId(),)
self.__ac_local_roles__ = {
user.getId(): ['Owner']
user.getId(): ['Owner'],
}

@property
Expand Down Expand Up @@ -148,7 +148,7 @@ def getText(self, targetMimetype=None):
text = self.text
if text is None:
return ''
if isinstance(text, six.text_type):
if six.PY2 and isinstance(text, six.text_type):
text = text.encode('utf8')
transform = transforms.convertTo(
targetMimetype,
Expand All @@ -162,7 +162,11 @@ def getText(self, targetMimetype=None):
msg = u'Transform "{0}" => "{1}" not available. Failed to ' \
u'transform comment "{2}".'
logger.error(
msg.format(sourceMimetype, targetMimetype, self.absolute_url())
msg.format(
sourceMimetype,
targetMimetype,
self.absolute_url(),
),
)
return text

Expand All @@ -174,10 +178,12 @@ def Title(self):

if not self.author_name:
author_name = translate(
Message(_(
u'label_anonymous',
default=u'Anonymous'
))
Message(
_(
u'label_anonymous',
default=u'Anonymous',
),
),
)
else:
author_name = self.author_name
Expand Down Expand Up @@ -284,11 +290,11 @@ def notify_content_object_moved(obj, event):
old_path = '/'.join(
event.oldParent.getPhysicalPath() +
(event.oldName,) +
moved_path
moved_path,
)
brains = catalog.searchResults(dict(
path={'query': old_path},
portal_type='Discussion Item'
portal_type='Discussion Item',
))
for brain in brains:
catalog.uncatalog_object(brain.getPath())
Expand Down Expand Up @@ -350,24 +356,28 @@ def notify_user(obj, event):
mapping={
'title': safe_unicode(content_object.title),
'link': content_object.absolute_url() + '/view#' + obj.id,
'text': obj.text
}
'text': obj.text,
},
),
context=obj.REQUEST
context=obj.REQUEST,
)
for email in emails:
# Send email
try:
mail_host.send(message,
email,
sender,
subject,
charset='utf-8')
mail_host.send(
message,
email,
sender,
subject,
charset='utf-8',
)
except SMTPException:
logger.error('SMTP exception while trying to send an ' +
'email from %s to %s',
sender,
email)
logger.error(
'SMTP exception while trying to send an ' +
'email from %s to %s',
sender,
email,
)


def notify_moderator(obj, event):
Expand Down Expand Up @@ -420,19 +430,21 @@ def notify_moderator(obj, event):
'text': obj.text,
'link_approve': link_approve,
'link_delete': link_delete,
}
},
),
context=obj.REQUEST
context=obj.REQUEST,
)

# Send email
try:
mail_host.send(message, mto, sender, subject, charset='utf-8')
except SMTPException as e:
logger.error('SMTP exception (%s) while trying to send an ' +
'email notification to the comment moderator ' +
'(from %s to %s, message: %s)',
e,
sender,
mto,
message)
logger.error(
'SMTP exception (%s) while trying to send an ' +
'email notification to the comment moderator ' +
'(from %s to %s, message: %s)',
e,
sender,
mto,
message,
)
Loading

0 comments on commit 3648c33

Please sign in to comment.