Exemplo n.º 1
0
def _send_activation_notification_email(context, organization_dict):

    model = context['model']

    members = p.toolkit.get_action('member_list')(context, {
        'id': organization_dict['id']
    })
    admins = [m for m in members if m[1] == 'user' and m[2] == 'Admin']

    subject = config.get('iati.publisher_activation_email_subject',
                         'IATI Registry Publisher Activation')

    group_link = urljoin(site_url, '/publisher/' + organization_dict['name'])

    for admin in admins:
        user = model.User.get(admin[0])
        if user and user.email:
            user_name = user.fullname or user.name
            content = emailer.publisher_activation_body_template.format(
                user_name=user_name.encode('utf8'),
                group_title=organization_dict['title'].encode('utf8'),
                group_link=group_link,
                user_email=user.email,
                site_url=site_url)
            emailer.send_email(content,
                               subject,
                               user.email,
                               content_type='html')
            log.debug(
                '[email] Publisher activated notification email sent to user {0}'
                .format(user.name))
Exemplo n.º 2
0
def organization_create(context, data_dict):

    # When creating a publisher, if the user is not a sysadmin it will be
    # created as pending, and sysadmins notified

    notify_sysadmins = False
    try:
        p.toolkit.check_access('sysadmin', context, data_dict)
    except p.toolkit.NotAuthorized:
        # Not a sysadmin, create as pending and notify sysadmins (if all went
        # well)
        context['__iati_state_pending'] = True
        data_dict['state'] = 'approval_needed'
        notify_sysadmins = True

    org_dict = create_core.organization_create(context, data_dict)

    if data_dict.get(
            'state', ''
    ) == "approval_needed":  # Send email if created user is not sysadmin
        try:
            user = context['auth_user_obj']
            body = emailer.new_publisher_email_to_publisher_body.format(
                user_name=context['user'])
            subject = "[IATI Registry] New Publisher: {0} - Status: {1}".format(
                data_dict['title'].encode('utf8'), "Pending")
            emailer.send_email(body, subject, user.email, content_type='html')
        except Exception as e:
            log.error("Failed to send notification email to publisher")
            log.error(e)

    if notify_sysadmins:
        _send_new_publisher_email(context, org_dict)

    return org_dict
Exemplo n.º 3
0
def send_data_published_notification(context, owner_org, package_title):
    publisher_link = urljoin(site_url, '/publisher/' + owner_org)
    try:
        user = context['auth_user_obj']
        body = emailer.data_published_email_notification_body.format(
            user_name=context['user'], publisher_link=publisher_link)
        subject = "[IATI Registry] Data: {0} is published".format(
            package_title.encode('utf8'))
        emailer.send_email(body, subject, user.email, content_type='html')
    except Exception as e:
        log.error("Failed to send data published notification")
        log.error(e)
    return None
Exemplo n.º 4
0
def _send_new_publisher_email(context, organization_dict):

    publisher_link = urljoin(site_url, '/publisher/' + organization_dict['name'])

    for sysadmin in _get_sysadmins(context):
        if sysadmin.email:
            body = emailer.new_publisher_body_template.format(
               sysadmin_name=sysadmin.name,
               user_name=context['user'],
               site_url=site_url,
               publisher_title=organization_dict['title'].encode('utf8'),
               publisher_link=publisher_link,
            )
            subject = "[IATI Registry] New Publisher: {0}".format(organization_dict['title'].encode('utf8'))
            emailer.send_email(body, subject, sysadmin.email)
            log.debug('[email] New publisher notification email sent to sysadmin {0}'.format(sysadmin.name))
Exemplo n.º 5
0
def _send_new_publisher_email(context, organization_dict):

    publisher_link = urljoin(site_url, '/publisher/' + organization_dict['name'])

    for sysadmin in _get_sysadmins(context):
        if sysadmin.email:
            body = emailer.new_publisher_body_template.format(
               sysadmin_name=sysadmin.name,
               user_name=context['user'],
               site_url=site_url,
               publisher_title=organization_dict['title'].encode('utf8'),
               publisher_link=publisher_link,
            )
            subject = "[IATI Registry] New Publisher: {0}".format(organization_dict['title'].encode('utf8'))
            emailer.send_email(body, subject, sysadmin.email)
            log.debug('[email] New publisher notification email sent to sysadmin {0}'.format(sysadmin.name))
Exemplo n.º 6
0
def _send_activation_notification_email(context, organization_dict):

    model = context['model']

    members = p.toolkit.get_action('member_list')(context, {'id': organization_dict['id']})
    admins = [m for m in members if m[1] == 'user' and m[2] == 'Admin']

    subject = config.get('iati.publisher_activation_email_subject', 'IATI Registry Publisher Activation')

    group_link = urljoin(site_url, '/publisher/' + organization_dict['name'])

    for admin in admins:
        user = model.User.get(admin[0])
        if user and user.email:
            user_name = user.fullname or user.name
            content = emailer.publisher_activation_body_template.format(user_name=user_name.encode('utf8'),
                    group_title=organization_dict['title'].encode('utf8'), group_link=group_link, user_email=user.email,
                    site_url=site_url)
            emailer.send_email(content, subject, user.email)
            log.debug('[email] Publisher activated notification email sent to user {0}'.format(user.name))