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

Configure actions in auditlog.register #682

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

CleitonDeLima
Copy link
Contributor

Resolve #424

Copy link

codecov bot commented Oct 28, 2024

Codecov Report

Attention: Patch coverage is 95.23810% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.49%. Comparing base (5289482) to head (910f1bf).
Report is 26 commits behind head on master.

Files with missing lines Patch % Lines
auditlog/registry.py 95.23% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #682      +/-   ##
==========================================
+ Coverage   95.21%   95.49%   +0.27%     
==========================================
  Files          31       32       +1     
  Lines        1025     1088      +63     
==========================================
+ Hits          976     1039      +63     
  Misses         49       49              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hramezani
Copy link
Member

Thanks @CleitonDeLima for this PR.

I think this PR will introduce a breaking change. the AuditlogModelRegistry class is exposed and this PR will change the class constructor signature.

In the current implementation, we can have multiple instances of AuditlogModelRegistry with different create, update, delete, .. configs.

from auditlog.registry import AuditlogModelRegistry, auditlog

auditlog.register(MyModel)  # registers model with all actions

custom_auditlog = AuditlogModelRegistry(delete=False, access=False)
custom_auditlog.register(MyOtherModel)

This will not be possible by your change and some people's code might depend on this.

Also, by moving the adding to _signals to def register, by registering a model this will change for all other models as well which is wrong.

from auditlog.registry import  auditlog

auditlog.register(MyModel)  # registers model with all actions

# This will change the signals in `_signals` for the whole instance and will change the log behavior for all registered model
custom_auditlog.register(MyOtherModel, actions={'DELETE': False})

I think the action can be added to def register but it shouldn't change the whole auditlog behavior.
I would suggest handling the override actions in _connect_signals method.

Please remember to add more tests and change the documentation if you want to continue.

@CleitonDeLima
Copy link
Contributor Author

Hi @hramezani, thanks for reviewing

In the current implementation, we can have multiple instances of AuditlogModelRegistry with different create, update, delete, .. configs.

Is it possible to have multiple instances? It seems to me that the application currently does not support this. The auditlog instance is used elsewhere. This problem is described here #617.

Also, by moving the adding to _signals to def register, by registering a model this will change for all other models as well which is wrong.

This really is weird, I'll think of an alternative.

Please remember to add more tests and change the documentation if you want to continue.

I'll see how it works to change the documentation for this, it's a new world for me 😄.

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

Successfully merging this pull request may close these issues.

Enable/disable logging actions (Create, Update, Delete) on specific Models
2 participants