summaryrefslogtreecommitdiffstats
path: root/src/pfwbged/policy/subscribers/document.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/pfwbged/policy/subscribers/document.py')
-rw-r--r--src/pfwbged/policy/subscribers/document.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/pfwbged/policy/subscribers/document.py b/src/pfwbged/policy/subscribers/document.py
index a14edc3..e069519 100644
--- a/src/pfwbged/policy/subscribers/document.py
+++ b/src/pfwbged/policy/subscribers/document.py
@@ -604,6 +604,55 @@ def email_notification_of_canceled_information(context):
log = logging.getLogger('pfwbged.policy')
log.exception(e)
+@grok.subscribe(IValidation, IObjectWillBeRemovedEvent)
+def email_notification_of_canceled_validation(context, event):
+ 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()
+
+ for enquirer in (context.enquirer or []):
+ member = context.portal_membership.getMemberById(enquirer)
+ if member:
+ email_from = member.getProperty('email', None)
+ if email_from:
+ break
+ else:
+ email_from = api.user.get_current().email or api.portal.get().getProperty('email_from_address') or 'admin@localhost'
+
+ 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 not recipient_email:
+ return
+
+ subject = '%s - %s' % (context.title, document.title)
+
+ body = translate(_('A validation request previously sent to you has been deleted'), 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):