From fa68a3b5a4a43b167525a005d42420dd8d532cff Mon Sep 17 00:00:00 2001 From: Bjarke Madsen <bjarke@nordu.net> Date: Mon, 21 Aug 2023 14:04:31 +0200 Subject: [PATCH] Add config for enabling emails --- compendium_v2/__init__.py | 11 +++++++++++ compendium_v2/config.py | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/compendium_v2/__init__.py b/compendium_v2/__init__.py index 9d1b68d0..187920ac 100644 --- a/compendium_v2/__init__.py +++ b/compendium_v2/__init__.py @@ -67,6 +67,17 @@ def _create_app_with_db(app_config) -> Flask: # for the publishers app.config['SQLALCHEMY_BINDS'] = app_config['SQLALCHEMY_BINDS'] + if 'mail' in app_config: + mail_config = app_config['mail'] + app.config['MAIL_ENABLE'] = True + app.config['MAIL_SERVER'] = mail_config['MAIL_SERVER'] + app.config['MAIL_PORT'] = mail_config['MAIL_PORT'] + app.config['MAIL_SENDER_EMAIL'] = mail_config['MAIL_SENDER_EMAIL'] # email address to send emails from + excluded_admins = mail_config.get('MAIL_EXCLUDED_ADMINS', []) + app.config['MAIL_EXCLUDED_ADMINS'] = excluded_admins # list of admin emails not to send emails to + else: + app.config['MAIL_ENABLE'] = False + db.init_app(app) return app diff --git a/compendium_v2/config.py b/compendium_v2/config.py index 490f399a..4c67ad98 100644 --- a/compendium_v2/config.py +++ b/compendium_v2/config.py @@ -17,6 +17,20 @@ CONFIG_SCHEMA = { 'required': ['client_id', 'client_secret', 'server_metadata_url'], 'additionalProperties': False }, + 'mail': { + 'type': 'object', + 'properties': { + 'MAIL_SERVER': {'type': 'string'}, + 'MAIL_PORT': {'type': 'integer'}, + 'MAIL_SENDER_EMAIL': {'type': 'string', 'format': 'email'}, + 'MAIL_EXCLUDED_ADMINS': { + 'type': 'array', + 'items': {'type': 'string', 'format': 'email'} + } + }, + 'required': ['MAIL_SERVER', 'MAIL_PORT', 'MAIL_SENDER_EMAIL'], + 'additionalProperties': False + }, 'SECRET_KEY': {'type': 'string'}, }, 'required': ['SQLALCHEMY_DATABASE_URI', 'SURVEY_DATABASE_URI', 'SECRET_KEY'], -- GitLab