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

Add register model using Django settings #368

Merged
merged 12 commits into from
May 23, 2022

Conversation

2ykwang
Copy link
Member

@2ykwang 2ykwang commented Mar 27, 2022

This PR makes it easy to register model in the django-auditlog.

Setting variable

AUDITLOG_INCLUDE_ALL_MODELS
-> registers all models loaded from the django instance.

from django.apps import apps

apps.get_models()

e.g)

# The code below means to register all models.
AUDITLOG_INCLUDE_ALL_MODELS=True

AUDITLOG_INCLUDE_TRACKING_MODELS
-> assign models to register. this has the same behavior as audit log.register()

e.g)

AUDITLOG_INCLUDE_TRACKING_MODELS = (
    "<appname>.<model1>",
    {
        "model": "<appname>.<model1>",
        "include_fields": ["field1", "field2"],
        "exclude_fields": ["field3", "field4"],
        "mapping_fields": {
            "field1": "FIELD",
        },
        "mask_fields": ["field5", "field6"],
    },
    "<appname>.<model3>",
)

AUDITLOG_EXCLUDE_TRACKING_MODELS
-> assign models to exclude. this option is executed when AUDITLOG_INCLUDE_ALL_MODELS value is True.

e.g)

AUDITLOG_EXCLUDE_TRACKING_MODELS = (
    "<app_name>",
    "<app_name>.<model>"
)

@2ykwang 2ykwang requested review from jjkester and hramezani March 27, 2022 13:33
@2ykwang 2ykwang self-assigned this Mar 27, 2022
@codecov
Copy link

codecov bot commented Mar 27, 2022

Codecov Report

Merging #368 (3b1cec1) into master (a93f539) will increase coverage by 2.26%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #368      +/-   ##
==========================================
+ Coverage   83.39%   85.66%   +2.26%     
==========================================
  Files          20       21       +1     
  Lines         506      565      +59     
==========================================
+ Hits          422      484      +62     
+ Misses         84       81       -3     
Impacted Files Coverage Δ
auditlog/apps.py 100.00% <100.00%> (ø)
auditlog/conf.py 100.00% <100.00%> (ø)
auditlog/registry.py 98.18% <100.00%> (+6.80%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a93f539...3b1cec1. Read the comment docs.

@2ykwang 2ykwang force-pushed the registration-from-settings branch from 097cf56 to fb38f0c Compare March 27, 2022 15:09
@2ykwang 2ykwang requested review from Linkid, jezdez and 0417taehyun and removed request for 0417taehyun March 27, 2022 15:10
auditlog/registry.py Outdated Show resolved Hide resolved
@hramezani
Copy link
Member

Thanks @2ykwang for this patch. Please:

Linkid
Linkid previously requested changes May 9, 2022
Copy link
Contributor

@Linkid Linkid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add some tests with excluding fields, errors in new config vars and with a batch registration, please? Thanks

auditlog/registry.py Outdated Show resolved Hide resolved
auditlog/registry.py Outdated Show resolved Hide resolved
auditlog/registry.py Outdated Show resolved Hide resolved
@hramezani
Copy link
Member

@2ykwang Please add a changelog entry.

@2ykwang
Copy link
Member Author

2ykwang commented May 9, 2022

@hramezani Done!

@2ykwang 2ykwang requested review from hramezani and Linkid May 9, 2022 14:43
@hramezani
Copy link
Member

I think you forgot to add documentation

self.test_auditlog.unregister(model)

def test_auditlog_register_models(self):
with self.assertRaises(TypeError):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use assertRaisesMessage to check the error message as well

@hramezani
Copy link
Member

@hramezani Can you help me with the documentation? If you don't mind. my English is not so fluent.

Please provide the initial version of the documentation and then we can improve it with the help of @Linkid

@2ykwang 2ykwang requested a review from hramezani May 9, 2022 15:34
docs/source/usage.rst Outdated Show resolved Hide resolved
@2ykwang 2ykwang force-pushed the registration-from-settings branch from 68d8f11 to c4c471b Compare May 9, 2022 16:10
auditlog/registry.py Outdated Show resolved Hide resolved
@2ykwang 2ykwang requested a review from hramezani May 9, 2022 22:24
@2ykwang 2ykwang changed the title Add register model from settings Add register model using Django settings May 9, 2022
Comment on lines 209 to 210
include_all_models=False,
include_auto_created=False,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have these two args here? Do they need just to make the function easier to test?

auditlog/registry.py Outdated Show resolved Hide resolved
@hramezani
Copy link
Member

@2ykwang Could you please open my access to your fork, I am going to push some changes to your PR

@2ykwang
Copy link
Member Author

2ykwang commented May 10, 2022

@hramezani I just invited you. thank you!

@hramezani hramezani force-pushed the registration-from-settings branch from 18615bd to 8065a11 Compare May 10, 2022 07:58
@hramezani
Copy link
Member

@2ykwang I will work on this patch and will update it later when I have time.
Then we can merge this patch.
Thanks for your effort!

@hramezani hramezani force-pushed the registration-from-settings branch 5 times, most recently from 1802fa7 to cd74ffa Compare May 11, 2022 11:12
@hramezani hramezani force-pushed the registration-from-settings branch from 51f2be6 to 1c28d97 Compare May 11, 2022 11:15
@hramezani
Copy link
Member

@2ykwang I've refactored some parts of your patch. Please take look.

@hramezani
Copy link
Member

@Linkid It would be great if you have time for a review!

@2ykwang
Copy link
Member Author

2ykwang commented May 11, 2022

@hramezani
Thanks to you, the code looks much better. Thanks for the work 😄

@2ykwang 2ykwang removed request for jjkester and jezdez May 18, 2022 04:26
@hramezani hramezani merged commit 32694b1 into jazzband:master May 23, 2022
@hramezani hramezani deleted the registration-from-settings branch May 23, 2022 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants