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.
This commit is contained in:
Kumi 2024-05-26 18:28:38 +02:00
parent 2d4df9bae1
commit 9c8c9b6c17
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -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