• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OCHA-DAP / hdx-ckan / #5218

11 Apr 2024 11:29AM UTC coverage: 71.375% (+0.06%) from 71.316%
#5218

Pull #6302

coveralls-python

danmihaila
HDX-9444 HDX-9443 HDX-9442 review email subject
Pull Request #6302: Feature/dev org join hdx 9447

98 of 110 new or added lines in 10 files covered. (89.09%)

14 existing lines in 2 files now uncovered.

11667 of 16346 relevant lines covered (71.38%)

0.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.08
/ckanext-hdx_users/ckanext/hdx_users/actions/misc.py
1
import datetime
1✔
2
import logging
1✔
3

4
import ckan.lib.helpers as h
1✔
5
import ckan.plugins.toolkit as tk
1✔
6
import ckanext.hdx_users.helpers.mailer as hdx_mailer
1✔
7
import ckanext.hdx_org_group.helpers.analytics as org_analytics
1✔
8
import ckan.model as model
1✔
9

10
log = logging.getLogger(__name__)
1✔
11
_check_access = tk.check_access
1✔
12
_get_or_bust = tk.get_or_bust
1✔
13
NotFound = tk.ObjectNotFound
1✔
14
get_action = tk.get_action
1✔
15
config = tk.config
1✔
16
g = tk.g
1✔
17
_ = tk._
1✔
18

19

20
def hdx_send_new_org_request(context, data_dict):
1✔
21
    _check_access('hdx_send_new_org_request', context, data_dict)
1✔
22

23
    email = config.get('hdx.orgrequest.email', None)
1✔
24
    if not email:
1✔
25
        email = 'hdx@un.org'
×
26
    display_name = 'HDX Feedback'
1✔
27

28
    ckan_username = g.user
1✔
29
    ckan_email = ''
1✔
30
    if g.userobj:
1✔
31
        ckan_email = g.userobj.email
1✔
32
    user_obj = model.User.get(ckan_username)
1✔
33
    if user_obj:
1✔
34
        user_fullname = user_obj.fullname or user_obj.display_name
1✔
35
    else:
NEW
36
        user_fullname = 'User'
×
37
    if config.get('hdx.onboarding.send_confirmation_email', 'false') == 'true':
1✔
38
        hdx_email = config.get('hdx.faqrequest.email', 'hdx@humdata.org')
1✔
39
        email_data = {
1✔
40
            'org_name': data_dict.get('name', ''),
41
            'org_description': data_dict.get('description', ''),
42
            'org_website': data_dict.get('website', ''),
43
            'data_type': data_dict.get('data_type', ''),
44
            'data_already_available': data_dict.get('data_already_available', ''),
45
            'data_already_available_link': data_dict.get('data_already_available_link', ''),
46
            'user_fullname': user_fullname,
47
            'requestor_hdx_username': ckan_username,
48
            'user_role': data_dict.get('role', ''),
49
            'requestor_hdx_email': ckan_email,
50
            'request_time': datetime.datetime.now().isoformat(),
51
        }
52
        subject = u'Request to create a new organisation on HDX'
1✔
53
        hdx_mailer.mail_recipient([{'display_name': 'Humanitarian Data Exchange (HDX)', 'email': hdx_email}],
1✔
54
                                  subject, email_data, sender_name=user_fullname,
55
                                  sender_email=ckan_email,
56
                                  snippet='email/content/new_org_request_hdx_team_notification.html')
57

58
        subject = u'Thank you for your request to create an organisation on HDX'
1✔
59
        email_data = {
1✔
60
            'user_fullname': user_fullname,
61
        }
62
        hdx_mailer.mail_recipient([{'display_name': user_fullname, 'email': ckan_email}],
1✔
63
                                  subject, email_data, footer=ckan_email,
64
                                  snippet='email/content/new_org_request_confirmation_to_user.html')
65

66
        org_analytics.OrganizationRequestAnalyticsSender(data_dict.get('name', ''), data_dict.get('org_type', '')) \
1✔
67
            .send_to_queue()
68

69

70
def hdx_send_request_data_auto_approval(context, data_dict):
1✔
71
    _check_access('hdx_send_request_data_auto_approval', context, {'package_id': data_dict.get('package_id')})
1✔
72

73
    model = context['model']
1✔
74

75
    req_dict = get_action('requestdata_request_show')(context, {'id': data_dict.get('id'),
1✔
76
                                                                'package_id': data_dict.get('package_id')})
77
    pkg_dict = get_action('package_show')(context, {'id': data_dict.get('package_id')})
1✔
78
    org_dict = get_action('organization_show')(context, {'id': pkg_dict.get('owner_org')})
1✔
79
    maintainer_obj = model.User.get(pkg_dict.get('maintainer'))
1✔
80

81
    subject = u'The metadata-only dataset you requested to access is now public: %s' % pkg_dict.get('name')
1✔
82

83
    email_data = {
1✔
84
        'user_fullname': req_dict.get('sender_name'),
85
        'org_name': org_dict.get('title'),
86
        'dataset_link': h.url_for('dataset_read', id=data_dict.get('package_id'), qualified=True),
87
        'dataset_title': pkg_dict.get('name')
88
    }
89
    hdx_mailer.mail_recipient([{'display_name': data_dict.get('requested_by'), 'email': req_dict.get('email_address')}],
1✔
90
                              subject, email_data, footer=data_dict.get('send_to'),
91
                              snippet='email/content/request_data_auto_approval_to_user.html')
92

93
    subject = u'%s’s request for access to one of your datasets: %s is archived' % (req_dict.get('sender_name'), pkg_dict.get('name'))
1✔
94

95
    email_data = {
1✔
96
        'user_fullname': req_dict.get('sender_name'),
97
        'user_email': req_dict.get('email_address'),
98
        'dataset_link': h.url_for('dataset_read', id=data_dict.get('package_id'), qualified=True),
99
        'dataset_title': pkg_dict.get('name')
100
    }
101
    hdx_mailer.mail_recipient([{'display_name': maintainer_obj.fullname, 'email': maintainer_obj.email}],
1✔
102
                              subject, email_data, footer=maintainer_obj.email,
103
                              snippet='email/content/request_data_auto_approval_to_admins.html')
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc