Send email to task enquirer when it is marked as done #32827
This commit is contained in:
parent
998f04473c
commit
d82a32792c
|
@ -208,7 +208,11 @@ msgstr "Note :"
|
|||
msgid "One document is not mentioned for your information anymore"
|
||||
msgstr "Une note pour information vous concernant a été supprimée"
|
||||
|
||||
#: ../subscribers/document.py:549
|
||||
#: ../subscribers/document.py:429
|
||||
msgid "One of the tasks you requested has been marked as done"
|
||||
msgstr "Une tâche demandée par vous a été marquée comme faite"
|
||||
|
||||
#: ../subscribers/document.py:625
|
||||
msgid "One of your tasks has been cancelled"
|
||||
msgstr "Une de vos tâches a été annulée"
|
||||
|
||||
|
|
|
@ -210,7 +210,11 @@ msgstr ""
|
|||
msgid "One document is not mentioned for your information anymore"
|
||||
msgstr ""
|
||||
|
||||
#: ../subscribers/document.py:549
|
||||
#: ../subscribers/document.py:429
|
||||
msgid "One of the tasks you requested has been marked as done"
|
||||
msgstr ""
|
||||
|
||||
#: ../subscribers/document.py:625
|
||||
msgid "One of your tasks has been cancelled"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -399,6 +399,53 @@ def email_notification_of_tasks_sync(context, event, document, absolute_url, tar
|
|||
log.exception(e)
|
||||
|
||||
|
||||
@grok.subscribe(ITask, IAfterTransitionEvent)
|
||||
def email_notification_of_done_tasks(context, event):
|
||||
if event.transition.id == 'mark-as-done':
|
||||
document = None
|
||||
for obj in aq_chain(context):
|
||||
obj = aq_parent(obj)
|
||||
if IDmsDocument.providedBy(obj):
|
||||
document = obj
|
||||
break
|
||||
if not document:
|
||||
return
|
||||
absolute_url = build_absolute_url(document)
|
||||
|
||||
recipient_emails = []
|
||||
for recipient in _recursiveGetMembersFromIds(api.portal.get(), (context.enquirer or [])):
|
||||
email = recipient.getProperty('email', None)
|
||||
if email:
|
||||
recipient_emails.append(email)
|
||||
|
||||
if not recipient_emails:
|
||||
return
|
||||
|
||||
email_from = api.user.get_current().email or api.portal.get().getProperty(
|
||||
'email_from_address') or 'admin@localhost'
|
||||
|
||||
subject = '%s - %s' % (context.title, document.title)
|
||||
|
||||
body = translate(_('One of the tasks you requested has been marked as done'), context=context.REQUEST) + \
|
||||
'\n\n' + \
|
||||
translate(_('Title: %s'), context=context.REQUEST) % context.title + \
|
||||
'\n\n' + \
|
||||
translate(_('Document: %s'), context=context.REQUEST) % document.title + \
|
||||
'\n\n' + \
|
||||
translate(_('Document Address: %s'), context=context.REQUEST) % absolute_url + \
|
||||
'\n\n\n\n-- \n' + \
|
||||
translate(_('Sent by GED'))
|
||||
body = body.encode('utf-8')
|
||||
|
||||
for recipient_email in recipient_emails:
|
||||
try:
|
||||
context.MailHost.send(body, recipient_email, email_from, subject, charset='utf-8')
|
||||
except Exception as e:
|
||||
# do not abort transaction in case of email error
|
||||
log = logging.getLogger('pfwbged.policy')
|
||||
log.exception(e)
|
||||
|
||||
|
||||
@grok.subscribe(IBaseTask, IObjectAddedEvent)
|
||||
def email_notification_of_tasks(context, event):
|
||||
# go up in the acquisition chain to find the document, this cannot be done
|
||||
|
|
Reference in New Issue