From e64e6bb5742d5b67f0f02aa710b9bac5b98bc838 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Sun, 27 Jul 2025 10:18:21 +0200 Subject: [PATCH] Added option to display custom RSS feed also to super admins --- modoboa/core/api/v2/serializers.py | 1 + modoboa/core/api/v2/tests.py | 6 ++++++ modoboa/core/api/v2/views.py | 5 ++++- modoboa/core/app_settings.py | 12 ++++++++++++ modoboa/templates/registration/base.html | 1 - modoboa/urls.py | 2 -- 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/modoboa/core/api/v2/serializers.py b/modoboa/core/api/v2/serializers.py index 1bded346d..f7ae10682 100644 --- a/modoboa/core/api/v2/serializers.py +++ b/modoboa/core/api/v2/serializers.py @@ -145,6 +145,7 @@ class CoreGlobalParametersSerializer(serializers.Serializer): rss_feed_url = serializers.URLField( allow_blank=True, required=False, allow_null=True ) + show_rss_feed_to_superadmins = serializers.BooleanField(default=False) hide_features_widget = serializers.BooleanField(default=False) # Theme settings diff --git a/modoboa/core/api/v2/tests.py b/modoboa/core/api/v2/tests.py index 50b208106..9d2588631 100644 --- a/modoboa/core/api/v2/tests.py +++ b/modoboa/core/api/v2/tests.py @@ -592,6 +592,12 @@ class NewsFeedAPIViewTestCase(ModoAPITestCase): self.assertEqual(response.status_code, 200) self.assertIn("modoboa", response.json()[0]["link"]) + # Try as superadmin and show_rss_feed_to_superadmins enabled + self.set_global_parameter("show_rss_feed_to_superadmins", True) + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + self.assertIn("django", response.json()[0]["link"]) + # Try as domainadmin dadmin = models.User.objects.get(username="admin@test.com") self.authenticate_user(dadmin) diff --git a/modoboa/core/api/v2/views.py b/modoboa/core/api/v2/views.py index 269d79224..d69e224c8 100644 --- a/modoboa/core/api/v2/views.py +++ b/modoboa/core/api/v2/views.py @@ -210,7 +210,10 @@ class NewsFeedAPIView(APIView): def get(self, request, *args, **kwargs): lang = "fr" if request.user.language == "fr" else "en" feed_url = f"{MODOBOA_WEBSITE_URL}{lang}/weblog/feeds/" - if request.user.role != "SuperAdmins": + show_rss_feed_to_superadmins = request.localconfig.parameters.get_value( + "show_rss_feed_to_superadmins" + ) + if request.user.role != "SuperAdmins" or show_rss_feed_to_superadmins: custom_feed_url = request.localconfig.parameters.get_value("rss_feed_url") if custom_feed_url: feed_url = custom_feed_url diff --git a/modoboa/core/app_settings.py b/modoboa/core/app_settings.py index 82bb837af..0ebb254a6 100644 --- a/modoboa/core/app_settings.py +++ b/modoboa/core/app_settings.py @@ -499,6 +499,18 @@ GLOBAL_PARAMETERS_STRUCT = collections.OrderedDict( ), }, ), + ( + "show_rss_feed_to_superadmins", + { + "label": gettext_lazy( + "Display custom RSS feed to super admins" + ), + "help_text": gettext_lazy( + "Display custom RSS feed also to super administrators" + ), + "widget": "BooleanField", + }, + ), ( "hide_features_widget", { diff --git a/modoboa/templates/registration/base.html b/modoboa/templates/registration/base.html index bc41ca789..78e1fd02a 100644 --- a/modoboa/templates/registration/base.html +++ b/modoboa/templates/registration/base.html @@ -22,7 +22,6 @@ {% block main_content %}{% endblock %} - {% block extra_js %}{% endblock %} diff --git a/modoboa/urls.py b/modoboa/urls.py index 72cd1df69..9b88d13f3 100644 --- a/modoboa/urls.py +++ b/modoboa/urls.py @@ -1,7 +1,6 @@ from django.conf import settings from django.contrib.auth import views as auth_views from django.urls import include, path -from django.views.i18n import JavaScriptCatalog from drf_spectacular.views import ( SpectacularJSONAPIView, @@ -13,7 +12,6 @@ from modoboa.core import views as core_views from modoboa.core.extensions import exts_pool urlpatterns = [ - path("jsi18n/", JavaScriptCatalog.as_view(), name="javascript-catalog"), path("", include("modoboa.core.urls")), path( "accounts/password_reset/",