Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log pre-existing object state when creating an ObjectChange instance #5913

Closed
jeremystretch opened this issue Mar 3, 2021 · 2 comments
Closed
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Milestone

Comments

@jeremystretch
Copy link
Member

Environment

  • Python version: 3.7.9
  • NetBox version: 2.10.5

Proposed Functionality

When creating a new ObjectChange instance to log a change to a NetBox object, capture its pre-change state as well as its current state. This may take a bit of cleverness to implement, but it should be possible by using a custom signal to register a pre-change copy of data on an instance immediately prior to modifying it.

Use Case

Storing both the pre- and post-change copies of an object allows us to present a more accurate depiction of that changes attributable to a specific action, and not worry about indirect changes not being accounted for. Related issues:

Database Changes

Add a field to the ObjectChange model for storing pre-change data.

External Dependencies

None expected

@jeremystretch jeremystretch added type: feature Introduction of new functionality to the application status: under review Further discussion is needed to determine this issue's scope and/or implementation status: accepted This issue has been accepted for implementation and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Mar 3, 2021
@jeremystretch jeremystretch self-assigned this Mar 3, 2021
@jeremystretch jeremystretch added this to the v2.11 milestone Mar 3, 2021
@jeremystretch
Copy link
Member Author

This is what I've come up with so far: The ObjectChange model has been extended to store both pre- and post-change data. When a request is processed, the responsible view calls snapshot() on the object being modified or deleted, which saves a serialized representation of the object on the object itself generated by the serialize_object() utility. After the change has been made, serialize_object() is called on the object once more to catch the post-change data. Both of these serialized representations are then stored in the new ObjectChange instance.

Screenshot_2021-03-03 dcim site Site X updated by admin - NetBox

I'd like to add some GitHub-style diff highlighting to the UI, but the important bits are all there. I also still need to write changelog tests for bulk edit and delete views.

jeremystretch added a commit that referenced this issue Mar 3, 2021
jeremystretch added a commit that referenced this issue Mar 4, 2021
* Initial work on #5913
* Provide per-line diff highlighting
* BulkDeteView should delete objects individually to secure a pre-change snapshot
* Add changelog tests for bulk operations
@jeremystretch
Copy link
Member Author

Now with diff highlighting!

Screenshot_2021-03-04 ipam prefix 192 0 2 0 24 updated by admin - NetBox

I expect we'll put a bit more polish on it in conjunction with the ongoing UI overhaul (#5893) prior to release.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

No branches or pull requests

1 participant