Repository: modoboa/modoboa

Issue:
Dashboard - server behind proxy
# Impacted versions

* Modoboa: 1.14.0
* Webserver: Nginx

# Steps to reproduce
Modoboa server is behind proxy, so no internet direct access
Acces dashboard via admin account

# Current behavior
504 Gateway Time-out

# Expected behavior
no error



Discussion:

Resolving patch:
diff --git a/modoboa/core/views/dashboard.py b/modoboa/core/views/dashboard.py
--- a/modoboa/core/views/dashboard.py
+++ b/modoboa/core/views/dashboard.py
@@ -8,6 +8,8 @@
 from django.contrib.auth import mixins as auth_mixins
 from django.views import generic
 
+from django.conf import settings
+
 from .. import signals
 
 MODOBOA_WEBSITE_URL = "https://modoboa.org/"
@@ -43,11 +45,12 @@ def get_context_data(self, **kwargs):
                 self.request.localconfig.parameters.get_value("rss_feed_url"))
             if custom_feed_url:
                 feed_url = custom_feed_url
-        posts = feedparser.parse(feed_url)
         entries = []
-        for entry in posts["entries"][:5]:
-            entry["published"] = parser.parse(entry["published"])
-            entries.append(entry)
+        if not settings.DISABLE_DASHBOARD_EXTERNAL_QUERIES:
+            posts = feedparser.parse(feed_url)
+            for entry in posts["entries"][:5]:
+                entry["published"] = parser.parse(entry["published"])
+                entries.append(entry)
         context["widgets"]["left"].append("core/_latest_news_widget.html")
         context.update({"news": entries})
 
@@ -57,13 +60,14 @@ def get_context_data(self, **kwargs):
             url = "{}{}/api/projects/?featured=true".format(
                 MODOBOA_WEBSITE_URL, lang)
             features = []
-            try:
-                response = requests.get(url)
-            except RequestException:
-                pass
-            else:
-                if response.status_code == 200:
-                    features = response.json()
+            if not settings.DISABLE_DASHBOARD_EXTERNAL_QUERIES:
+                try:
+                    response = requests.get(url)
+                except RequestException:
+                    pass
+                else:
+                    if response.status_code == 200:
+                        features = response.json()
             context["widgets"]["right"].append("core/_current_features.html")
             context.update({"features": features})
 


Test patch:
diff --git a/modoboa/core/tests/test_views.py b/modoboa/core/tests/test_views.py
--- a/modoboa/core/tests/test_views.py
+++ b/modoboa/core/tests/test_views.py
@@ -4,6 +4,7 @@
 
 from django import forms
 from django.urls import reverse
+from django.test import override_settings
 
 from modoboa.lib.tests import ModoTestCase
 from modoboa.parameters import forms as param_forms, tools as param_tools
@@ -159,6 +160,20 @@ def test_features_visibility(self):
         response = self.client.get(url)
         self.assertNotContains(response, "Features looking for sponsoring")
 
+    @override_settings(DISABLE_DASHBOARD_EXTERNAL_QUERIES=False)
+    def test_enable_dashboard_external_queries(self):
+        """Load dashboard with DISABLE_DASHBOARD_EXTERNAL_QUERIES = False"""
+        url = reverse("core:dashboard")
+        response = self.client.get(url)
+        self.assertContains(response, 'href="https://modoboa.org/en/weblog/')
+
+    @override_settings(DISABLE_DASHBOARD_EXTERNAL_QUERIES=True)
+    def test_disable_dashboard_external_queries(self):
+        """Load dashboard with DISABLE_DASHBOARD_EXTERNAL_QUERIES = True"""
+        url = reverse("core:dashboard")
+        response = self.client.get(url)
+        self.assertNotContains(response, 'https://modoboa.org/en/weblog/')
+
     def test_root_dispatch(self):
         """Check root dispatching."""
         url = reverse("core:root")
diff --git a/test_project/test_project/settings.py b/test_project/test_project/settings.py
--- a/test_project/test_project/settings.py
+++ b/test_project/test_project/settings.py
@@ -292,4 +292,5 @@
     "security.W019",  # modoboa uses iframes to display e-mails
 ]
 
+DISABLE_DASHBOARD_EXTERNAL_QUERIES = False
 # Load settings from extensions