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