Fix of the Notifications Funktions and the notifications system in generell in regarts to the Vapid key handeling

This commit is contained in:
2026-07-28 23:46:15 +02:00
parent b037434e89
commit 3571bb6f6d
4 changed files with 11 additions and 10 deletions
+3 -5
View File
@@ -10376,18 +10376,15 @@ def my_borrowed_items():
@app.route('/notifications') @app.route('/notifications')
def notifications_view(): def notifications_view():
"""Notification center for users and admins.""" """Notification center for users and admins."""
from Web.push_notifications import _get_vapid_public
if 'username' not in session: if 'username' not in session:
flash('Bitte melden Sie sich an, um Benachrichtigungen zu sehen.', 'error') flash('Bitte melden Sie sich an, um Benachrichtigungen zu sehen.', 'error')
return redirect(url_for('login')) return redirect(url_for('login'))
username = session['username'] username = session['username']
is_admin_user = False
current_permissions = us.get_effective_permissions(session['username']) current_permissions = us.get_effective_permissions(session['username'])
if not current_permissions['actions'].get('can_manage_settings', False): is_admin_user = current_permissions['actions'].get('can_manage_settings', False)
is_admin_user = True
else:
is_admin_user = False
client = None client = None
try: try:
@@ -10421,6 +10418,7 @@ def notifications_view():
is_admin_user=is_admin_user, is_admin_user=is_admin_user,
library_module_enabled=cfg.MODULES.is_enabled('library'), library_module_enabled=cfg.MODULES.is_enabled('library'),
student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards'), student_cards_module_enabled=cfg.MODULES.is_enabled('student_cards'),
vapid_public_key=_get_vapid_public()
) )
except Exception as exc: except Exception as exc:
app.logger.error(f"Error loading notifications: {exc}") app.logger.error(f"Error loading notifications: {exc}")
+3
View File
@@ -60,6 +60,9 @@ VAPID_SUBJECT = os.getenv('VAPID_SUBJECT', 'mailto:support@invario-software.de')
FCM_API_KEY = os.getenv('FCM_API_KEY', '') FCM_API_KEY = os.getenv('FCM_API_KEY', '')
def _get_vapid_public():
return VAPID_PUBLIC_KEY
def _get_username_hash(username): def _get_username_hash(username):
"""Generates a deterministic hash for database lookups.""" """Generates a deterministic hash for database lookups."""
if not username: if not username:
+3 -3
View File
@@ -324,7 +324,7 @@ const pushNotificationManager = new PushNotificationManager();
/** /**
* Show notification subscription UI (typically in settings) * Show notification subscription UI (typically in settings)
*/ */
function showPushNotificationSettings() { function showPushNotificationSettings(vapidPublicKey) {
const container = document.getElementById('push-notification-settings'); const container = document.getElementById('push-notification-settings');
if (!container) return; if (!container) return;
@@ -350,9 +350,9 @@ function showPushNotificationSettings() {
container.innerHTML = html; 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'); const toggleBtn = document.getElementById('toggle-push-btn');
pushNotificationManager.init().then(() => { pushNotificationManager.init(vapidPublicKey).then(() => {
updatePushStatus(); updatePushStatus();
}); });
+1 -1
View File
@@ -89,7 +89,7 @@
<script> <script>
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
if (typeof showPushNotificationSettings === 'function') { if (typeof showPushNotificationSettings === 'function') {
showPushNotificationSettings(); showPushNotificationSettings('{{ vapid_public_key }}');
} }
}); });
</script> </script>