Skip to content

Commit

Permalink
Merge 89dc7f2 into 27cd8bf
Browse files Browse the repository at this point in the history
  • Loading branch information
tomgross committed Apr 12, 2018
2 parents 27cd8bf + 89dc7f2 commit 8c16013
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ env:
- PLONE_VERSION=5.0
- PLONE_VERSION=5.1
before_install:
- pip install --upgrade pip setuptools zc.buildout
- if [ $PLONE_VERSION == 5.0 ]; then pip install --upgrade setuptools==33.1.1; fi
- if [ $PLONE_VERSION == 5.1 ]; then pip install --upgrade setuptools==33.1.1; fi
- if [ $PLONE_VERSION == 4.3 ]; then pip install --upgrade setuptools==26.1.1 zc.buildout==2.9.5; fi
- if [ $PLONE_VERSION == 5.0 ]; then pip install -r https://raw.githubusercontent.com/plone/buildout.coredev/5.0/requirements.txt; fi
- if [ $PLONE_VERSION == 5.1 ]; then pip install -r https://raw.githubusercontent.com/plone/buildout.coredev/5.1/requirements.txt; fi
install:
- sed -ie "s#test-5.0#test-$PLONE_VERSION#" buildout.cfg
- buildout annotate -c buildout.cfg
Expand Down
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Changelog
1.0rc4 (unreleased)
-------------------

- Nothing changed yet.
- Use email of current user, instead of system email
[tomgross]


1.0rc3 (2017-11-08)
Expand Down
3 changes: 3 additions & 0 deletions redomino/tokenrole/browser/send_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ def nextURL(self):
return "%s/%s" % (self.context.absolute_url(), '@@token_manage')

def send_mail(self, data):
current_user = api.user.get_current()
sender = current_user.getProperty('email', default=None)
email_list = data['email_list']
subject = safe_unicode(data['subject'])
text = safe_unicode(data['text'])
Expand All @@ -104,6 +106,7 @@ def send_mail(self, data):
try:
for recipient in email_list:
api.portal.send_email(
sender=sender,
recipient=recipient, subject=subject, body=message)
return _('token_role_send_ok_mail', default=u'Token email sent.')
except ValueError:
Expand Down
84 changes: 84 additions & 0 deletions redomino/tokenrole/tests/test_mail.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2010 Redomino srl (http://redomino.com)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

from email import message_from_string
from datetime import datetime
from plone import api
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.app.testing import login
from redomino.tokenrole.testing import REDOMINO_TOKENROLE_INTEGRATION_TESTING
from redomino.tokenrole.interfaces import ITokenURL
from redomino.tokenrole.interfaces import ITokenInfoSchema
from redomino.tokenrole.validators import isEmail
from redomino.tokenrole.browser.send_token import TokenSendForm
from redomino.tokenrole.browser.token_manage import TokenDeleteForm
from Products.CMFPlone.tests.utils import MockMailHost
from Products.MailHost.interfaces import IMailHost
from zope.component import getSiteManager
from zope.component import getUtility


import unittest


class TestMailing(unittest.TestCase):
""" Test mailing """
layer = REDOMINO_TOKENROLE_INTEGRATION_TESTING


def setUp(self):
self.portal = self.layer['portal']
mails = self.portal.MailHost = MockMailHost('MailHost')
# configure mailhost
mails.smtp_host = 'localhost'
api.portal.set_registry_record(
'plone.email_from_name', u'Portal Owner', )
api.portal.set_registry_record(
'plone.email_from_address', 'sender@example.org', )
sm = getSiteManager(self.portal)
sm.unregisterUtility(provided=IMailHost)
sm.registerUtility(mails, IMailHost)
self.mailhost = api.portal.get_tool('MailHost')
setRoles(self.portal, TEST_USER_ID, ['Manager'])
self.doc = api.content.create(self.portal, 'Document', id='test-doc')
self.token = ITokenInfoSchema(self.doc)
self.token.token_id = '0815'
self.token.token_end = datetime(2018, 1, 30, 12, 45)

def test_memberemail(self):
user = api.user.create(email='foo@example.com', username='foo')
login(self.portal, 'foo')
#user = api.user.get(userid=TEST_USER_ID)
#user.setMemberProperties(mapping={'email': 'foo@example.com', })
form = TokenSendForm(self.doc, self.layer['request'])
data = {'email_list': ['bar@example.org'],
'subject': 'Token send',
'text': 'Token bla bla ${date}s ${url}s ',
'token_id': '0815'}
self.mailhost.reset()
form.send_mail(data)
msg = message_from_string(self.mailhost.messages[0])
self.assertEqual(msg['To'], 'bar@example.org')
self.assertEqual(msg['From'], 'foo@example.com')
self.assertEqual(msg['Subject'], '=?utf-8?q?Token_send?=')
self.assertIn(
'Token bla bla Jan 30, 2018 http://nohost/plone/test-doc?token=3D0815=20',
msg.get_payload())


# EOF

0 comments on commit 8c16013

Please sign in to comment.