From eedf8a10686812530136c218e13bd91a31063757 Mon Sep 17 00:00:00 2001 From: Abhimanyu Saharan Date: Thu, 11 May 2023 02:35:19 +0530 Subject: [PATCH 1/4] adds BANNER_MAINTENANCE config #12554 --- docs/configuration/miscellaneous.md | 9 +++++++++ netbox/extras/admin.py | 5 ++++- netbox/netbox/config/parameters.py | 7 +++++++ netbox/templates/base/layout.html | 4 ++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/docs/configuration/miscellaneous.md b/docs/configuration/miscellaneous.md index c3fbb40aaf5..f86086d5366 100644 --- a/docs/configuration/miscellaneous.md +++ b/docs/configuration/miscellaneous.md @@ -121,6 +121,15 @@ Default: False Setting this to True will display a "maintenance mode" banner at the top of every page. Additionally, NetBox will no longer update a user's "last active" time upon login. This is to allow new logins when the database is in a read-only state. Recording of login times will resume when maintenance mode is disabled. +## BANNER_MAINTENANCE + +!!! tip "Dynamic Configuration Parameter" + +!!! note + This parameter was added in NetBox v3.5. + +This adds a banner to the top of every page when maintenance mode is enabled. HTML is allowed. + --- ## MAPS_URL diff --git a/netbox/extras/admin.py b/netbox/extras/admin.py index 04a67b521bc..6cc503096f1 100644 --- a/netbox/extras/admin.py +++ b/netbox/extras/admin.py @@ -39,7 +39,10 @@ class ConfigRevisionAdmin(admin.ModelAdmin): 'fields': ('DEFAULT_USER_PREFERENCES',), }), ('Miscellaneous', { - 'fields': ('MAINTENANCE_MODE', 'GRAPHQL_ENABLED', 'CHANGELOG_RETENTION', 'JOB_RETENTION', 'MAPS_URL'), + 'fields': ( + 'MAINTENANCE_MODE', 'BANNER_MAINTENANCE', 'GRAPHQL_ENABLED', 'CHANGELOG_RETENTION', 'JOB_RETENTION', + 'MAPS_URL' + ), }), ('Config Revision', { 'fields': ('comment',), diff --git a/netbox/netbox/config/parameters.py b/netbox/netbox/config/parameters.py index 2bfa234f086..228cbd4f799 100644 --- a/netbox/netbox/config/parameters.py +++ b/netbox/netbox/config/parameters.py @@ -199,6 +199,13 @@ def __init__(self, name, label, default, description='', field=None, field_kwarg description=_("Enable maintenance mode"), field=forms.BooleanField ), + ConfigParam( + name='BANNER_MAINTENANCE', + label=_('Maintenance banner'), + default=None, + description=_('Additional content to display when in maintenance mode'), + field=forms.CharField, + ), ConfigParam( name='GRAPHQL_ENABLED', label=_('GraphQL enabled'), diff --git a/netbox/templates/base/layout.html b/netbox/templates/base/layout.html index 6b247d81a80..9e8b7d7bfb9 100644 --- a/netbox/templates/base/layout.html +++ b/netbox/templates/base/layout.html @@ -77,10 +77,10 @@ {% endif %} - {% if config.MAINTENANCE_MODE %} + {% if config.MAINTENANCE_MODE and config.BANNER_MAINTENANCE %} {% endif %} From 3e38c10b8113d15a79a5b72a5e0130300ab69c39 Mon Sep 17 00:00:00 2001 From: Abhimanyu Saharan Date: Fri, 12 May 2023 18:45:42 +0530 Subject: [PATCH 2/4] changes as per review --- docs/configuration/miscellaneous.md | 20 +++++++++++--------- netbox/extras/admin.py | 6 ++---- netbox/netbox/config/parameters.py | 14 +++++++------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/docs/configuration/miscellaneous.md b/docs/configuration/miscellaneous.md index f86086d5366..e3728acabef 100644 --- a/docs/configuration/miscellaneous.md +++ b/docs/configuration/miscellaneous.md @@ -29,6 +29,17 @@ This defines custom content to be displayed on the login page above the login fo --- +## BANNER_MAINTENANCE + +!!! tip "Dynamic Configuration Parameter" + +!!! note + This parameter was added in NetBox v3.5. + +This adds a banner to the top of every page when maintenance mode is enabled. HTML is allowed. + +--- + ## BANNER_TOP !!! tip "Dynamic Configuration Parameter" @@ -121,15 +132,6 @@ Default: False Setting this to True will display a "maintenance mode" banner at the top of every page. Additionally, NetBox will no longer update a user's "last active" time upon login. This is to allow new logins when the database is in a read-only state. Recording of login times will resume when maintenance mode is disabled. -## BANNER_MAINTENANCE - -!!! tip "Dynamic Configuration Parameter" - -!!! note - This parameter was added in NetBox v3.5. - -This adds a banner to the top of every page when maintenance mode is enabled. HTML is allowed. - --- ## MAPS_URL diff --git a/netbox/extras/admin.py b/netbox/extras/admin.py index 6cc503096f1..e78a46cc56e 100644 --- a/netbox/extras/admin.py +++ b/netbox/extras/admin.py @@ -25,7 +25,7 @@ class ConfigRevisionAdmin(admin.ModelAdmin): 'fields': ('ALLOWED_URL_SCHEMES',), }), ('Banners', { - 'fields': ('BANNER_LOGIN', 'BANNER_TOP', 'BANNER_BOTTOM'), + 'fields': ('BANNER_LOGIN', 'BANNER_MAINTENANCE', 'BANNER_TOP', 'BANNER_BOTTOM'), 'classes': ('monospace',), }), ('Pagination', { @@ -39,9 +39,7 @@ class ConfigRevisionAdmin(admin.ModelAdmin): 'fields': ('DEFAULT_USER_PREFERENCES',), }), ('Miscellaneous', { - 'fields': ( - 'MAINTENANCE_MODE', 'BANNER_MAINTENANCE', 'GRAPHQL_ENABLED', 'CHANGELOG_RETENTION', 'JOB_RETENTION', - 'MAPS_URL' + 'fields': ('MAINTENANCE_MODE', 'GRAPHQL_ENABLED', 'CHANGELOG_RETENTION', 'JOB_RETENTION', 'MAPS_URL' ), }), ('Config Revision', { diff --git a/netbox/netbox/config/parameters.py b/netbox/netbox/config/parameters.py index 228cbd4f799..4cc93c1612b 100644 --- a/netbox/netbox/config/parameters.py +++ b/netbox/netbox/config/parameters.py @@ -28,6 +28,13 @@ def __init__(self, name, label, default, description='', field=None, field_kwarg ), }, ), + ConfigParam( + name='BANNER_MAINTENANCE', + label=_('Maintenance banner'), + default='NetBox is currently in maintenance mode. Functionality may be limited.', + description=_('Additional content to display when in maintenance mode'), + field=forms.CharField, + ), ConfigParam( name='BANNER_TOP', label=_('Top banner'), @@ -199,13 +206,6 @@ def __init__(self, name, label, default, description='', field=None, field_kwarg description=_("Enable maintenance mode"), field=forms.BooleanField ), - ConfigParam( - name='BANNER_MAINTENANCE', - label=_('Maintenance banner'), - default=None, - description=_('Additional content to display when in maintenance mode'), - field=forms.CharField, - ), ConfigParam( name='GRAPHQL_ENABLED', label=_('GraphQL enabled'), From 16dff7c45c4bf009d399905799bfe3d715e28b84 Mon Sep 17 00:00:00 2001 From: Abhimanyu Saharan Date: Fri, 12 May 2023 18:46:54 +0530 Subject: [PATCH 3/4] lint fix --- netbox/extras/admin.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/netbox/extras/admin.py b/netbox/extras/admin.py index e78a46cc56e..6d1b1437068 100644 --- a/netbox/extras/admin.py +++ b/netbox/extras/admin.py @@ -39,8 +39,7 @@ class ConfigRevisionAdmin(admin.ModelAdmin): 'fields': ('DEFAULT_USER_PREFERENCES',), }), ('Miscellaneous', { - 'fields': ('MAINTENANCE_MODE', 'GRAPHQL_ENABLED', 'CHANGELOG_RETENTION', 'JOB_RETENTION', 'MAPS_URL' - ), + 'fields': ('MAINTENANCE_MODE', 'GRAPHQL_ENABLED', 'CHANGELOG_RETENTION', 'JOB_RETENTION', 'MAPS_URL'), }), ('Config Revision', { 'fields': ('comment',), From 8e01663ec0a685a64d36288d33c29f98123aa94a Mon Sep 17 00:00:00 2001 From: jeremystretch Date: Fri, 12 May 2023 09:54:05 -0400 Subject: [PATCH 4/4] Fix admin form field widget --- netbox/netbox/config/parameters.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/netbox/netbox/config/parameters.py b/netbox/netbox/config/parameters.py index 4cc93c1612b..9c613217c38 100644 --- a/netbox/netbox/config/parameters.py +++ b/netbox/netbox/config/parameters.py @@ -33,7 +33,11 @@ def __init__(self, name, label, default, description='', field=None, field_kwarg label=_('Maintenance banner'), default='NetBox is currently in maintenance mode. Functionality may be limited.', description=_('Additional content to display when in maintenance mode'), - field=forms.CharField, + field_kwargs={ + 'widget': forms.Textarea( + attrs={'class': 'vLargeTextField'} + ), + }, ), ConfigParam( name='BANNER_TOP',