Convert UserAction logging to use signals #905

Closed
opened 2025-12-29 16:26:51 +01:00 by adam · 6 comments
Owner

Originally created by @jeremystretch on GitHub (May 2, 2017).

NetBox records use activity as UserAction objects. Currently, these are created explicitly inside views. In order to standardize their creation and integrate with the new API, we NetBox should utilize Django's signals to control the creation of UserActions.

Originally created by @jeremystretch on GitHub (May 2, 2017). NetBox records use activity as UserAction objects. Currently, these are created explicitly inside views. In order to standardize their creation and integrate with the new API, we NetBox should utilize [Django's signals](https://docs.djangoproject.com/en/1.11/topics/signals/) to control the creation of UserActions.
adam added the status: acceptedtype: feature labels 2025-12-29 16:26:51 +01:00
adam closed this issue 2025-12-29 16:26:51 +01:00
Author
Owner

@lampwins commented on GitHub (May 2, 2017):

I like this approach a lot. It will tie nicely into #81.

@lampwins commented on GitHub (May 2, 2017): I like this approach a lot. It will tie nicely into #81.
Author
Owner

@jeremystretch commented on GitHub (May 3, 2017):

This should solve #403

@jeremystretch commented on GitHub (May 3, 2017): This should solve #403
Author
Owner

@jeremystretch commented on GitHub (May 3, 2017):

Actually, I'm not sure this is feasible. Django's post_save and post_delete signals unfortunately don't pass the request context, so we have no way of determining the user responsible for an action (which we need to record in the UserAction). We might just have to keep handling this in the views.

@jeremystretch commented on GitHub (May 3, 2017): Actually, I'm not sure this is feasible. Django's `post_save` and `post_delete` signals unfortunately don't pass the request context, so we have no way of determining the user responsible for an action (which we need to record in the UserAction). We might just have to keep handling this in the views.
Author
Owner

@lampwins commented on GitHub (Aug 8, 2017):

Could we not create our own signals to handle this? I agree, it would be more elegant if post_save and post_delete were feasible, but I think there is still a way to do this and set it up for future extension via #81

@lampwins commented on GitHub (Aug 8, 2017): Could we not create our own signals to handle this? I agree, it would be more elegant if `post_save` and `post_delete` were feasible, but I think there is still a way to do this and set it up for future extension via #81
Author
Owner

@jeremystretch commented on GitHub (Dec 20, 2017):

The django-audit-log project has a really clever way of handling this. It uses process_request in middleware to create a curried function which has been passed request data (the user) and connect it to the pre_save signal.

@jeremystretch commented on GitHub (Dec 20, 2017): The [django-audit-log](https://github.com/Atomidata/django-audit-log/blob/master/audit_log/middleware.py#L26) project has a really clever way of handling this. It uses `process_request` in middleware to create a curried function which has been passed request data (the user) and connect it to the `pre_save` signal.
Author
Owner

@jeremystretch commented on GitHub (Feb 20, 2018):

Folding this into #1898

@jeremystretch commented on GitHub (Feb 20, 2018): Folding this into #1898
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#905