Exemplo n.º 1
0
def generate_role_digest(role):
    """Generate notification digest emails for the given user."""
    # TODO: get and use the role's locale preference.
    since = datetime.utcnow() - timedelta(hours=26)
    result = get_notifications(role, since=since)
    hits = result.get("hits", {})
    total_count = hits.get("total", {}).get("value")
    log.info("Daily digest: %r (%s notifications)", role, total_count)
    if total_count == 0:
        return
    notifications = [render_notification(role, n) for n in hits.get("hits")]
    notifications = [n for n in notifications if n is not None]
    params = dict(
        notifications=notifications,
        role=role,
        total_count=total_count,
        manage_url=ui_url("notifications"),
        ui_url=settings.APP_UI_URL,
        app_title=settings.APP_TITLE,
    )
    plain = render_template("email/notifications.txt", **params)
    html = render_template("email/notifications.html", **params)
    log.info("Notification: %s", plain)
    subject = "%s notifications" % total_count
    email_role(role, subject, html=html, plain=plain)
Exemplo n.º 2
0
def challenge_role(data):
    """Given an email address, this will send out a message to allow
    the user to then register an account."""
    signature = Role.SIGNATURE.dumps(data["email"])
    url = "{}activate/{}".format(settings.APP_UI_URL, signature)
    role = Role(email=data["email"], name=data["email"])
    params = dict(
        url=url, role=role, ui_url=settings.APP_UI_URL, app_title=settings.APP_TITLE
    )
    plain = render_template("email/registration_code.txt", **params)
    html = render_template("email/registration_code.html", **params)
    log.info("Challenge: %s", plain)
    email_role(role, gettext("Registration"), html=html, plain=plain)
Exemplo n.º 3
0
def send_export_notification(export):
    download_url = archive_url(
        export.content_hash,
        file_name=export.file_name,
        mime_type=export.mime_type,
        expire=export.expires_at,
    )
    params = dict(
        role=export.creator,
        export_label=export.label,
        download_url=download_url,
        expiration_date=export.expires_at.strftime("%Y-%m-%d"),
        exports_url=ui_url("exports"),
        ui_url=settings.APP_UI_URL,
        app_title=settings.APP_TITLE,
    )
    plain = render_template("email/export.txt", **params)
    html = render_template("email/export.html", **params)
    log.info("Notification: %s", plain)
    subject = "Export ready for download"
    email_role(export.creator, subject, html=html, plain=plain)
Exemplo n.º 4
0
def send_export_notification(export):
    role = Role.by_id(export.creator_id)
    authz = Authz.from_role(role)
    download_url = url_for(
        "exports_api.download",
        export_id=export.id,
        _authz=authz,
        _expire=export.expires_at,
    )
    params = dict(
        role=role,
        export_label=export.label,
        download_url=download_url,
        expiration_date=export.expires_at.strftime("%Y-%m-%d"),
        exports_url=ui_url("exports"),
        ui_url=settings.APP_UI_URL,
        app_title=settings.APP_TITLE,
    )
    plain = render_template("email/export.txt", **params)
    html = render_template("email/export.html", **params)
    log.info("Notification: %s", plain)
    subject = "Export ready for download"
    email_role(role, subject, html=html, plain=plain)