From 53cdc80df23ac94279c02a88ad5938128d708711 Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Thu, 19 Sep 2024 10:51:06 +0530 Subject: [PATCH] Add a new config variable - ALLOW_SPECIAL_EMAIL_DOMAINS to allow special domains for pgAdmin user emails. #6222 --- docs/en_US/release_notes_8_12.rst | 1 + web/config.py | 1 + web/pgadmin/evaluate_config.py | 10 ++++++++++ 3 files changed, 12 insertions(+) diff --git a/docs/en_US/release_notes_8_12.rst b/docs/en_US/release_notes_8_12.rst index 48f800296..3c21bf6d1 100644 --- a/docs/en_US/release_notes_8_12.rst +++ b/docs/en_US/release_notes_8_12.rst @@ -21,6 +21,7 @@ New features ************ | `Issue #1900 `_ - Added feature to restore preferences to their default values. + | `Issue #6222 `_ - Add a new config variable - ALLOW_SPECIAL_EMAIL_DOMAINS to allow special domains for pgAdmin user emails. | `Issue #7293 `_ - Allow running non-continuous selected SQL code blocks in the query tool. Housekeeping diff --git a/web/config.py b/web/config.py index 53145d159..a49ba1f09 100644 --- a/web/config.py +++ b/web/config.py @@ -400,6 +400,7 @@ SECURITY_EMAIL_SUBJECT_PASSWORD_CHANGE_NOTICE = \ CHECK_EMAIL_DELIVERABILITY = False SECURITY_EMAIL_VALIDATOR_ARGS = \ {"check_deliverability": CHECK_EMAIL_DELIVERABILITY} +ALLOW_SPECIAL_EMAIL_DOMAINS = [] ########################################################################## # Upgrade checks diff --git a/web/pgadmin/evaluate_config.py b/web/pgadmin/evaluate_config.py index 54475eac6..ac1384b0f 100644 --- a/web/pgadmin/evaluate_config.py +++ b/web/pgadmin/evaluate_config.py @@ -10,6 +10,7 @@ import os import sys import keyring +import email_validator # User configs loaded from config_local, config_distro etc. custom_config_settings = {} @@ -136,4 +137,13 @@ def evaluate_and_patch_config(config: dict) -> dict: 'SESSION_COOKIE_PATH': os.environ["SCRIPT_NAME"], })) + # Allow special email domains + try: + email_validator.SPECIAL_USE_DOMAIN_NAMES = [ + d for d in email_validator.SPECIAL_USE_DOMAIN_NAMES + if d not in config.get('ALLOW_SPECIAL_EMAIL_DOMAINS', []) + ] + except Exception: + pass + return config