From 3d830884b11fb0156b362202f350e0c8e2d8c7f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Thu, 30 Jul 2020 12:04:04 +0200 Subject: [PATCH 1/4] Use authens in GestioBDS --- cof/settings/bds_prod.py | 13 +++++++++++-- cof/urls.py | 3 +++ requirements.txt | 1 + 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cof/settings/bds_prod.py b/cof/settings/bds_prod.py index abd43ca9..6caf3bdf 100644 --- a/cof/settings/bds_prod.py +++ b/cof/settings/bds_prod.py @@ -13,7 +13,7 @@ from .common import BASE_DIR, INSTALLED_APPS ALLOWED_HOSTS = ["bds.ens.fr", "www.bds.ens.fr", "dev.cof.ens.fr"] -INSTALLED_APPS += ["bds", "events", "clubs"] +INSTALLED_APPS += ["bds", "events", "clubs", "authens"] STATIC_ROOT = os.path.join( os.path.dirname(os.path.dirname(BASE_DIR)), "public", "gestion", "static" @@ -28,5 +28,14 @@ MEDIA_URL = "/gestion/media/" # Auth-related stuff # --- -LOGIN_URL = "admin:login" +AUTHENTICATION_BACKENDS = [ + "django.contrib.auth.backends.ModelBackend", + "authens.backends.ENSCASBackend", + "authens.backends.OldCASBackend", +] + +AUTHENS_USE_OLDCAS = False + +LOGIN_URL = "authens:login" LOGIN_REDIRECT_URL = "bds:home" +LOGOUT_REDIRECT_URL = "bds:home" diff --git a/cof/urls.py b/cof/urls.py index fe7bf5d1..af7501d1 100644 --- a/cof/urls.py +++ b/cof/urls.py @@ -144,6 +144,9 @@ if "events" in settings.INSTALLED_APPS: # → rename this when the old events system is out urlpatterns += [path("event_v2/", include("events.urls"))] +if "authens" in settings.INSTALLED_APPS: + urlpatterns.append(path("authens/", include("authens.urls"))) + if "debug_toolbar" in settings.INSTALLED_APPS: import debug_toolbar diff --git a/requirements.txt b/requirements.txt index 9fbc3e06..14c99407 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,3 +17,4 @@ wagtailmenus==3.* wagtail-modeltranslation==0.10.* django-cors-headers==2.2.0 django-js-reverse +authens==0.* From df9639715b92f6e26222fef08b2559426377a6ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Mon, 24 Aug 2020 14:55:27 +0200 Subject: [PATCH 2/4] Move COF-specific settings (channels) to common.py --- cof/settings/cof_prod.py | 42 ++++++++++++++++++++++++++++++++++++++++ cof/settings/common.py | 42 ---------------------------------------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/cof/settings/cof_prod.py b/cof/settings/cof_prod.py index 180e92a6..0f73841e 100644 --- a/cof/settings/cof_prod.py +++ b/cof/settings/cof_prod.py @@ -18,6 +18,11 @@ from .common import ( # COF-specific secrets # --- +REDIS_PASSWD = import_secret("REDIS_PASSWD") +REDIS_DB = import_secret("REDIS_DB") +REDIS_HOST = import_secret("REDIS_HOST") +REDIS_PORT = import_secret("REDIS_PORT") + RECAPTCHA_PUBLIC_KEY = import_secret("RECAPTCHA_PUBLIC_KEY") RECAPTCHA_PRIVATE_KEY = import_secret("RECAPTCHA_PRIVATE_KEY") KFETOPEN_TOKEN = import_secret("KFETOPEN_TOKEN") @@ -112,6 +117,43 @@ AUTHENTICATION_BACKENDS += [ LOGIN_URL = "cof-login" LOGIN_REDIRECT_URL = "home" +# --- +# Cache settings +# --- + +CACHES = { + "default": { + "BACKEND": "redis_cache.RedisCache", + "LOCATION": "redis://:{passwd}@{host}:{port}/{db}".format( + passwd=REDIS_PASSWD, host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB + ), + } +} + + +# --- +# Channels settings +# --- + +CHANNEL_LAYERS = { + "default": { + "BACKEND": "asgi_redis.RedisChannelLayer", + "CONFIG": { + "hosts": [ + ( + "redis://:{passwd}@{host}:{port}/{db}".format( + passwd=REDIS_PASSWD, + host=REDIS_HOST, + port=REDIS_PORT, + db=REDIS_DB, + ) + ) + ] + }, + "ROUTING": "cof.routing.routing", + } +} + # --- # reCAPTCHA settings diff --git a/cof/settings/common.py b/cof/settings/common.py index 0c34bf67..4636ace3 100644 --- a/cof/settings/common.py +++ b/cof/settings/common.py @@ -41,11 +41,6 @@ DBNAME = import_secret("DBNAME") DBUSER = import_secret("DBUSER") DBPASSWD = import_secret("DBPASSWD") -REDIS_PASSWD = import_secret("REDIS_PASSWD") -REDIS_DB = import_secret("REDIS_DB") -REDIS_HOST = import_secret("REDIS_HOST") -REDIS_PORT = import_secret("REDIS_PORT") - LDAP_SERVER_URL = import_secret("LDAP_SERVER_URL") @@ -146,40 +141,3 @@ CAS_LOGIN_MSG = None CAS_IGNORE_REFERER = True CAS_REDIRECT_URL = "/" CAS_EMAIL_FORMAT = "%s@clipper.ens.fr" - -# --- -# Cache settings -# --- - -CACHES = { - "default": { - "BACKEND": "redis_cache.RedisCache", - "LOCATION": "redis://:{passwd}@{host}:{port}/{db}".format( - passwd=REDIS_PASSWD, host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB - ), - } -} - - -# --- -# Channels settings -# --- - -CHANNEL_LAYERS = { - "default": { - "BACKEND": "asgi_redis.RedisChannelLayer", - "CONFIG": { - "hosts": [ - ( - "redis://:{passwd}@{host}:{port}/{db}".format( - passwd=REDIS_PASSWD, - host=REDIS_HOST, - port=REDIS_PORT, - db=REDIS_DB, - ) - ) - ] - }, - "ROUTING": "cof.routing.routing", - } -} From 62d26560d953a0a47a74bd1507542705cb584b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Mon, 24 Aug 2020 14:56:03 +0200 Subject: [PATCH 3/4] Fix BDS {MEDIA,STATIC}_{URL,ROOT} --- cof/settings/bds_prod.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/cof/settings/bds_prod.py b/cof/settings/bds_prod.py index 6caf3bdf..31e986f8 100644 --- a/cof/settings/bds_prod.py +++ b/cof/settings/bds_prod.py @@ -15,13 +15,10 @@ ALLOWED_HOSTS = ["bds.ens.fr", "www.bds.ens.fr", "dev.cof.ens.fr"] INSTALLED_APPS += ["bds", "events", "clubs", "authens"] -STATIC_ROOT = os.path.join( - os.path.dirname(os.path.dirname(BASE_DIR)), "public", "gestion", "static" -) - -STATIC_URL = "/gestion/static/" -MEDIA_ROOT = os.path.join(os.path.dirname(BASE_DIR), "media") -MEDIA_URL = "/gestion/media/" +STATIC_ROOT = "/srv/bds.ens.fr/public/gestion2/static" +STATIC_URL = "/gestion2/static/" +MEDIA_ROOT = "/srv/bds.ens.fr/gestion2/media" +MEDIA_URL = "/gestion2/media/" # --- From 7a7e02adabea83010b8eaaf07ea4ff70ef5024e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Mon, 24 Aug 2020 15:30:50 +0200 Subject: [PATCH 4/4] Bump authens to 0.1b0 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 14c99407..bf58d8f4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,4 +17,4 @@ wagtailmenus==3.* wagtail-modeltranslation==0.10.* django-cors-headers==2.2.0 django-js-reverse -authens==0.* +authens==0.1b0