From 304b2a725c964fc326af47b08807c2a934997050 Mon Sep 17 00:00:00 2001 From: Gagan Deep Date: Tue, 27 Aug 2024 17:32:02 +0530 Subject: [PATCH 1/4] [fix] Dashboard timeseries chart should respect MONITORING_API_BASEURL Django admin should make API request to MONITORING_API_BASEURL. --- openwisp_monitoring/device/apps.py | 10 +- .../device/static/monitoring/js/device-map.js | 115 ++++++++++-------- .../static/monitoring/js/chart-utils.js | 3 + openwisp_monitoring/tests/test_selenium.py | 38 ++++++ 4 files changed, 112 insertions(+), 54 deletions(-) diff --git a/openwisp_monitoring/device/apps.py b/openwisp_monitoring/device/apps.py index 67d988073..0f61a5f05 100644 --- a/openwisp_monitoring/device/apps.py +++ b/openwisp_monitoring/device/apps.py @@ -427,6 +427,14 @@ def register_dashboard_items(self): } } + dashboard_chart_url = reverse_lazy( + 'monitoring_general:api_dashboard_timeseries', + urlconf=MONITORING_API_URLCONF, + ) + if MONITORING_API_BASEURL: + dashboard_chart_url = urljoin( + MONITORING_API_BASEURL, str(dashboard_chart_url) + ) register_dashboard_template( position=55, config={ @@ -450,7 +458,7 @@ def register_dashboard_items(self): ), }, extra_config={ - 'api_url': reverse_lazy('monitoring_general:api_dashboard_timeseries'), + 'api_url': dashboard_chart_url, 'default_time': Chart.DEFAULT_TIME, 'chart_quick_links': general_wifi_client_quick_links, }, diff --git a/openwisp_monitoring/device/static/monitoring/js/device-map.js b/openwisp_monitoring/device/static/monitoring/js/device-map.js index 1ab0f3dcf..00fc8a15a 100644 --- a/openwisp_monitoring/device/static/monitoring/js/device-map.js +++ b/openwisp_monitoring/device/static/monitoring/js/device-map.js @@ -54,65 +54,74 @@ loadingOverlay.show(); - $.getJSON(url, function (data) { - let html = '', - device; - for (let i = 0; i < data.results.length; i++) { - device = data.results[i]; - html += ` - - ${device.name} - - - ${device.monitoring.status_label} - - - `; - } - let pagination = '', - parts = []; - if (data.previous || data.next) { - if (data.previous) { - parts.push(``); + $.ajax({ + dataType: "json", + url: url, + xhrFields: { + withCredentials: true + }, + success: function (data) { + let html = '', + device; + for (let i = 0; i < data.results.length; i++) { + device = data.results[i]; + html += ` + + ${device.name} + + + ${device.monitoring.status_label} + + + `; } - if (data.next) { - parts.push(``); + let pagination = '', + parts = []; + if (data.previous || data.next) { + if (data.previous) { + parts.push(``); + } + if (data.next) { + parts.push(``); + } + pagination = `

${parts.join(' ')}`; } - pagination = `

${parts.join(' ')}`; - } - layer.bindPopup(` -

-

${layer.feature.properties.name} (${data.count})

- - - - - - - - - ${html} - -
${gettext('name')}${gettext('status')}
- ${pagination} -
`); - layer.openPopup(); + layer.bindPopup(` +
+

${layer.feature.properties.name} (${data.count})

+ + + + + + + + + ${html} + +
${gettext('name')}${gettext('status')}
+ ${pagination} +
`); + layer.openPopup(); - // bind next/prev buttons - let el = $(layer.getPopup().getElement()); - el.find('.next').click(function () { - loadPopUpContent(layer, $(this).data('url')); - }); - el.find('.prev').click(function () { - loadPopUpContent(layer, $(this).data('url')); - }); + // bind next/prev buttons + let el = $(layer.getPopup().getElement()); + el.find('.next').click(function () { + loadPopUpContent(layer, $(this).data('url')); + }); + el.find('.prev').click(function () { + loadPopUpContent(layer, $(this).data('url')); + }); - loadingOverlay.hide(); + loadingOverlay.hide(); - }).fail(function () { - loadingOverlay.hide(); - alert(gettext('Error while retrieving data')); + }, + error: function () { + loadingOverlay.hide(); + alert(gettext('Error while retrieving data')); + } }); + }; const leafletConfig = JSON.parse($('#leaflet-config').text()); const tiles = leafletConfig.TILES.map((tile) => { diff --git a/openwisp_monitoring/monitoring/static/monitoring/js/chart-utils.js b/openwisp_monitoring/monitoring/static/monitoring/js/chart-utils.js index 3584854b7..edf32a846 100644 --- a/openwisp_monitoring/monitoring/static/monitoring/js/chart-utils.js +++ b/openwisp_monitoring/monitoring/static/monitoring/js/chart-utils.js @@ -236,6 +236,9 @@ django.jQuery(function ($) { loadCharts = function (time, showLoading) { $.ajax(getChartFetchUrl(time), { dataType: 'json', + xhrFields: { + withCredentials: true + }, beforeSend: function () { chartContents.hide(); chartContents.empty(); diff --git a/openwisp_monitoring/tests/test_selenium.py b/openwisp_monitoring/tests/test_selenium.py index 8bab42117..4f27801ab 100644 --- a/openwisp_monitoring/tests/test_selenium.py +++ b/openwisp_monitoring/tests/test_selenium.py @@ -16,6 +16,7 @@ ) from openwisp_monitoring.monitoring.configuration import DEFAULT_DASHBOARD_TRAFFIC_CHART from openwisp_monitoring.monitoring.migrations import create_general_metrics +from openwisp_utils.admin_theme.dashboard import DASHBOARD_TEMPLATES from openwisp_utils.test_selenium_mixins import ( SeleniumTestMixin as BaseSeleniumTestMixin, ) @@ -30,6 +31,43 @@ class SeleniumTestMixin(BaseSeleniumTestMixin): + @classmethod + def setUpClass(cls): + """ + Sets up the necessary configurations for the test environment, ensuring + that the dashboard templates render correctly during Selenium tests. + + During testing, the `OPENWISP_MONITORING_API_BASEURL` is set to + `http://testserver`, a dummy value for the test environment. The dashboard + templates are registered in the `AppConfig.ready` method, and these + templates depend on specific URLs being correctly configured. + + Since mocking the `OPENWISP_MONITORING_API_BASEURL` does not update the + URLs in the already registered dashboard templates, this method manually + adjusts the template contexts to ensure they contain the correct URLs. + """ + super().setUpClass() + cls._dashboard_map_context = DASHBOARD_TEMPLATES[0][1].copy() + cls._dashboard_timeseries_context = DASHBOARD_TEMPLATES[55][1].copy() + DASHBOARD_TEMPLATES[0][1] = { + 'monitoring_device_list_url': reverse( + 'monitoring:api_location_device_list', + args=['000'], + ), + 'monitoring_location_geojson_url': reverse( + 'monitoring:api_location_geojson' + ), + } + DASHBOARD_TEMPLATES[55][1]['api_url'] = reverse( + 'monitoring_general:api_dashboard_timeseries' + ) + + @classmethod + def tearDownClass(cls): + super().tearDownClass() + DASHBOARD_TEMPLATES[0][1] = cls._dashboard_map_context + DASHBOARD_TEMPLATES[55][1] = cls._dashboard_timeseries_context + def setUp(self): self.admin = self._create_admin( username=self.admin_username, password=self.admin_password From b7e14204c84858f874c04e989dc7bba639712cf1 Mon Sep 17 00:00:00 2001 From: Gagan Deep Date: Wed, 28 Aug 2024 00:02:53 +0530 Subject: [PATCH 2/4] [deps] Added compatibility for django-allauth~=0.63.6 --- tests/openwisp2/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/openwisp2/settings.py b/tests/openwisp2/settings.py index c7772d5cd..f66a8e572 100644 --- a/tests/openwisp2/settings.py +++ b/tests/openwisp2/settings.py @@ -104,6 +104,7 @@ 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'allauth.account.middleware.AccountMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] From 669ee3d04713174fe95dc5ee827d71af3123d108 Mon Sep 17 00:00:00 2001 From: Federico Capoano Date: Fri, 30 Aug 2024 16:30:51 -0400 Subject: [PATCH 3/4] [docs] Minor fixes [skip ci] --- docs/developer/index.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/developer/index.rst b/docs/developer/index.rst index 99915fc96..d441a2cb1 100644 --- a/docs/developer/index.rst +++ b/docs/developer/index.rst @@ -12,5 +12,5 @@ Developer Docs Other useful resources: - - :doc:`../user/rest-api` - - :doc:`../user/settings` +- :doc:`../user/rest-api` +- :doc:`../user/settings` From d922c588ff5822fc4549acaa9f1ff2ca3e3976eb Mon Sep 17 00:00:00 2001 From: Federico Capoano Date: Tue, 24 Sep 2024 14:28:02 -0400 Subject: [PATCH 4/4] [docs] Added FUNDING.yml [skip ci] --- .github/FUNDING.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 000000000..978d8488a --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,15 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry +polar: # Replace with a single Polar username +buy_me_a_coffee: # Replace with a single Buy Me a Coffee username +thanks_dev: # Replace with a single thanks.dev username +custom: ["https://openwisp.org/sponsorship/"]