From f362bb1a6026696ebb08842e3aa7857e706e6502 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Sun, 23 May 2021 13:11:17 +0200 Subject: [PATCH] =?UTF-8?q?Rajoute=20la=20possibilit=C3=A9=20d'autoriser?= =?UTF-8?q?=20l'acc=C3=A8s=20aux=20membres=20de=20staffs,=20avec=20une=20p?= =?UTF-8?q?romotion=20valant=200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- authens/conf.py | 1 + authens/utils.py | 13 +++++++++++++ setup.cfg | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/authens/conf.py b/authens/conf.py index 732b984..1e9db4d 100644 --- a/authens/conf.py +++ b/authens/conf.py @@ -1,4 +1,5 @@ LDAP_SERVER_URL = "ldaps://ldap.spi.ens.fr:636" AUTHENS_USE_OLDCAS = True AUTHENS_USE_PASSWORD = True +AUTHENS_ALLOW_STAFF = False # TODO: CAS_SERVER_URL diff --git a/authens/utils.py b/authens/utils.py index 2dc0876..733cf10 100644 --- a/authens/utils.py +++ b/authens/utils.py @@ -3,6 +3,10 @@ from urllib.parse import urlunparse from cas import CASClient +from django.conf import settings + +from authens import conf as default_conf + def get_cas_client(request): """Return a CAS client configured for SPI's CAS.""" @@ -26,6 +30,15 @@ def parse_entrance_year(home_dir): return None dirs = home_dir.split("/") + + allow_staff = getattr( + settings, "AUTHENS_ALLOW_STAFF", default_conf.AUTHENS_ALLOW_STAFF + ) + + # The staff members have an entrance year set to 0 + if allow_staff and dirs[:3] == ["", "users", "staffs"]: + return 0 + if len(dirs) < 3 or not dirs[2].isdecimal() or dirs[1] != "users": raise ValueError("Invalid home directory: {}".format(home_dir)) diff --git a/setup.cfg b/setup.cfg index eea30e5..7d2e5cf 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,7 +10,7 @@ ignore = W503 [isort] -profile=black +profile = black known_django = django known_first_party = authens,tests sections = FUTURE,STDLIB,THIRDPARTY,DJANGO,FIRSTPARTY,LOCALFOLDER