From 3571bb6f6d930b2a5fb60ddf91ca9b159fe413e2 Mon Sep 17 00:00:00 2001 From: AIIrondev Date: Tue, 28 Jul 2026 23:46:15 +0200 Subject: [PATCH] Fix of the Notifications Funktions and the notifications system in generell in regarts to the Vapid key handeling --- Web/app.py | 10 ++++------ Web/push_notifications.py | 3 +++ Web/static/js/push-notifications.js | 6 +++--- Web/templates/notifications.html | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Web/app.py b/Web/app.py index d3b390d..bd82858 100755 --- a/Web/app.py +++ b/Web/app.py @@ -10376,18 +10376,15 @@ def my_borrowed_items(): @app.route('/notifications') def notifications_view(): """Notification center for users and admins.""" + from Web.push_notifications import _get_vapid_public if 'username' not in session: flash('Bitte melden Sie sich an, um Benachrichtigungen zu sehen.', 'error') return redirect(url_for('login')) username = session['username'] - is_admin_user = False current_permissions = us.get_effective_permissions(session['username']) - - if not current_permissions['actions'].get('can_manage_settings', False): - is_admin_user = True - else: - is_admin_user = False + + is_admin_user = current_permissions['actions'].get('can_manage_settings', False) client = None try: @@ -10421,6 +10418,7 @@ def notifications_view(): is_admin_user=is_admin_user, library_module_enabled=cfg.MODULES.is_enabled('library'), student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards'), + vapid_public_key=_get_vapid_public() ) except Exception as exc: app.logger.error(f"Error loading notifications: {exc}") diff --git a/Web/push_notifications.py b/Web/push_notifications.py index b1a0d0b..578fdb3 100644 --- a/Web/push_notifications.py +++ b/Web/push_notifications.py @@ -60,6 +60,9 @@ VAPID_SUBJECT = os.getenv('VAPID_SUBJECT', 'mailto:support@invario-software.de') FCM_API_KEY = os.getenv('FCM_API_KEY', '') +def _get_vapid_public(): + return VAPID_PUBLIC_KEY + def _get_username_hash(username): """Generates a deterministic hash for database lookups.""" if not username: diff --git a/Web/static/js/push-notifications.js b/Web/static/js/push-notifications.js index 6dbfe62..9d734d3 100644 --- a/Web/static/js/push-notifications.js +++ b/Web/static/js/push-notifications.js @@ -324,7 +324,7 @@ const pushNotificationManager = new PushNotificationManager(); /** * Show notification subscription UI (typically in settings) */ -function showPushNotificationSettings() { +function showPushNotificationSettings(vapidPublicKey) { const container = document.getElementById('push-notification-settings'); if (!container) return; @@ -350,9 +350,9 @@ function showPushNotificationSettings() { container.innerHTML = html; - // Set up button handler + // Set up button handler and pass the VAPID public key to init() const toggleBtn = document.getElementById('toggle-push-btn'); - pushNotificationManager.init().then(() => { + pushNotificationManager.init(vapidPublicKey).then(() => { updatePushStatus(); }); diff --git a/Web/templates/notifications.html b/Web/templates/notifications.html index 60bfc91..2d745ec 100644 --- a/Web/templates/notifications.html +++ b/Web/templates/notifications.html @@ -89,7 +89,7 @@