mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
Fix: always update document modified property on bulk edit operations (#7079)
This commit is contained in:
parent
6ed5d11758
commit
6defe24ae7
@ -418,7 +418,10 @@ def update_filename_and_move_files(sender, instance: Document, **kwargs):
|
|||||||
move_archive = False
|
move_archive = False
|
||||||
|
|
||||||
if not move_original and not move_archive:
|
if not move_original and not move_archive:
|
||||||
# Don't do anything if filenames did not change.
|
# Just update modified. Also, don't save() here to prevent infinite recursion.
|
||||||
|
Document.objects.filter(pk=instance.pk).update(
|
||||||
|
modified=timezone.now(),
|
||||||
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
if move_original:
|
if move_original:
|
||||||
|
@ -573,7 +573,19 @@ class TestFileHandling(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
|||||||
|
|
||||||
@override_settings(FILENAME_FORMAT="{title}")
|
@override_settings(FILENAME_FORMAT="{title}")
|
||||||
@mock.patch("documents.signals.handlers.Document.objects.filter")
|
@mock.patch("documents.signals.handlers.Document.objects.filter")
|
||||||
def test_no_update_without_change(self, m):
|
@mock.patch("documents.signals.handlers.shutil.move")
|
||||||
|
def test_no_move_only_save(self, mock_move, mock_filter):
|
||||||
|
"""
|
||||||
|
GIVEN:
|
||||||
|
- A document with a filename
|
||||||
|
- The document is saved
|
||||||
|
- The filename is not changed
|
||||||
|
WHEN:
|
||||||
|
- The document is saved
|
||||||
|
THEN:
|
||||||
|
- The document modified date is updated
|
||||||
|
- The document is not moved
|
||||||
|
"""
|
||||||
with disable_auditlog():
|
with disable_auditlog():
|
||||||
doc = Document.objects.create(
|
doc = Document.objects.create(
|
||||||
title="document",
|
title="document",
|
||||||
@ -583,12 +595,16 @@ class TestFileHandling(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
|||||||
archive_checksum="B",
|
archive_checksum="B",
|
||||||
mime_type="application/pdf",
|
mime_type="application/pdf",
|
||||||
)
|
)
|
||||||
|
original_modified = doc.modified
|
||||||
Path(doc.source_path).touch()
|
Path(doc.source_path).touch()
|
||||||
Path(doc.archive_path).touch()
|
Path(doc.archive_path).touch()
|
||||||
|
|
||||||
doc.save()
|
doc.save()
|
||||||
|
doc.refresh_from_db()
|
||||||
|
|
||||||
m.assert_not_called()
|
mock_filter.assert_called()
|
||||||
|
self.assertNotEqual(original_modified, doc.modified)
|
||||||
|
mock_move.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
class TestFileHandlingWithArchive(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
class TestFileHandlingWithArchive(DirectoriesMixin, FileSystemAssertsMixin, TestCase):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user