Commit graph

51 commits

Author SHA1 Message Date
mostafaeftekharizadeh
7d13fd4ba8
Add CustomLogEntry model support and update tests: (#764)
* Add CustomLogEntry model support and update tests:

- Added support for CustomLogEntry data model to extend django-auditlog capabilities

- Updated existing test cases to align with new model structure and data handling logic

- Added new test cases to validate CustomLogEntry behavior, model registration, and signal handling

- Ensured backward compatibility with existing LogEntry model where applicable

* Update auditlog/__init__.py

Co-authored-by: Youngkwang Yang <me@youngkwang.dev>

* run only one custom model test matrix (#761)

---------

Co-authored-by: Youngkwang Yang <me@youngkwang.dev>
2025-11-19 09:46:43 +01:00
David Thompson
b1b6f9f4dd
Add base manager setting to override default manager use (#747) (#766)
* Add `AUDITLOG_USE_BASE_MANAGER` setting configuration
* Adjust `LogEntry._get_changes_display_for_fk_field` behaviour for setting
* Adjust `log_update` and `log_m2m_changes` in `receivers.py` for setting
* Add `ModelManagerTest.test_use_base_manager_setting`
* Add entry in Usage documentation
* (In passing, fix a formatting issue in `usage.rst`)

The `AUDITLOG_USE_BASE_MANAGER` setting has a default of `False` to maintain
initial backwards compatibility with previous versions.
2025-10-18 13:55:43 +02:00
Youngkwang Yang
d417f30142
Drop 'Python 3.9' support (#773)
* Drop Python 3.9 support, set minimum version to 3.10

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

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

* Update CHANGELOG.md

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

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

* Fix lint error

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-10-17 17:51:53 +02:00
The Alchemist
d4d9f287a6
added fixes for changes_display_dict when AUDITLOG_STORE_JSON_CHANGES is True (#738) 2025-07-22 23:19:40 +02:00
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
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
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
hamsh
602c760b4c
add actor email (#641) 2025-01-30 18:33:51 +03:30
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
Hasan Ramezani
a53a6facfe
Drop Python 3.8 support (#678) 2024-10-17 18:40:21 +02: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
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
Pascal Mathis
e6fc81016c
fix: avoid exception in changes_display_dict when model is missing (#609) 2024-02-13 20:05:27 +01:00
Aleh Rymašeŭski
dbb50e462c
Handle ObjectDoesNotExist in evaluation of repr (#592) 2023-12-11 22:15:34 +03:00
Aleh Rymašeŭski
ac737fd55c
Stop deleting log entries in log_create (#559) 2023-09-11 16:16:37 +02:00
Aleh Rymašeŭski
fb1ae7abed
Set history delete_related to False by default (#557)
This is a breaking change. The default behavior is to delete the
related objects, but it doesn't make sense to apply it to audit log
entries, at least not by default.
2023-08-24 17:25:56 +02:00
Abdullah Alaqeel
134ef73723
feat: give users the option to run the json migration asyncly (#495) 2023-08-13 11:38: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
Joey Lange
98fe8d4173
Make M2M changes comply with JSONField properly (#514) 2023-02-15 15:10:27 +01:00
Hasan Ramezani
3a90087d32
Add null=True to ci field (#506)
* Add null=True to ci field

* [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>
2023-02-03 16:33:20 +03: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
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
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
August Raack
777bd537e7
Add serialized object field (#412) 2022-08-21 21:45:50 +02:00
Alieh Rymašeŭski
2ac014baa5 Remove a redundant exception handler
It duplicates the handler for its parent class Exception.
2022-06-28 19:20:02 +02:00
Alieh Rymašeŭski
68c7f44f9c Make checks for empty collections more pythonic 2022-06-28 19:20:02 +02:00
Hasan Ramezani
7771075dc0 Remove South compatibility codes 2022-06-28 19:19:09 +02:00
Viktor
d928ff7f77 Return default value None if attribute choices doesn't exist
Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
2022-06-27 09:08:19 +02:00
Hasan Ramezani
11dceb81b8
Add flake8 to pre-commit config (#387) 2022-06-18 20:50:25 +04:30
Alieh Rymašeŭski
10c47181bb
Add logic to track changes to m2m fields (#309) 2022-06-08 17:09:27 +02:00
George Leslie-Waksman
1e7d320a93
Add an index to the timestamp column (#364)
Many queries, including the default ordering, for the LogEntry
model rely on the timestamp field. Adding an index will ensure
reasonable scalability for large audit logs.
2022-05-31 09:01:13 +02:00
Hasan Ramezani
de0625b378 Drop Django 2.2 support. 2022-05-01 13:48:26 +02:00
Samuel Gonçalves
77ef852706
enable use of replica database (#359)
* enable use of replica database

When you use replica database the django-auditlog try to write in the same database where object was read (replica). But this is a read only database and crash the application.

This changes saves always in the default database.

If you want to save in multiple databases or in a special one use `DATABASE_ROUTERS` to configure it.

Co-authored-by: Hasan Ramezani <hasan.r67@gmail.com>
2022-03-07 14:22:08 +01:00
Hasan Ramezani
f003f3332a Update syntax to Python 3.7+ 2022-01-10 10:18:20 +01:00
François Magimel
2e9668dc05
build: replace django-jsonfield with django-jsonfield-backport (#339)
The `django-jsonfield` module is not maintained anymore and raises some
errors with Django 4.0. So, as a recommendation in this package, and as
Django 2.2 is still maintained, `django-jsonfield-backport` will do the
job for the `JSONField` field.

Ref #43
Ref #334
2022-01-07 22:14:36 +01:00
Basti
05c280575f replace ugettext with gettext for django4 2022-01-07 08:36:23 +01:00
Andreas Hasenkopf
938431389f
Add a DB index to LogEntry's action field (#236)
For some applications the possibility to filter by the `action` field might be really interesting. However the lack of an index can lead to severe reduction of such queries.

The simplest solution: Let's a DB index on that field :)
2022-01-04 10:06:45 +01:00
Hasan Ramezani
497c83fc83 Add isort and sort orders with isort. 2020-12-06 23:10:18 +01:00
Hasan Ramezani
f5bb5cb1a2 Add black and format files with black. 2020-12-06 23:10:18 +01:00
Jan-Jelle Kester
2010b49d06 Fix Django 3.0 field choices diff 2020-09-07 16:52:32 +02:00
Jan-Jelle Kester
3acab4322b Drop Python 2, support Django 3.0, update dependencies 2020-09-07 16:52:32 +02:00
Jan-Jelle Kester
ee8a700b1b Clean up project structure 2020-09-07 16:52:32 +02:00
Jan-Jelle Kester
81098cd179 Big commit: testproject, bugfixes, changed directory structure 2013-10-21 21:46:31 +02:00
Jan-Jelle Kester
db8529b773 Make LogEntry and middleware compatible with custom user models 2013-10-20 19:24:33 +02:00