Skip to content

Commit

Permalink
Fixes: #18369 - Remove the json filter for protection rules (#18388)
Browse files Browse the repository at this point in the history
* Remove the json filter for protection rules

* Configure PROTECTION_RULE config attribute to use ConfigJSONEncoder as serializer

* Tweak getattr()

---------

Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
  • Loading branch information
2 people authored and bctiemann committed Jan 29, 2025
1 parent 8cc9a5a commit 39cd8bc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions netbox/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,8 +570,9 @@ def get(self, request):
return response

# Serialize any CustomValidator classes
if hasattr(config, 'CUSTOM_VALIDATORS') and config.CUSTOM_VALIDATORS:
config.CUSTOM_VALIDATORS = json.dumps(config.CUSTOM_VALIDATORS, cls=ConfigJSONEncoder, indent=4)
for attr in ['CUSTOM_VALIDATORS', 'PROTECTION_RULES']:
if hasattr(config, attr) and getattr(config, attr, None):
setattr(config, attr, json.dumps(getattr(config, attr), cls=ConfigJSONEncoder, indent=4))

return render(request, 'core/system.html', {
'stats': stats,
Expand Down
2 changes: 1 addition & 1 deletion netbox/templates/core/inc/config_data.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<tr>
<th scope="row" class="border-0 ps-3">{% trans "Protection rules" %}</th>
{% if config.PROTECTION_RULES %}
<td class="border-0"><pre>{{ config.PROTECTION_RULES|json }}</pre></td>
<td class="border-0"><pre>{{ config.PROTECTION_RULES }}</pre></td>
{% else %}
<td class="border-0">{{ ''|placeholder }}</td>
{% endif %}
Expand Down

0 comments on commit 39cd8bc

Please sign in to comment.