Skip to content

Commit

Permalink
Do not allow failures under Plone 5 anymore
Browse files Browse the repository at this point in the history
Fix 4.x tests and backward compatibility.

Fix robot import failure in Plone 5 tests, and some flake fixes.

Fix conditional zcml import for plone 4 and 5.

Use integration instead of functional testing layer.  No difference.

Fix tests for Plone 5.

Fix tests for Plone 4.  Fix some flake8 issues.

Fix some flake8 issues.

Fix some flake8 issues.

Fix another syntax error in tests.

Fix isort issues.
  • Loading branch information
fulv committed Oct 25, 2016
1 parent ea19477 commit 5275c75
Show file tree
Hide file tree
Showing 15 changed files with 432 additions and 102 deletions.
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ cache:
directories:
- eggs
env:
- PLONE_VERSION=4.2
- PLONE_VERSION=4.3
- PLONE_VERSION=5.0
- PLONE_VERSION=5.1
matrix:
allow_failures:
- env: PLONE_VERSION=5.0
fast_finish: true
install:
- sed -ie "s#4.3.x.cfg#$PLONE_VERSION.x.cfg#" buildout.cfg
Expand Down
7 changes: 5 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
Changelog
=========

1.5.1 (unreleased)
1.6 (unreleased)
-------------------

- Drop support for Plone 4.0 and Plone 4.1.
- Add support for Plone 5.0 and 5.1. On Plone 5.x we use z3c.form instead of formlib.
[fulv]

- Drop support for Plone 4.0, Plone 4.1 and Plone 4.2.
Package may work, but we are no longer testing against these versions as Python 2.6 is no longer supported on code analysis.
[hvelarde]

Expand Down
2 changes: 1 addition & 1 deletion buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ parts +=
recipe = plone.recipe.codeanalysis[recommended]
directory = ${buildout:directory}/collective/contentrules/mailtogroup
clean-lines = True
flake8-ignore = E501
flake8-ignore = E501,P001,T000
multiprocessing = True
pre-commit-hook = True
return-status-codes = False
Expand Down
1 change: 1 addition & 0 deletions collective/contentrules/mailtogroup/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# -*- coding: UTF-8 -*-
from zope.i18nmessageid import MessageFactory

mailtogroupMessageFactory = MessageFactory('collective.contentrules.mailtogroup')
Expand Down
2 changes: 1 addition & 1 deletion collective/contentrules/mailtogroup/actions/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#
# -*- coding: UTF-8 -*-
95 changes: 46 additions & 49 deletions collective/contentrules/mailtogroup/actions/mail.py
Original file line number Diff line number Diff line change
@@ -1,79 +1,81 @@
import logging
# -*- coding: UTF-8 -*-
from Acquisition import aq_inner
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from plone.app.contentrules.actions import ActionAddForm, ActionEditForm
from OFS.SimpleItem import SimpleItem
from plone.app.contentrules.actions import ActionAddForm
from plone.app.contentrules.actions import ActionEditForm
from plone.app.contentrules.browser.formhelper import ContentRuleFormWrapper
from plone.app.z3cform.widget import SelectWidget
from plone.autoform import directives
from plone.contentrules.rule.interfaces import IRuleElementData, IExecutable
from plone.contentrules.rule.interfaces import IExecutable
from plone.contentrules.rule.interfaces import IRuleElementData
from plone.registry.interfaces import IRegistry
from plone.stringinterp.interfaces import IStringInterpolator
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone import PloneMessageFactory as _
from Products.CMFPlone.interfaces import IMailSchema
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
from Products.statusmessages.interfaces import IStatusMessage
from OFS.SimpleItem import SimpleItem
from zope import schema
from zope.component import adapts
from zope.component import getUtility
from zope.component.interfaces import ComponentLookupError
from zope.globalrequest import getRequest
from zope.interface import Interface, implements
from zope.interface import implements
from zope.interface import Interface

import logging

logger = logging.getLogger(__file__)


class IMailGroupAction(Interface):
"""Definition of the configuration available for a mail action
"""
""" Definition of the configuration available for a mail action """
subject = schema.TextLine(
title=_(u"Subject"),
description=_(u"Subject of the message"),
title=_(u'Subject'),
description=_(u'Subject of the message'),
required=True
)

source = schema.TextLine(
title=_(u"Email source"),
description=_("The email address that sends the email. If no email is \
provided here, it will use the portal from address."),
title=_(u'Email source'),
description=_('The email address that sends the email. If no email is \
provided here, it will use the portal from address.'),
required=False
)

directives.widget('members', SelectWidget)
members = schema.List(
title=_(u"User(s) to mail"),
description=_("The members where you want to send the e-mail message."),
value_type=schema.Choice(vocabulary=u"plone.principalsource.Users"),
title=_(u'User(s) to mail'),
description=_('The members where you want to send the e-mail message.'),
value_type=schema.Choice(vocabulary=u'plone.principalsource.Users'),
required=False
)

directives.widget('groups', SelectWidget)
groups = schema.List(
title=_(u"Group(s) to mail"),
description=_("The group where you want to send this message. All \
members of the group will receive an email."),
value_type=schema.Choice(vocabulary=u"plone.principalsource.Groups"),
title=_(u'Group(s) to mail'),
description=_('The group where you want to send this message. All \
members of the group will receive an email.'),
value_type=schema.Choice(vocabulary=u'plone.principalsource.Groups'),
required=False
)

message = schema.Text(
title=_(u"Message"),
description=_(u"Type in here the message that you want to mail. Some \
title=_(u'Message'),
description=_(u'Type in here the message that you want to mail. Some \
defined content can be replaced: ${title} will be replaced by the title \
of the item. ${url} will be replaced by the URL of the item. \
${namedirectory} will be replaced by the Title of the folder the rule is applied to. \
${text} will be replace by the body-text-field (if the item has a field named 'text') \
and send it as HTML with a plain-text-fallback."),
${text} will be replace by the body-text-field (if the item has a field named \'text\') \
and send it as HTML with a plain-text-fallback.'),
required=True
)


class MailGroupAction(SimpleItem):
"""
The implementation of the action defined before
"""
""" The implementation of the action defined before """
implements(IMailGroupAction, IRuleElementData)

subject = u''
Expand All @@ -89,13 +91,12 @@ def summary(self):
groups = self.groups and 'the groups ' + ', '.join(self.groups) or ''
members = self.members and 'the members ' + ', '.join(self.members) or ''
both = (groups and members) and ' and ' or ''
return _(u"Email report to ${groups} ${both} ${members}",
return _(u'Email report to ${groups} ${both} ${members}',
mapping=dict(groups=groups, both=both, members=members))


class MailActionExecutor(object):
"""The executor for this action.
"""
""" The executor for this action. """
implements(IExecutable)
adapts(Interface, IMailGroupAction, Interface)

Expand All @@ -108,7 +109,7 @@ def __init__(self, context, element, event):
prefix='plone')

def __call__(self):
mailhost = getToolByName(aq_inner(self.context), "MailHost")
mailhost = getToolByName(aq_inner(self.context), 'MailHost')
if not mailhost:
raise ComponentLookupError('You must have a Mailhost utility to \
execute this action')
Expand All @@ -132,19 +133,19 @@ def __call__(self):
request = getRequest()
if request:
messages = IStatusMessage(request)
msg = _(u"Error sending email from content rule. You must "
"provide a source address for mail "
"actions or enter an email in the portal properties")
messages.add(msg, type=u"error")
msg = _(u'Error sending email from content rule. You must '
'provide a source address for mail '
'actions or enter an email in the portal properties')
messages.add(msg, type=u'error')
return False
from_name = self.mail_settings.email_from_name.strip('"')
self.source = "%s <%s>" % (from_name, from_address)
self.source = '%s <%s>' % (from_name, from_address)

self.recipients = self.get_recipients()

# prepend interpolated message with \n to avoid interpretation
# of first line as header
self.message = "\n%s" % interpolator(self.element.message)
self.message = '\n%s' % interpolator(self.element.message)

self.subject = interpolator(self.element.subject)

Expand Down Expand Up @@ -196,7 +197,7 @@ def create_mime_msg(self):
mime_msg = MIMEMultipart('related')
mime_msg['Subject'] = self.subject
mime_msg['From'] = self.source
# mime_msg['To'] = ""
# mime_msg['To'] = ''
mime_msg['Bcc'] = ', '.join(list_of_recipients)
mime_msg.preamble = 'This is a multi-part message in MIME format.'

Expand All @@ -223,13 +224,11 @@ def create_mime_msg(self):


class MailGroupAddForm(ActionAddForm):
"""
An add form for the mail group action
"""
""" An add form for the mail group action """
schema = IMailGroupAction
label = _(u"Add Mail Group Action")
description = _(u"A mail action can mail different groups and members.")
form_name = _(u"Configure element")
label = _(u'Add Mail Group Action')
description = _(u'A mail action can mail different groups and members.')
form_name = _(u'Configure element')
Type = MailGroupAction
# custom template will allow us to add help text
template = ViewPageTemplateFile('templates/mail.pt')
Expand All @@ -240,13 +239,11 @@ class MailGroupAddFormView(ContentRuleFormWrapper):


class MailGroupEditForm(ActionEditForm):
"""
An edit form for the mail group action
"""
""" An edit form for the mail group action """
schema = IMailGroupAction
label = _(u"Edit Mail group Action")
description = _(u"A mail action can mail different recipient.")
form_name = _(u"Configure element")
label = _(u'Edit Mail group Action')
description = _(u'A mail action can mail different recipient.')
form_name = _(u'Configure element')

# custom template will allow us to add help text
template = ViewPageTemplateFile('templates/mail.pt')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: UTF-8 -*-
41 changes: 41 additions & 0 deletions collective/contentrules/mailtogroup/actions_formlib/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:plone="http://namespaces.plone.org/plone"
xmlns:five="http://namespaces.zope.org/five"
i18n_domain="collective.contentrules.mailtogroup">

<include package="plone.contentrules" />
<include package="plone.contentrules" file="meta.zcml" />


<!-- Email action definition -->
<adapter factory=".mail.MailActionExecutor" />

<browser:page
for="plone.app.contentrules.browser.interfaces.IRuleActionAdding"
name="plone.actions.MailGroup"
class=".mail.MailGroupAddForm"
permission="plone.app.contentrules.ManageContentRules"
/>

<browser:page
for="collective.contentrules.mailtogroup.actions_formlib.mail.IMailGroupAction"
name="edit"
class=".mail.MailGroupEditForm"
permission="plone.app.contentrules.ManageContentRules"
/>

<plone:ruleAction
name="plone.actions.MailGroup"
title="Send email to groups and members"
description="Send an email on the triggering object."
for="*"
event="*"
addview="plone.actions.MailGroup"
editview="edit"
schema=".mail.IMailGroupAction"
factory=".mail.MailGroupAction"
/>

</configure>
Loading

0 comments on commit 5275c75

Please sign in to comment.