From a7e3b5cfdcd5c2ffed6e6c30bb8d6741aeedd649 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Sat, 22 Aug 2026 21:24:58 +0200 Subject: [PATCH] Link the server's terms of service from the about page --- lib/core/consts.dart | 5 +++++ lib/core/helpers.dart | 17 +++++++++++++++++ lib/core/widgets/about.dart | 14 ++++++++++++++ lib/l10n/app_de.arb | 1 + lib/l10n/app_en.arb | 1 + lib/l10n/app_es.arb | 1 + lib/l10n/app_fr.arb | 1 + test/core/helpers_test.dart | 23 +++++++++++++++++++++++ 8 files changed, 63 insertions(+) diff --git a/lib/core/consts.dart b/lib/core/consts.dart index 64e834b2d..920c31337 100644 --- a/lib/core/consts.dart +++ b/lib/core/consts.dart @@ -195,6 +195,11 @@ const WEBLATE_URL = 'https://hosted.weblate.org/engage/wger'; const BUY_ME_A_COFFEE_URL = 'https://buymeacoffee.com/wger'; const LIBERAPAY_URL = 'https://liberapay.com/wger'; +/// Terms of service and privacy policy, served by every instance. What it says +/// is up to whoever runs the server, upstream ships a placeholder. The Health +/// Connect entry points in MainActivity.kt use wger.de's copy of this page. +const TERMS_OF_SERVICE_PATH = 'software/terms-of-service'; + /// Factor to multiply / divide in the charts when converting dates to milliseconds /// from epoch since fl_charts does not support real time series charts and using /// the milliseconds themselves can cause the application to crash since it runs diff --git a/lib/core/helpers.dart b/lib/core/helpers.dart index 9a8122165..6e0129f0c 100644 --- a/lib/core/helpers.dart +++ b/lib/core/helpers.dart @@ -90,6 +90,23 @@ Uri makeUri( return uri; } +/// Builds the URL of a page the server renders itself, e.g. its terms of +/// service. Unlike [makeUri] the path is used as given, without the API prefix +/// and without a trailing slash. +Uri makePageUri(String serverUrl, String path) { + final server = Uri.parse(serverUrl); + final basePath = server.path.endsWith('/') + ? server.path.substring(0, server.path.length - 1) + : server.path; + + return Uri( + scheme: server.scheme, + host: server.host, + port: server.port, + path: '$basePath/$path', + ); +} + /// Builds a URL for the `allauth.headless` `app` client API at /// `/allauth/app/v1/`. Used by the auth notifier for login, /// signup, MFA, refresh, etc. The headless API does not use a trailing diff --git a/lib/core/widgets/about.dart b/lib/core/widgets/about.dart index 144308fa0..b7ae7cdc8 100644 --- a/lib/core/widgets/about.dart +++ b/lib/core/widgets/about.dart @@ -23,6 +23,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:wger/core/consts.dart'; import 'package:wger/core/errors.dart' show buildGithubIssueUrl; +import 'package:wger/core/helpers.dart' show makePageUri; import 'package:wger/core/logs.dart'; import 'package:wger/core/misc.dart'; import 'package:wger/core/network/auth_notifier.dart'; @@ -60,6 +61,10 @@ class AboutPage extends ConsumerWidget { final i18n = AppLocalizations.of(context); final today = DateTime.now(); + // The terms are the server operator's, not ours, so point at the instance + // the user is actually connected to + final serverUrl = authState?.serverUrl; + return Scaffold( appBar: AppBar(title: Text(i18n.aboutPageTitle)), body: WidescreenWrapper( @@ -257,6 +262,15 @@ class AboutPage extends ConsumerWidget { contentPadding: EdgeInsets.zero, onTap: () => launchURL(READTHEDOCS_URL, context), ), + if (serverUrl != null) + ListTile( + leading: const Icon(Icons.privacy_tip), + trailing: const Icon(Icons.arrow_outward), + title: Text(i18n.aboutPrivacyPolicyTitle), + contentPadding: EdgeInsets.zero, + onTap: () => + launchURL(makePageUri(serverUrl, TERMS_OF_SERVICE_PATH).toString(), context), + ), ], ), ), diff --git a/lib/l10n/app_de.arb b/lib/l10n/app_de.arb index dec55aa12..948098a11 100644 --- a/lib/l10n/app_de.arb +++ b/lib/l10n/app_de.arb @@ -1086,6 +1086,7 @@ "carbohydratesSugar": "Zucker (Kohlenhydrate)", "aboutViewDocsTitle": "Dokumentation öffnen", "aboutViewLicensesTitle": "Lizenzen anzeigen", + "aboutPrivacyPolicyTitle": "Nutzungsbedingungen und Datenschutz", "powerSyncUnreachableTitle": "Sync-Dienst nicht erreichbar", "powerSyncUnreachableContent": "Dein wger-Server ist erreichbar, aber der (separate) Dienst für die Offline-Synchronisierung antwortet nicht. Wenn du wger selbst hostest, überprüfe deine Konfiguration und stelle sicher, dass der PowerSync-Dienst korrekt läuft.", "serverUnreachableRetry": "Erneut versuchen", diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index b040cc7e0..be1f2e154 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -1085,6 +1085,7 @@ "aboutDiscordTitle": "Discord", "aboutViewDocsTitle": "Open documentation", "aboutViewLicensesTitle": "View licenses", + "aboutPrivacyPolicyTitle": "Terms and privacy policy", "others": "Others", "calendar": "Calendar", "@calendar": {}, diff --git a/lib/l10n/app_es.arb b/lib/l10n/app_es.arb index dc8510fd3..93dfb933f 100644 --- a/lib/l10n/app_es.arb +++ b/lib/l10n/app_es.arb @@ -1120,6 +1120,7 @@ "carbohydratesSugar": "Azúcar (carbohidratos)", "aboutViewDocsTitle": "Abrir la documentación", "aboutViewLicensesTitle": "Ver licencias", + "aboutPrivacyPolicyTitle": "Términos y política de privacidad", "enterMaxCharacters": "Introduce como máximo {max} caracteres", "powerSyncUnreachableTitle": "Servicio de sincronización no disponible", "powerSyncUnreachableContent": "Tu servidor de wger es accesible, pero el servicio (independiente) que gestiona la sincronización sin conexión no responde. Si alojas wger por tu cuenta, revisa tu configuración y asegúrate de que el servicio PowerSync funcione correctamente.", diff --git a/lib/l10n/app_fr.arb b/lib/l10n/app_fr.arb index 88f4ecd2d..eb4901a9e 100644 --- a/lib/l10n/app_fr.arb +++ b/lib/l10n/app_fr.arb @@ -1091,6 +1091,7 @@ "carbohydratesSugar": "Sucre (glucides)", "aboutViewDocsTitle": "Ouvrir la documentation", "aboutViewLicensesTitle": "Voir les licences", + "aboutPrivacyPolicyTitle": "Conditions et politique de confidentialité", "enterMaxCharacters": "Veuillez saisir au maximum {max} caractères", "powerSyncUnreachableTitle": "Service de synchronisation inaccessible", "powerSyncUnreachableContent": "Votre serveur wger est accessible, mais le service (distinct) qui gère la synchronisation hors ligne ne répond pas. Si vous hébergez wger vous-même, vérifiez votre configuration et assurez-vous que le service PowerSync fonctionne correctement.", diff --git a/test/core/helpers_test.dart b/test/core/helpers_test.dart index 5e28eb692..d77f12544 100644 --- a/test/core/helpers_test.dart +++ b/test/core/helpers_test.dart @@ -181,6 +181,29 @@ void main() { }); }); + group('makePageUri', () { + test('builds the page URL on the server itself', () { + expect( + makePageUri('https://wger.de', 'software/terms-of-service').toString(), + 'https://wger.de/software/terms-of-service', + ); + }); + + test('handles a trailing slash on the server URL', () { + expect( + makePageUri('https://wger.de/', 'software/terms-of-service').toString(), + 'https://wger.de/software/terms-of-service', + ); + }); + + test('keeps a subpath and a non-default port (self-hosted setups)', () { + expect( + makePageUri('http://localhost:8000/wger', 'software/terms-of-service').toString(), + 'http://localhost:8000/wger/software/terms-of-service', + ); + }); + }); + group('findLivePowerSyncUrl', () { const serverUrl = 'https://wger.example.com';