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

Question: Stop Log Creation for Specific User in Django Auditlog #656

Open
Algos70 opened this issue Jul 17, 2024 · 5 comments
Open

Question: Stop Log Creation for Specific User in Django Auditlog #656

Algos70 opened this issue Jul 17, 2024 · 5 comments

Comments

@Algos70
Copy link

Algos70 commented Jul 17, 2024

I would like to prevent the creation of logs for a specific user when they perform actions in our Django application. Specifically, I want to exclude the user with the username 'system' from generating audit log entries. Is there any way to do this in this version? I found the issue #590 but couldn't figure out how to use recievers to do this.

@hramezani
Copy link
Member

You can use pre_log signal and return False

@Algos70
Copy link
Author

Algos70 commented Jul 17, 2024

You can use pre_log signal and return False

I tried it but it seems like I couldn't access the user field's value that we see in the django-admin page's audit log tab.
Here, this is the user field I am trying to access:
image

@hramezani
Copy link
Member

I tried it but it seems like I couldn't access the user field's value that we see in the django-admin page's audit log tab.
Here, this is the user field I am trying to access:

Why do you need to access these fields? in pre_log you will receive sender and instance and you can prevent logging for some specific user by these two params

@Algos70
Copy link
Author

Algos70 commented Jul 17, 2024

In the system I'm working with, there's no indication from either the sender or the instance itself that distinguishes whether a change originates from a physical device or a user. The 'system' user, which I aim to exclude, represents a device deployed in the field. It periodically sends data to our app, which we store in the database. To streamline my admin page, I need a method to differentiate and exclude logs generated by this device from user-generated logs.

@hramezani
Copy link
Member

Right now, there is no config to prevent saving logs for a specific user. every log entry object has an actor field that contain the user that does the change. So, probably you need to somehow override the save method of LogEntry model to prevent logging there. because you have access to the actor by instance.actor there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants