Skip to content

Commit

Permalink
Revert "Merge pull request #179 from plone/remove_sendto_cleanedup"
Browse files Browse the repository at this point in the history
This reverts commit ae4a51c, reversing
changes made to 1453b0c.
  • Loading branch information
eleddy committed Feb 17, 2014
1 parent ae4a51c commit 8db491b
Show file tree
Hide file tree
Showing 11 changed files with 263 additions and 162 deletions.
24 changes: 24 additions & 0 deletions Products/CMFPlone/PloneTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
import LinkIntegrityNotificationException


AllowSendto = 'Allow sendto'
permissions.setDefaultRoles(AllowSendto, ('Anonymous', 'Manager', ))

_marker = utils._marker
_icons = {}

Expand Down Expand Up @@ -160,6 +163,27 @@ def getMailHost(self):
"""
return getattr(aq_parent(self), 'MailHost')

security.declareProtected(AllowSendto, 'sendto')
def sendto(self, send_to_address, send_from_address, comment,
subject='Plone', **kwargs):
# Sends a link of a page to someone.
host = self.getMailHost()
template = getattr(self, 'sendto_template')
portal = getToolByName(self, 'portal_url').getPortalObject()
encoding = portal.getProperty('email_charset')
if 'envelope_from' in kwargs:
envelope_from = kwargs['envelope_from']
else:
envelope_from = send_from_address
# Cook from template
message = template(self, send_to_address=send_to_address,
send_from_address=send_from_address,
comment=comment, subject=subject, **kwargs)
message = message.encode(encoding)
host.send(message, mto=send_to_address,
mfrom=envelope_from, subject=subject,
charset='utf-8')

security.declarePublic('validateSingleNormalizedEmailAddress')
def validateSingleNormalizedEmailAddress(self, address):
"""Lower-level function to validate a single normalized email address,
Expand Down
11 changes: 0 additions & 11 deletions Products/CMFPlone/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,6 @@
<allow interface="plone.app.layout.navigation.interfaces.INavigationQueryBuilder" />
</class>

<permission
id="Products.CMFPlone.AllowSendto"
title="Allow sendto" />

<browser:page
for="*"
name="sendto_form"
class=".sendto.SendToForm"
permission="Products.CMFPlone.AllowSendto"
/>

<browser:page
for="*"
name="breadcrumbs_view"
Expand Down
32 changes: 0 additions & 32 deletions Products/CMFPlone/browser/interfaces.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from zope import schema
from zope.interface import Interface

import zope.deferredimport

from Products.CMFPlone import PloneMessageFactory as _


# This is used as a persistent marker interface, we need to provide an upgrade
# step to update the class reference before removing it.
zope.deferredimport.deprecated(
Expand Down Expand Up @@ -312,31 +308,3 @@ def bodyClass(template, view):
""" returns template or view name to mark body tag with
template-${template_id} CSS class
"""


class ISendToForm(Interface):
""" Interface for describing the 'sendto' form """

send_to_address = schema.TextLine(
title=_(u'label_send_to_mail',
default=u'Send to'),
description=_(u'help_send_to_mail',
default=u'The e-mail address to send this link to.'),
required=True
)

send_from_address = schema.TextLine(
title=_(u'label_send_from',
default=u'From'),
description=_(u'help_send_from',
default=u'Your email address.'),
required=True
)

comment = schema.Text(
title=_(u'label_comment',
default=u'Comment'),
description=_(u'help_comment_to_link',
default=u'A comment about this link.'),
required=False
)
119 changes: 0 additions & 119 deletions Products/CMFPlone/browser/sendto.py

This file was deleted.

1 change: 1 addition & 0 deletions Products/CMFPlone/profiles/default/rolemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<role name="Contributor"/>
</permission>
<permission name="Allow sendto" acquire="True">
<role name="Anonymous"/>
<role name="Manager"/>
<role name="Site Administrator"/>
<role name="Member"/>
Expand Down
58 changes: 58 additions & 0 deletions Products/CMFPlone/skins/plone_form_scripts/sendto.cpy
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
## Controller Python Script "sendto"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind state=state
##bind subpath=traverse_subpath
##parameters=
##title=Send an URL to a friend

REQUEST = context.REQUEST

from Products.CMFPlone.utils import transaction_note
from Products.CMFPlone.PloneTool import AllowSendto
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone import PloneMessageFactory as _
from ZODB.POSException import ConflictError

plone_utils = getToolByName(context, 'plone_utils')
mtool = getToolByName(context, 'portal_membership')
site = getToolByName(context, 'portal_url').getPortalObject()
pretty_title_or_id = plone_utils.pretty_title_or_id

if not mtool.checkPermission(AllowSendto, context):
plone_utils.addPortalMessage(_(u'You are not allowed to send this link.'),
'error')
return state.set(status='failure')

# Find the view action.
context_state = context.restrictedTraverse("@@plone_context_state")
url = context_state.view_url()

variables = {'send_from_address' : REQUEST.send_from_address,
'send_to_address' : REQUEST.send_to_address,
'subject' : pretty_title_or_id(context),
'url' : url,
'title' : pretty_title_or_id(context),
'description' : context.Description(),
'comment' : REQUEST.get('comment', None),
'envelope_from' : site.getProperty('email_from_address'),
}

try:
plone_utils.sendto(**variables)
except ConflictError:
raise
except: # TODO To many things could possibly go wrong. So we catch all.
exception = plone_utils.exceptionString()
message = _(u'Unable to send mail: ${exception}',
mapping={u'exception': exception})
plone_utils.addPortalMessage(message, 'error')
return state.set(status='failure')

tmsg = 'Sent page %s to %s' % (url, REQUEST.send_to_address)
transaction_note(tmsg)

plone_utils.addPortalMessage(_(u'Mail sent.'))
return state
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[validators]
validators=validate_sendto

[actions]
action.success = redirect_to_action:string:view
action.failure = redirect_to_action:string:view
39 changes: 39 additions & 0 deletions Products/CMFPlone/skins/plone_form_scripts/validate_sendto.vpy
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## Controller Script Python "validate_sendto"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind state=state
##bind subpath=traverse_subpath
##parameters=send_to_address='',send_from_address=''
##title=validates the email adresses

from Products.CMFPlone import PloneMessageFactory as _
plone_utils=context.plone_utils

if not send_to_address:
state.setError('send_to_address',
_(u'Please submit an email address.'),
'email_required')

if not plone_utils.validateEmailAddresses(send_to_address):
state.setError('send_to_address',
_(u'Please submit a valid email address.'),
'email_required')

if not send_from_address:
state.setError('send_from_address',
_(u'Please submit an email address.'),
'email_required')

if not plone_utils.validateSingleEmailAddress(send_from_address):
state.setError('send_from_address',
_(u'Please submit a valid email address.'),
'email_required')

if state.getErrors():
context.plone_utils.addPortalMessage(
_(u'Please correct the indicated errors.'), 'error')
return state.set(status='failure')
else:
return state
Loading

1 comment on commit 8db491b

@mister-roboto
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TESTS PASSED
Mr.Roboto url : http://jenkins.plone.org/roboto/get_info?push=1dbefe7c40ed4dbb813bc414ebae1c94
plone-5.0-python-2.7 [SUCCESS]

Please sign in to comment.