diff --git a/aleksis/core/apps.py b/aleksis/core/apps.py index 75feb14c3ed9e6d717d1bbd89bf0ef87070d34b3..3d3f86933acb3b86e87c644bfc92db37832c27cb 100644 --- a/aleksis/core/apps.py +++ b/aleksis/core/apps.py @@ -2,8 +2,6 @@ from typing import Any, List, Optional, Tuple import django.apps from django.apps import apps -from django.conf import settings -from django.db import OperationalError, ProgrammingError from django.http import HttpRequest from django.utils.module_loading import autodiscover_modules @@ -16,7 +14,7 @@ from .registries import ( site_preferences_registry, ) from .util.apps import AppConfig -from .util.core_helpers import get_site_preferences, has_person +from .util.core_helpers import has_person from .util.sass_helpers import clean_scss @@ -52,8 +50,6 @@ class CoreConfig(AppConfig): preference_models.register(personpreferencemodel, person_preferences_registry) preference_models.register(grouppreferencemodel, group_preferences_registry) - self._refresh_authentication_backends() - self._load_data_checks() from .health_checks import DataChecksHealthCheckBackend @@ -70,24 +66,6 @@ class CoreConfig(AppConfig): data_checks += getattr(model, "data_checks", []) DataCheckRegistry.data_checks = data_checks - @classmethod - def _refresh_authentication_backends(cls): - """Refresh config list of enabled authentication backends.""" - from .preferences import AuthenticationBackends # noqa - - idx = settings.AUTHENTICATION_BACKENDS.index("django.contrib.auth.backends.ModelBackend") - - try: - # Don't set array directly in order to keep object reference - settings._wrapped.AUTHENTICATION_BACKENDS.clear() - settings._wrapped.AUTHENTICATION_BACKENDS += settings.ORIGINAL_AUTHENTICATION_BACKENDS - - for backend in get_site_preferences()["auth__backends"]: - settings._wrapped.AUTHENTICATION_BACKENDS.insert(idx, backend) - idx += 1 - except (ProgrammingError, OperationalError): - pass - def preference_updated( self, sender: Any, @@ -97,9 +75,6 @@ class CoreConfig(AppConfig): new_value: Optional[Any] = None, **kwargs, ) -> None: - if section == "auth" and name == "backends": - self._refresh_authentication_backends() - if section == "theme": if name in ("primary", "secondary"): clean_scss() diff --git a/aleksis/core/preferences.py b/aleksis/core/preferences.py index a8cbe1ef56deee73e82c5d0a77983078de186dac..1a9f77d41962554708219370f445b0bb1f0a6b8e 100644 --- a/aleksis/core/preferences.py +++ b/aleksis/core/preferences.py @@ -190,18 +190,6 @@ class SchoolNameOfficial(StringPreference): verbose_name = _("Official name of the school, e.g. as given by supervisory authority") -@site_preferences_registry.register -class AuthenticationBackends(MultipleChoicePreference): - section = auth - name = "backends" - default = None - verbose_name = _("Enabled custom authentication backends") - field_attribute = {"initial": []} - - def get_choices(self): - return [(b, b) for b in settings.CUSTOM_AUTHENTICATION_BACKENDS] - - @site_preferences_registry.register class AvailableLanguages(MultipleChoicePreference): section = internationalisation diff --git a/aleksis/core/settings.py b/aleksis/core/settings.py index f6f8f538345f76bbfd3a340ae748c9bbc77e3f09..d60eee40cf50d0f77ea6156a7ad0bc1511e2eafe 100644 --- a/aleksis/core/settings.py +++ b/aleksis/core/settings.py @@ -723,6 +723,4 @@ HEALTH_CHECK = { "MEMORY_MIN": _settings.get("health.memory_min_mb", 500), } -ORIGINAL_AUTHENTICATION_BACKENDS = AUTHENTICATION_BACKENDS[:] - PROMETHEUS_EXPORT_MIGRATIONS = False diff --git a/aleksis/core/tests/test_authentication_backends.py b/aleksis/core/tests/test_authentication_backends.py deleted file mode 100644 index 227f48c1469d97f246132a4bfbef2f5af5f4dbb9..0000000000000000000000000000000000000000 --- a/aleksis/core/tests/test_authentication_backends.py +++ /dev/null @@ -1,64 +0,0 @@ -from typing import Optional - -from django.contrib.auth import authenticate -from django.contrib.auth.backends import BaseBackend -from django.contrib.auth.base_user import AbstractBaseUser -from django.contrib.auth.models import User - -import pytest - -from aleksis.core.apps import CoreConfig -from aleksis.core.util.core_helpers import get_site_preferences - -pytestmark = pytest.mark.django_db - - -class DummyBackend(BaseBackend): - def authenticate( - self, request, username: str, password: str, **kwargs - ) -> Optional[AbstractBaseUser]: - if username == "foo" and password == "baz": - return User.objects.get_or_create(username="foo")[0] - - -backend_name = "aleksis.core.tests.test_authentication_backends.DummyBackend" - - -def test_backends_simple(settings): - - assert not authenticate(username="foo", password="baz") - - assert backend_name not in settings.AUTHENTICATION_BACKENDS - - settings.AUTHENTICATION_BACKENDS.append(backend_name) - assert backend_name in settings.AUTHENTICATION_BACKENDS - - assert authenticate(username="foo", password="baz") - - settings.AUTHENTICATION_BACKENDS.remove(backend_name) - - assert not authenticate(username="foo", password="baz") - - -def test_backends_with_activation(settings): - assert not authenticate(username="foo", password="baz") - - settings.CUSTOM_AUTHENTICATION_BACKENDS.append(backend_name) - - assert backend_name not in get_site_preferences()["auth__backends"] - assert backend_name not in settings.AUTHENTICATION_BACKENDS - assert not authenticate(username="foo", password="baz") - - print(get_site_preferences()["auth__backends"]) - print(get_site_preferences()["auth__backends"].append(backend_name)) - - get_site_preferences()["auth__backends"] = [backend_name] - - assert backend_name in get_site_preferences()["auth__backends"] - assert backend_name in settings.AUTHENTICATION_BACKENDS - assert authenticate(username="foo", password="baz") - - get_site_preferences()["auth__backends"] = [] - - assert backend_name not in get_site_preferences()["auth__backends"] - assert backend_name not in settings.AUTHENTICATION_BACKENDS