From 47f70d73bdfcd1355e00acca41afda118f98c245 Mon Sep 17 00:00:00 2001 From: Stefan Gangefors Date: Sat, 20 Mar 2021 18:28:54 +0100 Subject: [PATCH] Easy override for social logins (#446) Add MAILMAN_WEB_SOCIAL_AUTH for social logins The `MAILMAN_WEB_SOCIAL_AUTH` list contains a default set of social login provides. This was previously included in `INSTALLED_APPS`. Separating it to it's own list makes it easier to disable or otherwise override which social login providers are enabled without the need to modify `INSTALLED_APPS`. Older installations where `INSTALLED_APPS` were overridden continues to work. The `MAILMAN_WEB_SOCIAL_AUTH` is ignored for those and `INSTALLED_APPS` is used as is. --- postorius/mailman-web/settings.py | 9 ++++++++- web/README.md | 8 ++++++++ web/mailman-web/settings.py | 19 ++++++++----------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/postorius/mailman-web/settings.py b/postorius/mailman-web/settings.py index 79cc70c..50994da 100644 --- a/postorius/mailman-web/settings.py +++ b/postorius/mailman-web/settings.py @@ -65,7 +65,8 @@ MAILMAN_ARCHIVER_FROM = (os.environ.get('MAILMAN_HOST_IP', gethostbyname(os.envi # Application definition -INSTALLED_APPS = [ +INSTALLED_APPS = [] +DEFAULT_APPS = [ 'postorius', 'django_mailman3', # Uncomment the next line to enable the admin: @@ -82,6 +83,8 @@ INSTALLED_APPS = [ 'allauth', 'allauth.account', 'allauth.socialaccount', +] +MAILMAN_WEB_SOCIAL_AUTH = [ 'django_mailman3.lib.auth.fedora', 'allauth.socialaccount.providers.openid', 'allauth.socialaccount.providers.github', @@ -344,3 +347,7 @@ try: from settings_local import * except ImportError: pass + +# Compatibility for older installs that override INSTALLED_APPS +if not INSTALLED_APPS: + INSTALLED_APPS = DEFAULT_APPS + MAILMAN_WEB_SOCIAL_AUTH diff --git a/web/README.md b/web/README.md index 01d8caa..1cd98db 100644 --- a/web/README.md +++ b/web/README.md @@ -71,6 +71,14 @@ change them unless you know what you want. `http://mailman-web:8000` by default so that Core can fetch templates from Web. +- `MAILMAN_WEB_SOCIAL_AUTH`: This is a list of Social login providers. + It contains a default set of providers. Override it if you want to remove + or disable social login entierly. + If `INSTALLED_APPS` is overridden `MAILMAN_WEB_SOCIAL_AUTH` is not used and + you must specify any social login provider in `INSTALLED_APPS` instead. + See [settings.py](mailman-web/settings.py) for implementation details. + + Running ======= diff --git a/web/mailman-web/settings.py b/web/mailman-web/settings.py index 9356165..b8d9c60 100644 --- a/web/mailman-web/settings.py +++ b/web/mailman-web/settings.py @@ -66,7 +66,8 @@ MAILMAN_ARCHIVER_FROM = (os.environ.get('MAILMAN_HOST_IP', gethostbyname(os.envi # Application definition -INSTALLED_APPS = [ +INSTALLED_APPS = [] +DEFAULT_APPS = [ 'hyperkitty', 'postorius', 'django_mailman3', @@ -89,6 +90,8 @@ INSTALLED_APPS = [ 'allauth', 'allauth.account', 'allauth.socialaccount', +] +MAILMAN_WEB_SOCIAL_AUTH = [ 'django_mailman3.lib.auth.fedora', 'allauth.socialaccount.providers.openid', 'allauth.socialaccount.providers.github', @@ -96,16 +99,6 @@ INSTALLED_APPS = [ 'allauth.socialaccount.providers.google', ] -# Optionally include paintstore, if it was installed with Hyperkitty. -# TODO: Remove this after a new version of Hyperkitty is released and -# neither the stable nor the rolling version needs it. -try: - import paintstore - INSTALLED_APPS.append('paintstore') -except ImportError: - pass - - MIDDLEWARE = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -412,3 +405,7 @@ try: from settings_local import * except ImportError: pass + +# Compatibility for older installs that override INSTALLED_APPS +if not INSTALLED_APPS: + INSTALLED_APPS = DEFAULT_APPS + MAILMAN_WEB_SOCIAL_AUTH