diff --git a/apps/notifications/views.py b/apps/notifications/views.py index 148ac7ffc..3a235f679 100644 --- a/apps/notifications/views.py +++ b/apps/notifications/views.py @@ -1,12 +1,12 @@ from wtforms import SubmitField, BooleanField from apps.common import json_response from main import db -from flask import render_template, request, current_app as app +from flask import render_template, request, current_app as app, flash, redirect, url_for from flask_login import current_user, login_required from . import notifications from ..common.forms import Form -from models.web_push import public_key, WebPushTarget +from models.web_push import public_key, WebPushTarget, notify from models.notifications import UserNotificationPreference @@ -37,6 +37,20 @@ def index(): ) +@notifications.route("/test", methods=["POST"]) +@login_required +def test(): + if len(current_user.web_push_targets) == 0: + flash("You have no devices configured for push notifications.") + return redirect(url_for("notifications.index")) + + for target in current_user.web_push_targets: + notify(target, "This is a test notification.") + + flash("Test notifications have been sent.") + return redirect(url_for("notifications.index")) + + @notifications.route("/register", methods=["POST"]) @json_response @login_required diff --git a/templates/notifications/index.html b/templates/notifications/index.html index 246567a56..147d727c9 100644 --- a/templates/notifications/index.html +++ b/templates/notifications/index.html @@ -17,6 +17,9 @@
You have enabled push notifications on this device.
To disable them look in your browser settings.
+You have denied access to send push notifications to this device.