Skip to content

Commit

Permalink
Merge pull request #2761 from lunkwill42/bugfix/auditlog-netbox-change
Browse files Browse the repository at this point in the history
Fix SeedDB edit netbox regression
  • Loading branch information
lunkwill42 authored Nov 24, 2023
2 parents 4785f07 + 365d268 commit fbf4cfd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 0 additions & 4 deletions python/nav/web/seeddb/page/netbox/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,16 @@ def log_netbox_change(account, old, new):

# Compare changes from old to new
attribute_list = [
'read_only',
'read_write',
'category',
'ip',
'room',
'organization',
'snmp_version',
]
LogEntry.compare_objects(
account,
old,
new,
attribute_list,
censored_attributes=['read_only', 'read_write'],
)


Expand Down
14 changes: 12 additions & 2 deletions tests/integration/seeddb_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
from mock import MagicMock

from nav.models.manage import Netbox, Room
from nav.models.profiles import Account, AlertProfile
from nav.web.seeddb.page.netbox.edit import netbox_edit
from nav.web.seeddb.page.netbox.edit import netbox_edit, log_netbox_change
from nav.web.seeddb.utils.delete import dependencies

import pytest
Expand Down Expand Up @@ -58,3 +57,14 @@ def test_dependencies_no_whitelist(netbox):
deps = dependencies(qs, [])
assert Netbox.objects.get(pk=netbox.pk)
assert deps == {}


def test_log_netbox_change_should_not_crash(admin_account, netbox):
"""Regression test to ensure this function doesn't try to access removed or
invalid attributes on Netbox.
"""
old = Netbox.objects.get(id=netbox.id)
new = netbox
new.category_id = "OTHER"

assert log_netbox_change(admin_account, old, new) is None

0 comments on commit fbf4cfd

Please sign in to comment.