]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix: Make customfieldinstance soft delete, fix filepath when deleted (#8067)
authorshamoon <4887959+shamoon@users.noreply.github.com>
Mon, 28 Oct 2024 14:02:09 +0000 (07:02 -0700)
committerGitHub <noreply@github.com>
Mon, 28 Oct 2024 14:02:09 +0000 (14:02 +0000)
src/documents/migrations/1056_customfieldinstance_deleted_at_and_more.py [new file with mode: 0644]
src/documents/models.py
src/documents/serialisers.py
src/documents/templating/filepath.py

diff --git a/src/documents/migrations/1056_customfieldinstance_deleted_at_and_more.py b/src/documents/migrations/1056_customfieldinstance_deleted_at_and_more.py
new file mode 100644 (file)
index 0000000..eba1e42
--- /dev/null
@@ -0,0 +1,58 @@
+# Generated by Django 5.1.2 on 2024-10-28 01:55
+
+from django.db import migrations
+from django.db import models
+
+
+class Migration(migrations.Migration):
+    dependencies = [
+        ("documents", "1055_alter_storagepath_path"),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name="customfieldinstance",
+            name="deleted_at",
+            field=models.DateTimeField(blank=True, null=True),
+        ),
+        migrations.AddField(
+            model_name="customfieldinstance",
+            name="restored_at",
+            field=models.DateTimeField(blank=True, null=True),
+        ),
+        migrations.AddField(
+            model_name="customfieldinstance",
+            name="transaction_id",
+            field=models.UUIDField(blank=True, null=True),
+        ),
+        migrations.AddField(
+            model_name="note",
+            name="deleted_at",
+            field=models.DateTimeField(blank=True, null=True),
+        ),
+        migrations.AddField(
+            model_name="note",
+            name="restored_at",
+            field=models.DateTimeField(blank=True, null=True),
+        ),
+        migrations.AddField(
+            model_name="note",
+            name="transaction_id",
+            field=models.UUIDField(blank=True, null=True),
+        ),
+        migrations.AddField(
+            model_name="sharelink",
+            name="deleted_at",
+            field=models.DateTimeField(blank=True, null=True),
+        ),
+        migrations.AddField(
+            model_name="sharelink",
+            name="restored_at",
+            field=models.DateTimeField(blank=True, null=True),
+        ),
+        migrations.AddField(
+            model_name="sharelink",
+            name="transaction_id",
+            field=models.UUIDField(blank=True, null=True),
+        ),
+    ]
index 37c86305c69ea58eadeb21f2c9a6e5f810ea4e85..4528d51279a4723d31928658ed7ce6aa03f90bb7 100644 (file)
@@ -710,7 +710,7 @@ class PaperlessTask(models.Model):
         return f"Task {self.task_id}"
 
 
-class Note(models.Model):
+class Note(SoftDeleteModel):
     note = models.TextField(
         _("content"),
         blank=True,
@@ -750,7 +750,7 @@ class Note(models.Model):
         return self.note
 
 
-class ShareLink(models.Model):
+class ShareLink(SoftDeleteModel):
     class FileVersion(models.TextChoices):
         ARCHIVE = ("archive", _("Archive"))
         ORIGINAL = ("original", _("Original"))
@@ -866,7 +866,7 @@ class CustomField(models.Model):
         return f"{self.name} : {self.data_type}"
 
 
-class CustomFieldInstance(models.Model):
+class CustomFieldInstance(SoftDeleteModel):
     """
     A single instance of a field, attached to a CustomField for the name and type
     and attached to a single Document to be metadata for it
index 6f7dc8be094adde6d4d660b3d7cd17df97696a55..e08daff09db4810b4c8e99f74f9c6dad2ff5adf8 100644 (file)
@@ -855,6 +855,8 @@ class DocumentSerializer(
                 super().update(instance, validated_data)
         else:
             super().update(instance, validated_data)
+        # hard delete custom field instances that were soft deleted
+        CustomFieldInstance.deleted_objects.filter(document=instance).delete()
         return instance
 
     def __init__(self, *args, **kwargs):
index afb43ff4d1c73e6f6da8e6e64d8a7fd11e2595f7..108ad0c814a54df7725cf24b49adc25e9949ff9e 100644 (file)
@@ -296,7 +296,7 @@ def validate_filepath_template_and_render(
     else:
         # or use the real document information
         tags_list = document.tags.order_by("name").all()
-        custom_fields = document.custom_fields.all()
+        custom_fields = CustomFieldInstance.global_objects.filter(document=document)
 
     # Build the context dictionary
     context = (