From 79a5a45ba0dfc91ab7239f32628fceec0b6412b3 Mon Sep 17 00:00:00 2001 From: Brian Bonnlander Date: Thu, 2 Jun 2022 23:30:08 +0000 Subject: [PATCH 1/6] make it possible to get email address --- .gitignore | 4 +++- ckanext/harvest/logic/action/get.py | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index df617f797..d01767a69 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,6 @@ development.ini node_modules *.project .eggs -.vscode/ \ No newline at end of file +.idea/ +.vscode/ + diff --git a/ckanext/harvest/logic/action/get.py b/ckanext/harvest/logic/action/get.py index 011dd668d..c9c2df3fa 100644 --- a/ckanext/harvest/logic/action/get.py +++ b/ckanext/harvest/logic/action/get.py @@ -450,9 +450,13 @@ def harvest_get_notifications_recipients(context, data_dict): 'capacity': 'admin' }) + # Get access to email address by running action as admin user + context['user'] = 'admin' for member in members: - member_details = p.toolkit.get_action( - 'user_show')(context, {'id': member[0]}) + member_details = p.toolkit.get_action('user_show')(context, { + 'id': member[0], + 'include_plugin_extras': True + }) if member_details.get('email', None): recipients.append({ From cdf767d1e941013ea5e6411d3135aed1f4a76afd Mon Sep 17 00:00:00 2001 From: Brian Bonnlander Date: Mon, 6 Jun 2022 19:50:10 +0000 Subject: [PATCH 2/6] Avoid crashing mailer when sysadmin has no email --- ckanext/harvest/logic/action/get.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ckanext/harvest/logic/action/get.py b/ckanext/harvest/logic/action/get.py index c9c2df3fa..10790e76b 100644 --- a/ckanext/harvest/logic/action/get.py +++ b/ckanext/harvest/logic/action/get.py @@ -436,11 +436,14 @@ def harvest_get_notifications_recipients(context, data_dict): model.User.sysadmin == True # noqa: E712 ).all() + # Send mail to all sysadmins with a non-empty email address for sysadmin in sysadmins: - recipients.append({ - 'name': sysadmin.name, - 'email': sysadmin.email - }) + email_address = sysadmin.email + if email_address and email_address.strip(): + recipients.append({ + 'name': sysadmin.name, + 'email': sysadmin.email + }) # gather organization-admins if source.get('organization'): From 053d6e99ea031b10bdf73a5ee4f1cd7c2fa1c677 Mon Sep 17 00:00:00 2001 From: Brian Bonnlander Date: Tue, 7 Jun 2022 16:42:48 +0000 Subject: [PATCH 3/6] Filter out users with no email address --- ckanext/harvest/logic/action/get.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ckanext/harvest/logic/action/get.py b/ckanext/harvest/logic/action/get.py index 10790e76b..f971fd4e9 100644 --- a/ckanext/harvest/logic/action/get.py +++ b/ckanext/harvest/logic/action/get.py @@ -461,10 +461,11 @@ def harvest_get_notifications_recipients(context, data_dict): 'include_plugin_extras': True }) - if member_details.get('email', None): + email_address = member_details.get('email', None) + if email_address and email_address.strip(): recipients.append({ 'name': member_details['name'], - 'email': member_details['email'] + 'email': email_address }) return recipients From f5e4e1c0932304ed2f50b39b853e09e88f1f865c Mon Sep 17 00:00:00 2001 From: bonnland Date: Thu, 9 Jun 2022 13:32:21 -0600 Subject: [PATCH 4/6] Update ckanext/harvest/logic/action/get.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: AdriĆ  Mercader --- ckanext/harvest/logic/action/get.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckanext/harvest/logic/action/get.py b/ckanext/harvest/logic/action/get.py index f971fd4e9..993f263a1 100644 --- a/ckanext/harvest/logic/action/get.py +++ b/ckanext/harvest/logic/action/get.py @@ -454,7 +454,7 @@ def harvest_get_notifications_recipients(context, data_dict): }) # Get access to email address by running action as admin user - context['user'] = 'admin' + context['user'] = p.toolkit.get_action('get_site_user')({'ignore_auth': True})['name'] for member in members: member_details = p.toolkit.get_action('user_show')(context, { 'id': member[0], From 9dbe02a606b5a5277a599142ff6e60b0195b3e18 Mon Sep 17 00:00:00 2001 From: Brian Bonnlander Date: Thu, 9 Jun 2022 20:07:33 +0000 Subject: [PATCH 5/6] Remove request for extra fields --- ckanext/harvest/logic/action/get.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ckanext/harvest/logic/action/get.py b/ckanext/harvest/logic/action/get.py index 993f263a1..c674ef28b 100644 --- a/ckanext/harvest/logic/action/get.py +++ b/ckanext/harvest/logic/action/get.py @@ -456,10 +456,7 @@ def harvest_get_notifications_recipients(context, data_dict): # Get access to email address by running action as admin user context['user'] = p.toolkit.get_action('get_site_user')({'ignore_auth': True})['name'] for member in members: - member_details = p.toolkit.get_action('user_show')(context, { - 'id': member[0], - 'include_plugin_extras': True - }) + member_details = p.toolkit.get_action('user_show')(context, {'id': member[0]}) email_address = member_details.get('email', None) if email_address and email_address.strip(): From 125ec71f89e71f34375e7211608ba2605eb90b26 Mon Sep 17 00:00:00 2001 From: Brian Bonnlander Date: Thu, 9 Jun 2022 20:09:43 +0000 Subject: [PATCH 6/6] Fix indents --- ckanext/harvest/logic/action/get.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ckanext/harvest/logic/action/get.py b/ckanext/harvest/logic/action/get.py index c674ef28b..954fdac1d 100644 --- a/ckanext/harvest/logic/action/get.py +++ b/ckanext/harvest/logic/action/get.py @@ -456,7 +456,8 @@ def harvest_get_notifications_recipients(context, data_dict): # Get access to email address by running action as admin user context['user'] = p.toolkit.get_action('get_site_user')({'ignore_auth': True})['name'] for member in members: - member_details = p.toolkit.get_action('user_show')(context, {'id': member[0]}) + member_details = p.toolkit.get_action( + 'user_show')(context, {'id': member[0]}) email_address = member_details.get('email', None) if email_address and email_address.strip():