Added SHOW_ADMIN_EMAIL environment variable and used it in flash_email_error helper function

This commit is contained in:
petermaksymo 2021-12-16 10:29:47 -05:00
parent d8d1f94c95
commit 08c045e98f
7 changed files with 19 additions and 4 deletions

View file

@ -23,6 +23,7 @@ ENV DEBUG="False" \
MAIL_USERNAME="" \ MAIL_USERNAME="" \
SECRET_KEY="tralala" \ SECRET_KEY="tralala" \
SESSION_COOKIE_SECURE="True" \ SESSION_COOKIE_SECURE="True" \
SHOW_ADMIN_EMAIL="True" \
SQLALCHEMY_DATABASE_URI="sqlite:////database/ihatemoney.db" \ SQLALCHEMY_DATABASE_URI="sqlite:////database/ihatemoney.db" \
SQLALCHEMY_TRACK_MODIFICATIONS="False" \ SQLALCHEMY_TRACK_MODIFICATIONS="False" \
ENABLE_CAPTCHA="False" \ ENABLE_CAPTCHA="False" \

View file

@ -19,6 +19,7 @@ MAIL_USE_TLS = $MAIL_USE_TLS
MAIL_USERNAME = "$MAIL_USERNAME" MAIL_USERNAME = "$MAIL_USERNAME"
SECRET_KEY = "$SECRET_KEY" SECRET_KEY = "$SECRET_KEY"
SESSION_COOKIE_SECURE = $SESSION_COOKIE_SECURE SESSION_COOKIE_SECURE = $SESSION_COOKIE_SECURE
SHOW_ADMIN_EMAIL = $SHOW_ADMIN_EMAIL
SQLACHEMY_DEBUG = DEBUG SQLACHEMY_DEBUG = DEBUG
SQLALCHEMY_DATABASE_URI = "$SQLALCHEMY_DATABASE_URI" SQLALCHEMY_DATABASE_URI = "$SQLALCHEMY_DATABASE_URI"
SQLALCHEMY_TRACK_MODIFICATIONS = $SQLALCHEMY_TRACK_MODIFICATIONS SQLALCHEMY_TRACK_MODIFICATIONS = $SQLALCHEMY_TRACK_MODIFICATIONS

View file

@ -22,6 +22,7 @@ services:
- MAIL_USERNAME= - MAIL_USERNAME=
- SECRET_KEY=tralala - SECRET_KEY=tralala
- SESSION_COOKIE_SECURE=True - SESSION_COOKIE_SECURE=True
- SHOW_ADMIN_EMAIL=True
- SQLALCHEMY_DATABASE_URI=sqlite:////database/ihatemoney.db - SQLALCHEMY_DATABASE_URI=sqlite:////database/ihatemoney.db
- SQLALCHEMY_TRACK_MODIFICATIONS=False - SQLALCHEMY_TRACK_MODIFICATIONS=False
- ENABLE_CAPTCHA=False - ENABLE_CAPTCHA=False

View file

@ -82,6 +82,15 @@ emails.
- **Default value:** `("Budget manager", "admin@email.com")` - **Default value:** `("Budget manager", "admin@email.com")`
- **Production value:** Any tuple you want. - **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 ## ACTIVATE_DEMO_PROJECT
If set to `True`, a demo project will be available on the frontpage. If set to `True`, a demo project will be available on the frontpage.

View file

@ -21,6 +21,10 @@ SECRET_KEY = "{{ secret_key }}"
# A python tuple describing the name and email adress of the sender of the mails. # A python tuple describing the name and email adress of the sender of the mails.
MAIL_DEFAULT_SENDER = ("Budget manager", "admin@email.com") # CUSTOMIZE 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. # If set to True, a demonstration project will be activated.
ACTIVATE_DEMO_PROJECT = True ACTIVATE_DEMO_PROJECT = True

View file

@ -4,6 +4,7 @@ SQLALCHEMY_DATABASE_URI = "sqlite:////tmp/ihatemoney.db"
SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_TRACK_MODIFICATIONS = False
SECRET_KEY = "tralala" SECRET_KEY = "tralala"
MAIL_DEFAULT_SENDER = ("Budget manager", "admin@email.com") MAIL_DEFAULT_SENDER = ("Budget manager", "admin@email.com")
SHOW_ADMIN_EMAIL = True
ACTIVATE_DEMO_PROJECT = True ACTIVATE_DEMO_PROJECT = True
ADMIN_PASSWORD = "" ADMIN_PASSWORD = ""
ALLOW_PUBLIC_PROJECT_CREATION = True ALLOW_PUBLIC_PROJECT_CREATION = True

View file

@ -49,16 +49,14 @@ def send_email(mail_message):
def flash_email_error(error_message, category="danger"): def flash_email_error(error_message, category="danger"):
"""Helper to flash a message for email errors. It will also show the """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 admin email as a contact if SHOW_ADMIN_EMAIL is True.
the MAIL_DEFAULT_SENDER is not the default value.
""" """
admin_email = current_app.config.get("MAIL_DEFAULT_SENDER") admin_email = current_app.config.get("MAIL_DEFAULT_SENDER")
error_extension = "." error_extension = "."
if ( if (
admin_email admin_email
and admin_email[1] != "admin@email.com" 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]) error_extension = " or contact the administrator at {}.".format(admin_email[1])