From a3ff96653af46aaebc21694cefc2c4b6d4b46622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Z=C3=B6ller?= Date: Wed, 3 Dec 2025 07:23:53 +0100 Subject: [PATCH] Moar federation --- .../templates/activities/detail.html | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main/resources/templates/activities/detail.html b/src/main/resources/templates/activities/detail.html index 9cbe903..ad109ad 100644 --- a/src/main/resources/templates/activities/detail.html +++ b/src/main/resources/templates/activities/detail.html @@ -317,11 +317,8 @@ // Show Edit/Delete buttons only if user is logged in and owns the activity if (FitPubAuth.isAuthenticated()) { - const currentUser = FitPubAuth.getCurrentUser(); - if (currentUser && currentUser.id === activity.userId) { - document.getElementById('activityActions').style.display = 'block'; - document.getElementById('editBtn').href = `/activities/${activity.id}/edit`; - } + // Fetch current user to check if they own this activity + checkActivityOwnership(activity); } // Metrics @@ -358,6 +355,25 @@ setupSocialInteractions(activity); } + /** + * Check if the current user owns this activity and show edit/delete buttons if so. + */ + async function checkActivityOwnership(activity) { + try { + const response = await FitPubAuth.authenticatedFetch('/api/users/me'); + if (response.ok) { + const currentUser = await response.json(); + if (currentUser.id === activity.userId) { + document.getElementById('activityActions').style.display = 'block'; + document.getElementById('editBtn').href = `/activities/${activity.id}/edit`; + } + } + } catch (error) { + console.error('Error checking activity ownership:', error); + // Don't show buttons if there's an error + } + } + function renderMap(simplifiedTrack) { // Parse GeoJSON from simplifiedTrack const geoJson = {