From 19b501b5caa8b11a94c3983fec14440a9a2ef501 Mon Sep 17 00:00:00 2001 From: Nicolas Demonte Date: Fri, 18 Jan 2019 16:15:17 +0100 Subject: [PATCH] Email notification for task cancelling #22006 --- src/pfwbged/policy/locales/pfwbged.policy.pot | 4 ++ src/pfwbged/policy/menu.py | 2 +- src/pfwbged/policy/subscribers/document.py | 41 +++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/pfwbged/policy/locales/pfwbged.policy.pot b/src/pfwbged/policy/locales/pfwbged.policy.pot index e223447..ed0a748 100644 --- a/src/pfwbged/policy/locales/pfwbged.policy.pot +++ b/src/pfwbged/policy/locales/pfwbged.policy.pot @@ -166,6 +166,10 @@ msgstr "" msgid "One of your tasks has been cancelled" msgstr "" +#: ../subscribers/document.py:480 +msgid "One of your tasks has been cancelled" +msgstr "" + #: ../browser/ask_opinion.py:25 msgid "Opinion application for version ${version}" msgstr "" diff --git a/src/pfwbged/policy/menu.py b/src/pfwbged/policy/menu.py index 41255ca..0d1aca6 100644 --- a/src/pfwbged/policy/menu.py +++ b/src/pfwbged/policy/menu.py @@ -184,7 +184,7 @@ class CustomMenu(menu.WorkflowMenu): description = '' if action['id'] in ('submit', 'ask_opinion', 'attribute', - 'to_process', 'refuse', 'send_by_email'): + 'to_process', 'refuse', 'send_by_email', 'cancel-attribution'): cssClass += " overlay-form-reload" if action['id'] in ('send_with_docbow',): diff --git a/src/pfwbged/policy/subscribers/document.py b/src/pfwbged/policy/subscribers/document.py index 3361ae4..ad0afa8 100644 --- a/src/pfwbged/policy/subscribers/document.py +++ b/src/pfwbged/policy/subscribers/document.py @@ -454,6 +454,47 @@ def email_notification_of_refused_task(context, event): log.exception(e) +def email_notification_of_canceled_subtask(context): + 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 = document.absolute_url() + + responsible = context.responsible[0] + principal = api.user.get(responsible) + if not principal: + principal = api.group.get(responsible) + recipient_email = principal.getProperty('email') if principal else None + if recipient_email: + + 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 your tasks has been cancelled'), 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) % document.absolute_url() + \ + '\n\n\n\n-- \n' + \ + translate(_('Sent by GED')) + body = body.encode('utf-8') + + 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(IDmsDocument, IObjectModifiedEvent) def log_some_history(context, event):