send harvest-error-mails to organization-admins

This commit is contained in:
Stefanie Taepke 2018-06-14 10:57:10 +02:00
parent 7dd82a0e01
commit 304bbcec06
2 changed files with 28 additions and 7 deletions

View File

@ -186,11 +186,11 @@ If you don't specify this setting, the default will be number-sequence.
Send error mails when harvesting fails (optional)
=================================================
If you want to send and email when a Harvest Job fails, you can set the following configuration option in the ini file:
If you want to send an email when a Harvest Job fails, you can set the following configuration option in the ini file:
ckan.harvest.status_mail.errored = True
That way, all CKAN Users who are declared as Sysadmins will receive the Error emails at their configured email address.
That way, all CKAN Users who are declared as Sysadmins will receive the Error emails at their configured email address. If the Harvest-Source of the failing Harvest-Job belongs to an organization, the error-mail will also be sent to the organization-members who have the admin-role if their E-Mail is configured.
If you don't specify this setting, the default will be False.

View File

@ -621,14 +621,35 @@ def send_error_mail(context, source_id, status):
msg += '\n--\n'
msg += toolkit._('You are receiving this email because you are currently set-up as Administrator for {0}. Please do not reply to this email as it was sent from a non-monitored address.').format(config.get('ckan.site_title'))
recipients = []
# gather sysadmins
model = context['model']
sysadmins = model.Session.query(model.User).filter(model.User.sysadmin == True).all()
for sysadmin in sysadmins:
recipients.append({
'name': sysadmin.name,
'email': sysadmin.email
})
# for recipient in email_recipients:
for recipient in sysadmins:
email = {'recipient_name': recipient,
'recipient_email': recipient,
# gather organization-admins
if source.get('organization'):
members = get_action('member_list')(context, {
'id': source['organization']['id'],
'object_type': 'user',
'capacity': 'admin'
})
for member in members:
member_details = get_action('user_show')(context, {'id': member[0]})
if member_details['email']:
recipients.append({
'name': member_details['name'],
'email': member_details['email']
})
for recipient in recipients:
email = {'recipient_name': recipient['name'],
'recipient_email': recipient['email'],
'subject': config.get('ckan.site_title') + ' - Harvesting Job - Error Notification',
'body': msg}