Commit graph

77 commits

Author SHA1 Message Date
Youngkwang Yang
af78976e53
Add support for custom masking functions (#725)
* Add test cases for the `mask_str` function

* Add custom masking function support through mask_callable

* Add test cases for custom masking function

* Update documentation for custom masking function

* fix test case

* rename `AUDITLOG_DEFAULT_MASK_CALLABLE` variable

-AUDITLOG_DEFAULT_MASK_CALLABLE to `AUDITLOG_MASK_CALLABLE`

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update `CHANGELOG.md` to include mask function customization feature

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-06-09 16:59:59 +03:30
Youngkwang Yang
3a58e0a999
Fix get_field_value field default value handling for Django 6.0 compatibility (#726)
* 'get_field_value' - improve default value handling

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add Test cases

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-06-09 16:30:28 +03:30
sebastianmanger
6414b7aedb
Let CI also check for missing migrations (#706)
* Refactor: re-arrange test application

This was triggered by the need to run "python manage.py", which is impossible when serving the whole project in the same directory as is configured in INSTALLED_APPS ("auditlog_tests"). This setup is heavily inspired by other jazzband projects.

* Add check for missing migrations
2025-03-19 19:58:43 +03:30
Jakub Ječmínek
4c1d573981
Fix IntegrityError when cloning objects with pk=None (#664) (#707)
* Fix IntegrityError when cloning objects with pk=None

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-03-19 17:24:03 +03:30
sebastianmanger
939dd9b298
Use recommended manager (#705)
See https://docs.djangoproject.com/en/5.1/topics/db/managers/#default-managers
2025-03-11 18:02:52 +03:30
Amirreza Ashouri
c4907bcd52
Add ability to globally mask fields by name on all models. (#702)
* Add ability to globally mask fields by name on all models.

Fixes https://github.com/jazzband/django-auditlog/issues/701

* Add feature explanation in `usage.rst` file.

* Add a record to CHANGELOG.md file.

* Add test coverage.
2025-02-24 12:05:04 +03:30
hamsh
602c760b4c
add actor email (#641) 2025-01-30 18:33:51 +03:30
Christopher Charbonneau Wells
5621777622
fix: use sender for m2m signal dispatch connection (#686)
* fix: use sender for m2m signal dispatch connection

This fix adds support for a use case where a single m2m through model is
used on multiple models. When the reciever is used for the dispatch uid
in this use case it cause duplicated logs because the through model
singal connection happens multiple times.

By changing the m2m signal connection to use the sender for the dispatch
uid this duplication is prevented because the signal connection only
happens once for the through model.

Refs: #685

* fix(format): apply black formatting

* add test and changelog entry

* remove unused import

* correct import sorting

* move change log message to correct section
2024-11-12 16:35:06 +01:00
Hoàng Quốc Hưng
d4f99c2729
Add AUDITLOG_TRUNCATE_CHANGES_DISPLAY and AUDITLOG_TRUNCATE_LIMIT (#684)
* Add AUDITLOG_TRUNCATE_CHANGES_DISPLAY and AUDITLOG_TRUNCATE_LIMIT

To configure how many characters will be truncated or disable it

* Add AUDITLOG_CHANGE_DISPLAY_TRUNCATE_LENGTH settings

to keep or truncate strings of `changes_display_dict` property at a variable length
2024-11-04 14:39:25 +01:00
Cleiton de Lima
4c3ee0b36d
Added remote port (#671) 2024-10-07 15:52:34 +02:00
evanandrews-xrd
2c0bd0fac6
Use attname to get pk value (#650)
* Use `attname` to get pk value

* Add tests for model as primary key

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add clarifying comments to _get_pk_value

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-06-11 14:30:28 +03:30
Hasan Ramezani
8af8011073
Fixed a problem when setting Value(None) in JSONField (#646) 2024-05-27 12:58:58 +03:30
Hasan Ramezani
a652eebfaf
Fixed problem when setting django.db.models.functions.Now() in DateTimeField (#635) 2024-04-29 23:38:09 +02:00
Hasan Ramezani
7b035943c7
Fixed manuall logging when model is not registered (#627)
* Fixed manuall logging when model is not registered

* Move change log
2024-04-12 10:14:42 +02:00
nathan
a93d9ef665
Fix serialize __proxy__ objects before logging (#624)
* Fix serialize __proxy__ objects before logging

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update CHANGELOG.md

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
2024-04-08 12:06:36 +02:00
nathan
a0ae594425
Disable logging remote IP address (#620)
* Disable logging remote IP address

* Update auditlog/middleware.py

* Update CHANGELOG.md

* Update auditlog/middleware.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update auditlog/middleware.py and add tests in ManyRelatedModelTest

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-03-31 01:37:39 +01:00
Pascal Mathis
e6fc81016c
fix: avoid exception in changes_display_dict when model is missing (#609) 2024-02-13 20:05:27 +01:00
Pascal Mathis
f3238c9bdb
feat: include LogEntry instance in post_log signal (#605) 2024-02-08 21:55:46 +01:00
Aleh Rymašeŭski
dbb50e462c
Handle ObjectDoesNotExist in evaluation of repr (#592) 2023-12-11 22:15:34 +03:00
errrken
140719eeb5
Conditionally disable / enable logging (#590)
* Update receivers.py

* Update signals.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update signals.py

Removed trailing whitespace...

* Update tests.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update CHANGELOG.md

* Update CHANGELOG.md

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
2023-12-07 20:45:41 +03:00
Aleh Rymašeŭski
c52786855b
Allow cascade deletion of auditlog entries (#556)
* Allow cascade deletion of auditlog entries

* Cache iteration over self.urls
2023-08-27 11:12:39 +02:00
Abdullah Alaqeel
f2591e420b
feat: collect all models including auto created ones and excluding non-managed ones (#550)
feat: automatically register m2m fields for models when opting to auto register models
2023-08-09 17:11:21 +02:00
Hasan Ramezani
9bcc511e21
Fix a bug in serialized_data with F expressions (#544) 2023-07-13 08:53:47 +02:00
Fırat Kılıç
7f2a3e395d
Fix unnecessary log when adding already existed m2m record (#535) 2023-06-21 17:55:29 +03:30
Rustam Astafeev
0d9fb8d6fc
fixed getting field's verbose_name (#508)
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
2023-05-18 01:59:11 +03:30
Darren Maki
cd0d3ea311
Audit changes to FK fields when saved using *_id naming. (#525)
* Audit changes to FK fields when saved using *_id naming.

In Django you can save changes to a FK field on a model using the ID
field name (attname) in addition to the regular FK field name with:

    model.related_model_id = 42
    model.save(update_fields=["related_model_id'])

or:

    model.related_model = related_model
    model.save(update_fields=["related_model_id'])

as opposed to the more common:

    model.related_model = related_model
    model.save(update_fields=["related_model'])

This change ensures those model changes are logged properly.

* Apply suggested change from code review.

* Add a CHANGELOG entry for the fix.
2023-05-08 18:56:01 +03:30
Joey Lange
98fe8d4173
Make M2M changes comply with JSONField properly (#514) 2023-02-15 15:10:27 +01:00
Hasan Ramezani
fcb6c4ce27
Fix a bug in audit log admin page when USE_TZ=False (#511)
Co-authored-by: Ebrahimi <z.ebrahimi.d80@gmail.com>
2023-02-10 17:52:07 +03:00
Aaron C. de Bruyn
06ae048378
Add ability to globally exclude fields by name on all models (#498)
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
2023-01-20 15:41:36 +01:00
Abdullah Alaqeel
f6b9e9f931
Always call set_actor (#484) 2023-01-04 15:05:32 +01:00
Thomas Steen Rasmussen
b9a86df456
raise AuditLogRegistrationError on invalid app in settings (#492)
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
2023-01-03 16:03:37 +01:00
Cleiton de Lima
ffa6d34b11
Fix repr of a json field in field changes (#489) 2022-12-30 08:28:55 +01:00
Aivars Kalvāns
7f8edd5456
Convert AUDITLOG_EXCLUDE_TRACKING_MODELS to tuple before concatenate (#488) 2022-12-29 09:09:56 +01:00
August Raack
c649629225
Change diff to evaluate PKs for FK relationships (#420)
* Change diff to evaluate PKs for FK relationships

The diff method now evaluates the primary keys for changes to determine
if a new LogEntry should be created. Previously, the diff method was
evaluating the string representation of the object. This was flawed
because cases can occur when a parent object has in memory changes to
its string string representation and the child related object is saved
prior to these in memory changes being persisted. In these cases a new
LogEntry object would be created erroneously. This cases is asserted
with a test and a regression test will verify the bug.

The consequence of these updates is that the ``LogEntry.changes`` field
now stores primary keys rather than string representations for related
objects. To keep the changes dictionary display unaffected by this
update, a method was added to the ``LogEntry`` model. This method looks
up the object display string from the stored foreign key. Exceptions
were written to handle backwards compatibility.

* Added test case to cover another bug

Because the string representation is not unique for every object, relying
on it to determine FK diffs may not capture all changes. This test case
shows another type of scenario that is fixed by comparing primary keys
rather than object string representations. This is likely occurring
fairly regularly but is hard to spot because it is an error of omission.

* Update to docstring and added changelog
2022-12-28 09:51:44 +01:00
August Raack
2a7fc23b29
Modify `change` field to be a json field. (#407)
* Modify ``change`` field to be a json field.

Storing the object changes as a json is preferred because it allows SQL
queries to access the change values. This work moves the burden of
handling json objects from an implementation of python's json library in
this package and puts it instead onto the ORM. Ultimately, having the
text field store the changes was leaving them less accessible to external
systems and code that is written outside the scope of the django
auditlog.

This change was accomplished by updating the field type on the model and
then removing the JSON dumps invocations on write and JSON loads
invocations on read. Test were updated to assert equality of
dictionaries rather than equality of JSON parsable text.

Separately, it was asserted that postgres will make these changes to
existing data. Therefore, existing postgres installations should update the
type of existing field values without issue.

* Add test coverage for messages exceeding char len

The "Modify change field to be a json field" commit reduced test
coverage on the mixins.py file by 0.03%. The reduction in coverage was
the result of reducing the number of operations required to achieve the
desired state. An additional test was added to increase previously
uncovered code. The net effect is an increase in test case coverage.

* Add line to changelog

Better markdown formatting

Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>

* Update CHANGELOG text format

More specific language in the improvement section regarding `LogEntry.change`

Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>

* Update migration to show Django version 4.0

Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>

* Update CHANGELOG to show breaking change

Running the migration to update the field type of `LogEntry.change` is a breaking change.

Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>

* Update serial order of migrations

* Adjust manager method for compatibility

The create log method on the LogEntry manager required an additional
kwarg for a call to create an instance regardless of a change or not.
This felt brittle anyway. The reason it had worked prior to these
changes was that the `change` kwarg was sending a string "null" and
not a None when there were no changes.

Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
2022-12-28 09:50:35 +01:00
Abdullah Alaqeel
c65c38e539
Adding Custom Pre- and Post- Log Hooks (#483) 2022-12-27 20:14:51 +01:00
Abdullah Alaqeel
bc6d393390
Added support for Correlation ID
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
2022-12-23 15:09:32 +01:00
Abdullah Alaqeel
a733cd0852
feat: Make timestamp in LogEntry overwritable (#478) 2022-12-19 08:43:29 +01:00
Thomas Steen Rasmussen
27f57a53ff
Fix LogEntry.changes_dict() to return {} when json.loads() returns None (#472)
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
2022-12-13 21:35:31 +01:00
Abdullah Alaqeel
4cdc756791
FIX: Parsing client IPv6 address when a proxy is involved (#457) 2022-11-22 08:44:59 +01:00
Alieh Rymašeŭski
1ba3bd9d07
Disallow changing or deleting log entries (#449) 2022-11-21 16:26:23 +01:00
Hasan Ramezani
2b0bc9efa2
Replace the django.utils.timezone.utc by datetime.timezone.utc (#448)
Co-authored-by: Alieh Rymašeŭski <alieh.rymasheuski@gmail.com>
2022-11-07 14:26:51 +01:00
Simon Kern
f71699a9d0
Added ACCESS action and enabled logging of object accesses (#436) 2022-11-07 08:51:00 +01:00
Robin Harms Oredsson
8fe776ae45
Option to disable logging on raw save and via context manager (#446)
* Disable on raw save prototype
* Contextmanager to disable instead of just raw - so we can catch m2m relations too
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
2022-11-04 09:12:06 +01:00
Youngkwang Yang
487b8ab5f4
Remove unnecessary code in created method. (#438) 2022-10-05 18:39:48 +02:00
Rahul Prasad
a56d0e6f78
added fix for OneToOneRel error happening in case of Polymorphic model (#429) 2022-09-21 08:53:10 +02:00
Mathieu Rampant
d74c118834
Added verbose field name in admin (#428)
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
2022-09-20 22:07:41 +02:00
August Raack
777bd537e7
Add serialized object field (#412) 2022-08-21 21:45:50 +02:00
Hasan Ramezani
18868aaaed Handle port in remote_addr 2022-08-17 13:37:22 +02:00
Alieh Rymašeŭski
a24b79af0c
Display timestamps in server timezone (#404) 2022-08-01 20:41:41 +02:00