-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Merge pull request #179 from plone/remove_sendto_cleanedup"
- Loading branch information
Showing
11 changed files
with
263 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
6 changes: 6 additions & 0 deletions
6
Products/CMFPlone/skins/plone_form_scripts/sendto.cpy.metadata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
39
Products/CMFPlone/skins/plone_form_scripts/validate_sendto.vpy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
8db491b
There was a problem hiding this comment.
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]