Example #1
0
def reviews_notification(self, context):
    timestamp = timezone.now()
    event_type = utils.find_subscription_type('global_reviews')
    template = context['template'] + '.html.mako'
    for user_id in context['email_recipients']:
        user = OSFUser.load(user_id)
        subscriptions = get_user_subscriptions(user, event_type)
        for notification_type in subscriptions:
            check_user_subscribe = subscriptions[
                notification_type] and user_id in subscriptions[
                    notification_type] and notification_type != 'none'  # check if user is subscribed to this type of notifications
            if check_user_subscribe:
                node_lineage_ids = get_node_lineage(
                    context.get('reviewable').node) if context.get(
                        'reviewable').node else []
                context['user'] = user
                context['no_future_emails'] = notification_type == 'none'
                send_type = notification_type if notification_type != 'none' else 'email_transactional'
                message = mails.render_message(template, **context)
                digest = NotificationDigest(user=user,
                                            timestamp=timestamp,
                                            send_type=send_type,
                                            event='global_reviews',
                                            message=message,
                                            node_lineage=node_lineage_ids)
                digest.save()
Example #2
0
def remove_notifications(email_notification_ids=None):
    """Remove sent emails.

    :param email_notification_ids:
    :return:
    """
    for email_id in email_notification_ids:
        NotificationDigest.remove(Q('_id', 'eq', email_id))
Example #3
0
def remove_notifications(email_notification_ids=None):
    """Remove sent emails.

    :param email_notification_ids:
    :return:
    """
    for email_id in email_notification_ids:
        NotificationDigest.remove(Q('_id', 'eq', email_id))
Example #4
0
def store_emails(recipient_ids,
                 notification_type,
                 event,
                 user,
                 node,
                 timestamp,
                 abstract_provider=None,
                 template=None,
                 **context):
    """Store notification emails

    Emails are sent via celery beat as digests
    :param recipient_ids: List of user ids to send mail to.
    :param notification_type: from constants.Notification_types
    :param event: event that triggered notification
    :param user: user who triggered the notification
    :param node: instance of Node
    :param timestamp: time event happened
    :param context:
    :return: --
    """
    if notification_type == 'none':
        return

    # If `template` is not specified, default to using a template with name `event`
    template = '{template}.html.mako'.format(template=template or event)

    # user whose action triggered email sending
    context['user'] = user
    node_lineage_ids = get_node_lineage(node) if node else []

    for recipient_id in recipient_ids:
        if recipient_id == user._id:
            continue
        recipient = OSFUser.load(recipient_id)
        if recipient.is_disabled:
            continue
        context['localized_timestamp'] = localize_timestamp(
            timestamp, recipient)
        context['recipient'] = recipient
        message = mails.render_message(template, **context)
        digest = NotificationDigest(timestamp=timestamp,
                                    send_type=notification_type,
                                    event=event,
                                    user=recipient,
                                    message=message,
                                    node_lineage=node_lineage_ids,
                                    provider=abstract_provider)
        digest.save()
Example #5
0
def store_emails(recipient_ids, notification_type, event, user, node, timestamp, abstract_provider=None, template=None, **context):
    """Store notification emails

    Emails are sent via celery beat as digests
    :param recipient_ids: List of user ids to send mail to.
    :param notification_type: from constants.Notification_types
    :param event: event that triggered notification
    :param user: user who triggered the notification
    :param node: instance of Node
    :param timestamp: time event happened
    :param context:
    :return: --
    """
    if notification_type == 'none':
        return

    # If `template` is not specified, default to using a template with name `event`
    template = '{template}.html.mako'.format(template=template or event)

    # user whose action triggered email sending
    context['user'] = user
    node_lineage_ids = get_node_lineage(node) if node else []

    for recipient_id in recipient_ids:
        if recipient_id == user._id:
            continue
        recipient = OSFUser.load(recipient_id)
        if recipient.is_disabled:
            continue
        context['localized_timestamp'] = localize_timestamp(timestamp, recipient)
        context['recipient'] = recipient
        message = mails.render_message(template, **context)
        digest = NotificationDigest(
            timestamp=timestamp,
            send_type=notification_type,
            event=event,
            user=recipient,
            message=message,
            node_lineage=node_lineage_ids,
            provider=abstract_provider
        )
        digest.save()
Example #6
0
def store_emails(recipient_ids, notification_type, event, user, node,
                 timestamp, **context):
    """Store notification emails

    Emails are sent via celery beat as digests
    :param recipient_ids: List of user ids to send mail to.
    :param notification_type: from constants.Notification_types
    :param event: event that triggered notification
    :param user: user who triggered the notification
    :param node: instance of Node
    :param timestamp: time event happened
    :param context:
    :return: --
    """

    if notification_type == 'none':
        return

    template = event + '.html.mako'
    # user whose action triggered email sending
    context['user'] = user
    node_lineage_ids = get_node_lineage(node) if node else []

    for recipient_id in recipient_ids:
        if recipient_id == user._id:
            continue
        recipient = OSFUser.load(recipient_id)
        context['localized_timestamp'] = localize_timestamp(
            timestamp, recipient)
        message = mails.render_message(template, **context)

        digest = NotificationDigest(timestamp=timestamp,
                                    send_type=notification_type,
                                    event=event,
                                    user=recipient,
                                    message=message,
                                    node_lineage=node_lineage_ids)
        digest.save()
Example #7
0
def store_emails(recipient_ids, notification_type, event, user, node, timestamp, **context):
    """Store notification emails

    Emails are sent via celery beat as digests
    :param recipient_ids: List of user ids to send mail to.
    :param notification_type: from constants.Notification_types
    :param event: event that triggered notification
    :param user: user who triggered the notification
    :param node: instance of Node
    :param timestamp: time event happened
    :param context:
    :return: --
    """

    if notification_type == 'none':
        return

    template = event + '.html.mako'
    # user whose action triggered email sending
    context['user'] = user
    node_lineage_ids = get_node_lineage(node) if node else []

    for recipient_id in recipient_ids:
        if recipient_id == user._id:
            continue
        recipient = OSFUser.load(recipient_id)
        context['localized_timestamp'] = localize_timestamp(timestamp, recipient)
        message = mails.render_message(template, **context)

        digest = NotificationDigest(
            timestamp=timestamp,
            send_type=notification_type,
            event=event,
            user=recipient,
            message=message,
            node_lineage=node_lineage_ids
        )
        digest.save()