From 13c26ccb0c3cf130556b99439b5f6f7f5d455b2f Mon Sep 17 00:00:00 2001 From: bctiemann Date: Mon, 16 Dec 2024 11:46:28 -0500 Subject: [PATCH] Fixes: #18184 - Gracefully handle unavailable internet connection on RSS feed dashboard widget if ISOLATED_DEPLOYMENT is set (#18186) * Suppress adding the RSS feed widget to the dashboard if ISOLATED_DEPLOYMENT is set * Add config option on RSSFeedWidget to specify requires_internet and to display a more appropriate error if ISOLATED_DEPLOYMENT is set * Remove skipping behavior from utils.py * Add required=False --- netbox/extras/constants.py | 1 + netbox/extras/dashboard/widgets.py | 10 ++++++++++ netbox/templates/extras/dashboard/widgets/rssfeed.html | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/netbox/extras/constants.py b/netbox/extras/constants.py index 3bfe3b21b..994586aca 100644 --- a/netbox/extras/constants.py +++ b/netbox/extras/constants.py @@ -79,6 +79,7 @@ DEFAULT_DASHBOARD = [ 'feed_url': 'http://netbox.dev/rss/', 'max_entries': 10, 'cache_timeout': 14400, + 'requires_internet': True, } }, { diff --git a/netbox/extras/dashboard/widgets.py b/netbox/extras/dashboard/widgets.py index c56e4cd7d..6bb7f59fb 100644 --- a/netbox/extras/dashboard/widgets.py +++ b/netbox/extras/dashboard/widgets.py @@ -275,6 +275,7 @@ class RSSFeedWidget(DashboardWidget): default_config = { 'max_entries': 10, 'cache_timeout': 3600, # seconds + 'requires_internet': True, } description = _('Embed an RSS feed from an external website.') template_name = 'extras/dashboard/widgets/rssfeed.html' @@ -285,6 +286,10 @@ class RSSFeedWidget(DashboardWidget): feed_url = forms.URLField( label=_('Feed URL') ) + requires_internet = forms.BooleanField( + label=_('Requires external connection'), + required=False, + ) max_entries = forms.IntegerField( min_value=1, max_value=1000, @@ -309,6 +314,11 @@ class RSSFeedWidget(DashboardWidget): return f'dashboard_rss_{url_checksum}' def get_feed(self): + if self.config['requires_internet'] and settings.ISOLATED_DEPLOYMENT: + return { + 'isolated_deployment': True, + } + # Fetch RSS content from cache if available if feed_content := cache.get(self.cache_key): return { diff --git a/netbox/templates/extras/dashboard/widgets/rssfeed.html b/netbox/templates/extras/dashboard/widgets/rssfeed.html index 4420783fd..fa602a112 100644 --- a/netbox/templates/extras/dashboard/widgets/rssfeed.html +++ b/netbox/templates/extras/dashboard/widgets/rssfeed.html @@ -12,6 +12,10 @@
{% trans "No content found" %}
{% endfor %} +{% elif isolated_deployment %} + + {% trans "This RSS feed requires an external connection. Check the ISOLATED_DEPLOYMENT setting." %} + {% else %} {# There was an error retrieving/parsing the feed #}