Read mail settings from new (Plone 5) registry.

This commit is contained in:
Timo Stollenwerk 2014-12-13 16:20:08 +01:00
parent e11471a44e
commit 785bc7b890
4 changed files with 35 additions and 24 deletions

View File

@ -7,6 +7,9 @@ Changelog
- Updated portuguese pt-br translation.
[jtmolon]
- Read mail settings from new (Plone 5) registry.
[timo]
2.3.3 (2014-10-23)
------------------

View File

@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_base, aq_inner
from zope.component import getUtility
from Products.CMFCore.utils import getToolByName
from Products.CMFCore.interfaces._content import IDiscussionResponse
from Products.CMFPlone.interfaces.controlpanel import IMailSchema
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
@ -152,12 +150,11 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
def mailhost_warning(self):
"""Returns true if mailhost is not configured properly.
"""
# Copied from plone.app.controlpanel/plone/app/controlpanel/overview.py
mailhost = getToolByName(aq_inner(self.context), 'MailHost', None)
if mailhost is None:
return True
mailhost = getattr(aq_base(mailhost), 'smtp_host', None)
email = getattr(aq_inner(self.context), 'email_from_address', None)
# Copied from Products.CMFPlone/controlpanel/browser/overview.py
registry = getUtility(IRegistry)
mail_settings = registry.forInterface(IMailSchema, prefix='plone')
mailhost = mail_settings.smtp_host
email = mail_settings.email_from_address
if mailhost and email:
return False
return True
@ -177,7 +174,7 @@ class DiscussionSettingsControlPanel(controlpanel.ControlPanelFormWrapper):
def unmigrated_comments_warning(self):
"""Returns true if site contains unmigrated comments.
"""
catalog = getToolByName(aq_inner(self.context), 'portal_catalog', None)
catalog = getToolByName(self.context, 'portal_catalog', None)
count_comments_old = catalog.searchResults(
object_provides=IDiscussionResponse.__identifier__)
if count_comments_old:

View File

@ -9,6 +9,7 @@ from datetime import datetime
from smtplib import SMTPException
from zope.annotation.interfaces import IAnnotatable
from zope.component import getUtility
from zope.event import notify
from zope.component.factory import Factory
@ -31,8 +32,6 @@ from Products.CMFPlone.utils import safe_unicode
from OFS.Traversable import Traversable
from plone.registry.interfaces import IRegistry
from plone.app.discussion.events import CommentAddedEvent
from plone.app.discussion.events import CommentRemovedEvent
from plone.app.discussion.events import ReplyAddedEvent
@ -43,8 +42,11 @@ from plone.app.discussion.interfaces import IComment
from plone.app.discussion.interfaces import IConversation
from plone.app.discussion.interfaces import IDiscussionSettings
from plone.registry.interfaces import IRegistry
from Products.CMFCore.CMFCatalogAware import CatalogAware
from Products.CMFCore.CMFCatalogAware import WorkflowAware
from Products.CMFPlone.interfaces.controlpanel import IMailSchema
from OFS.role import RoleManager
from AccessControl import ClassSecurityInfo
@ -329,9 +331,9 @@ def notify_user(obj, event):
# Get informations that are necessary to send an email
mail_host = getToolByName(obj, 'MailHost')
portal_url = getToolByName(obj, 'portal_url')
portal = portal_url.getPortalObject()
sender = portal.getProperty('email_from_address')
registry = getUtility(IRegistry)
mail_settings = registry.forInterface(IMailSchema, prefix='plone')
sender = mail_settings.email_from_address
# Check if a sender address is available
if not sender:
@ -403,9 +405,9 @@ def notify_moderator(obj, event):
# Get informations that are necessary to send an email
mail_host = getToolByName(obj, 'MailHost')
portal_url = getToolByName(obj, 'portal_url')
portal = portal_url.getPortalObject()
sender = portal.getProperty('email_from_address')
registry = getUtility(IRegistry)
mail_settings = registry.forInterface(IMailSchema, prefix='plone')
sender = mail_settings.email_from_address
if settings.moderator_email:
mto = settings.moderator_email

View File

@ -7,11 +7,13 @@ from Acquisition import aq_base
from zope.component import createObject
from zope.component import getSiteManager
from zope.component import queryUtility
from zope.component import getUtility
from plone.app.testing import TEST_USER_ID, setRoles
from Products.MailHost.interfaces import IMailHost
from Products.CMFPlone.tests.utils import MockMailHost
from Products.CMFPlone.interfaces import IMailSchema
from plone.registry.interfaces import IRegistry
@ -34,7 +36,9 @@ class TestUserNotificationUnit(unittest.TestCase):
sm.unregisterUtility(provided=IMailHost)
sm.registerUtility(mailhost, provided=IMailHost)
# We need to fake a valid mail setup
self.portal.email_from_address = "portal@plone.test"
registry = getUtility(IRegistry)
mail_settings = registry.forInterface(IMailSchema, prefix='plone')
mail_settings.email_from_address = "portal@plone.test"
self.mailhost = self.portal.MailHost
# Enable user notification setting
registry = queryUtility(IRegistry)
@ -122,7 +126,9 @@ class TestUserNotificationUnit(unittest.TestCase):
def test_do_not_notify_user_when_no_sender_is_available(self):
# Set sender mail address to none and make sure no email is send to
# the moderator.
self.portal.email_from_address = None
registry = getUtility(IRegistry)
mail_settings = registry.forInterface(IMailSchema, prefix='plone')
mail_settings.email_from_address = None
comment = createObject('plone.Comment')
comment.text = 'Comment text'
comment.user_notification = True
@ -132,7 +138,6 @@ class TestUserNotificationUnit(unittest.TestCase):
comment.text = 'Comment text'
self.conversation.addComment(comment)
self.assertEqual(len(self.mailhost.messages), 0)
def test_notify_only_once(self):
@ -172,7 +177,9 @@ class TestModeratorNotificationUnit(unittest.TestCase):
sm.unregisterUtility(provided=IMailHost)
sm.registerUtility(mailhost, provided=IMailHost)
# We need to fake a valid mail setup
self.portal.email_from_address = "portal@plone.test"
registry = getUtility(IRegistry)
mail_settings = registry.forInterface(IMailSchema, prefix='plone')
mail_settings.email_from_address = "portal@plone.test"
self.mailhost = self.portal.MailHost
# Enable comment moderation
self.portal.portal_types['Document'].allow_discussion = True
@ -255,7 +262,9 @@ class TestModeratorNotificationUnit(unittest.TestCase):
def test_do_not_notify_moderator_when_no_sender_is_available(self):
# Set sender mail address to nonw and make sure no email is send to the
# moderator.
self.portal.email_from_address = None
registry = getUtility(IRegistry)
mail_settings = registry.forInterface(IMailSchema, prefix='plone')
mail_settings.email_from_address = None
comment = createObject('plone.Comment')
comment.text = 'Comment text'