From 08c045e98f2181a8421b1a633f26242e53bb74d0 Mon Sep 17 00:00:00 2001 From: petermaksymo Date: Thu, 16 Dec 2021 10:29:47 -0500 Subject: [PATCH] Added SHOW_ADMIN_EMAIL environment variable and used it in flash_email_error helper function --- Dockerfile | 1 + conf/entrypoint.sh | 1 + docker-compose.yml | 1 + docs/configuration.md | 9 +++++++++ ihatemoney/conf-templates/ihatemoney.cfg.j2 | 4 ++++ ihatemoney/default_settings.py | 1 + ihatemoney/utils.py | 6 ++---- 7 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5bb068a3..fee3cfaf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,6 +23,7 @@ ENV DEBUG="False" \ MAIL_USERNAME="" \ SECRET_KEY="tralala" \ SESSION_COOKIE_SECURE="True" \ + SHOW_ADMIN_EMAIL="True" \ SQLALCHEMY_DATABASE_URI="sqlite:////database/ihatemoney.db" \ SQLALCHEMY_TRACK_MODIFICATIONS="False" \ ENABLE_CAPTCHA="False" \ diff --git a/conf/entrypoint.sh b/conf/entrypoint.sh index 4d48f86c..81fcd720 100755 --- a/conf/entrypoint.sh +++ b/conf/entrypoint.sh @@ -19,6 +19,7 @@ MAIL_USE_TLS = $MAIL_USE_TLS MAIL_USERNAME = "$MAIL_USERNAME" SECRET_KEY = "$SECRET_KEY" SESSION_COOKIE_SECURE = $SESSION_COOKIE_SECURE +SHOW_ADMIN_EMAIL = $SHOW_ADMIN_EMAIL SQLACHEMY_DEBUG = DEBUG SQLALCHEMY_DATABASE_URI = "$SQLALCHEMY_DATABASE_URI" SQLALCHEMY_TRACK_MODIFICATIONS = $SQLALCHEMY_TRACK_MODIFICATIONS diff --git a/docker-compose.yml b/docker-compose.yml index 1994e69e..c5c16878 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -22,6 +22,7 @@ services: - MAIL_USERNAME= - SECRET_KEY=tralala - SESSION_COOKIE_SECURE=True + - SHOW_ADMIN_EMAIL=True - SQLALCHEMY_DATABASE_URI=sqlite:////database/ihatemoney.db - SQLALCHEMY_TRACK_MODIFICATIONS=False - ENABLE_CAPTCHA=False diff --git a/docs/configuration.md b/docs/configuration.md index fd65b6db..722b7cd8 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -82,6 +82,15 @@ emails. - **Default value:** `("Budget manager", "admin@email.com")` - **Production value:** Any tuple you want. +## SHOW_ADMIN_EMAIL + +A boolean that determines whether the admin email (`MAIL_DEFAULT_SENDER`) is +shown in error messages. + +- **Default value:** `True` +- **Production value:** Usually `True` unless you don't want the admin + email to be shown for privacy reasons. + ## ACTIVATE_DEMO_PROJECT If set to `True`, a demo project will be available on the frontpage. diff --git a/ihatemoney/conf-templates/ihatemoney.cfg.j2 b/ihatemoney/conf-templates/ihatemoney.cfg.j2 index 6e0dbef7..5ea549e4 100644 --- a/ihatemoney/conf-templates/ihatemoney.cfg.j2 +++ b/ihatemoney/conf-templates/ihatemoney.cfg.j2 @@ -21,6 +21,10 @@ SECRET_KEY = "{{ secret_key }}" # A python tuple describing the name and email adress of the sender of the mails. MAIL_DEFAULT_SENDER = ("Budget manager", "admin@email.com") # CUSTOMIZE +# A boolean that determines whether the admin email (MAIL_DEFAULT_SENDER) is +# shown in error messages. +SHOW_ADMIN_EMAIL = True + # If set to True, a demonstration project will be activated. ACTIVATE_DEMO_PROJECT = True diff --git a/ihatemoney/default_settings.py b/ihatemoney/default_settings.py index 0cc113e0..eaf77ecb 100644 --- a/ihatemoney/default_settings.py +++ b/ihatemoney/default_settings.py @@ -4,6 +4,7 @@ SQLALCHEMY_DATABASE_URI = "sqlite:////tmp/ihatemoney.db" SQLALCHEMY_TRACK_MODIFICATIONS = False SECRET_KEY = "tralala" MAIL_DEFAULT_SENDER = ("Budget manager", "admin@email.com") +SHOW_ADMIN_EMAIL = True ACTIVATE_DEMO_PROJECT = True ADMIN_PASSWORD = "" ALLOW_PUBLIC_PROJECT_CREATION = True diff --git a/ihatemoney/utils.py b/ihatemoney/utils.py index 18dbfa12..b035db8f 100644 --- a/ihatemoney/utils.py +++ b/ihatemoney/utils.py @@ -49,16 +49,14 @@ def send_email(mail_message): def flash_email_error(error_message, category="danger"): """Helper to flash a message for email errors. It will also show the - admin email as a contact if public project creation is allowed and - the MAIL_DEFAULT_SENDER is not the default value. - + admin email as a contact if SHOW_ADMIN_EMAIL is True. """ admin_email = current_app.config.get("MAIL_DEFAULT_SENDER") error_extension = "." if ( admin_email and admin_email[1] != "admin@email.com" - and current_app.config.get("ALLOW_PUBLIC_PROJECT_CREATION") + and current_app.config.get("SHOW_ADMIN_EMAIL") ): error_extension = " or contact the administrator at {}.".format(admin_email[1])