diff --git a/allianceauth/authentication/middleware.py b/allianceauth/authentication/middleware.py index ca28d92f..e4bfb10f 100644 --- a/allianceauth/authentication/middleware.py +++ b/allianceauth/authentication/middleware.py @@ -52,4 +52,10 @@ class UserSettingsMiddleware(MiddlewareMixin): except Exception as e: logger.exception(e) + # Minimize Menu + try: + request.session["MINIMIZE_SIDEBAR"] = request.user.profile.minimize_sidebar + except Exception as e: + pass # We don't care that an anonymous user has no profile (not logged in) + return response diff --git a/allianceauth/authentication/migrations/0025_userprofile_minimize_sidebar.py b/allianceauth/authentication/migrations/0025_userprofile_minimize_sidebar.py new file mode 100644 index 00000000..bbd28732 --- /dev/null +++ b/allianceauth/authentication/migrations/0025_userprofile_minimize_sidebar.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.25 on 2025-10-14 22:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("authentication", "0024_alter_userprofile_language"), + ] + + operations = [ + migrations.AddField( + model_name="userprofile", + name="minimize_sidebar", + field=models.BooleanField( + default=False, + help_text="Keep the sidebar menu minimized", + verbose_name="Minimize Sidebar Menu", + ), + ), + ] diff --git a/allianceauth/authentication/models.py b/allianceauth/authentication/models.py index 8871e7ee..074c10a5 100644 --- a/allianceauth/authentication/models.py +++ b/allianceauth/authentication/models.py @@ -97,7 +97,8 @@ class UserProfile(models.Model): on_delete=models.SET_DEFAULT, default=get_guest_state_pk) language = models.CharField( - _("Language"), max_length=10, + _("Language"), + max_length=10, choices=Language.choices, blank=True, default='') @@ -112,6 +113,12 @@ class UserProfile(models.Model): null=True, help_text="Bootstrap 5 Themes from https://bootswatch.com/ or Community Apps" ) + minimize_sidebar = models.BooleanField( + _("Minimize Sidebar Menu"), + default=False, + help_text=_("Keep the sidebar menu minimized") + ) + def assign_state(self, state=None, commit=True): if not state: diff --git a/allianceauth/authentication/tests/test_middleware.py b/allianceauth/authentication/tests/test_middleware.py index 70335e58..d5dd8667 100644 --- a/allianceauth/authentication/tests/test_middleware.py +++ b/allianceauth/authentication/tests/test_middleware.py @@ -88,6 +88,7 @@ class TestUserSettingsMiddlewareLoginFlow(TestCase): self.request.LANGUAGE_CODE = 'en' self.request.user.profile.language = 'de' self.request.user.profile.night_mode = True + self.request.user.profile.minimize_sidebar = False self.request.user.is_anonymous = False self.response = Mock() self.response.content = 'hello world' @@ -173,3 +174,26 @@ class TestUserSettingsMiddlewareLoginFlow(TestCase): self.response ) self.assertEqual(self.request.session["NIGHT_MODE"], True) + + def test_middleware_set_mimimize_sidebar(self): + """ + tests the middleware will always set minimize_sidebar to False (default) + """ + + response = self.middleware.process_response( + self.request, + self.response + ) + self.assertEqual(self.request.session["MINIMIZE_SIDEBAR"], False) + + def test_middleware_minimize_sidebar_when_set(self): + """ + tests the middleware will set mimimize_sidebar to True from DB + """ + + self.request.user.profile.minimize_sidebar = True + response = self.middleware.process_response( + self.request, + self.response + ) + self.assertEqual(self.request.session["MINIMIZE_SIDEBAR"], True) diff --git a/allianceauth/menu/templates/menu/menu-user.html b/allianceauth/menu/templates/menu/menu-user.html index fd2bc31f..a5f45739 100644 --- a/allianceauth/menu/templates/menu/menu-user.html +++ b/allianceauth/menu/templates/menu/menu-user.html @@ -72,6 +72,31 @@ {% theme_select %} + {% if user.is_authenticated and not request.is_mobile_device %} +