From 9c8c9b6c17256c935f0d9a0fa5d0a500f4ddac9f Mon Sep 17 00:00:00 2001 From: Kumi Date: Sun, 26 May 2024 18:28:38 +0200 Subject: [PATCH] feat: dynamic privacy policy loading Enhanced the privacy policy display functionality to dynamically load content from a configurable file path. The path is specified via the `STRUCTABLES_PRIVACY_FILE` environment variable, allowing for greater flexibility and easier updates to the privacy policy without needing to redeploy the application. If the specified file is unreachable or the environment variable is unset, the system gracefully falls back to a default message, ensuring the site remains compliant with privacy policy disclosures under various circumstances. This change streamlines content management and improves the adaptability of the application to legal and policy requirements. --- src/structables/routes/main.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/structables/routes/main.py b/src/structables/routes/main.py index 2a8dda4..2ea749b 100644 --- a/src/structables/routes/main.py +++ b/src/structables/routes/main.py @@ -333,10 +333,19 @@ def init_main_routes(app): @app.route("/privacypolicy/") def privacypolicy(): + """Display the privacy policy. + + The privacy policy is loaded from the file specified in the + `STRUCTABLES_PRIVACY_FILE` environment variable. If that variable is + unset or the file cannot be read, a default message is displayed. + """ + content = "No privacy policy found." + path = app.config.get("PRIVACY_FILE", "privacy.txt") + try: - with (pathlib.Path(__file__).parent / "privacy.txt").open() as f: + with pathlib.Path(path).open() as f: content = f.read() except OSError: pass