mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-01-26 22:49:01 -06:00
Actually, doesnt even need to be a softdeletemodel
This commit is contained in:
@@ -154,18 +154,6 @@ class Migration(migrations.Migration):
|
|||||||
verbose_name="owner",
|
verbose_name="owner",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
(
|
|
||||||
"deleted_at",
|
|
||||||
models.DateTimeField(blank=True, null=True),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"restored_at",
|
|
||||||
models.DateTimeField(blank=True, null=True),
|
|
||||||
),
|
|
||||||
(
|
|
||||||
"transaction_id",
|
|
||||||
models.UUIDField(blank=True, null=True),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
options={
|
options={
|
||||||
"ordering": ("-created",),
|
"ordering": ("-created",),
|
||||||
|
|||||||
@@ -755,18 +755,13 @@ class ShareLink(SoftDeleteModel):
|
|||||||
return f"Share Link for {self.document.title}"
|
return f"Share Link for {self.document.title}"
|
||||||
|
|
||||||
|
|
||||||
class ShareLinkBundle(SoftDeleteModel):
|
class ShareLinkBundle(models.Model):
|
||||||
class Status(models.TextChoices):
|
class Status(models.TextChoices):
|
||||||
PENDING = ("pending", _("Pending"))
|
PENDING = ("pending", _("Pending"))
|
||||||
PROCESSING = ("processing", _("Processing"))
|
PROCESSING = ("processing", _("Processing"))
|
||||||
READY = ("ready", _("Ready"))
|
READY = ("ready", _("Ready"))
|
||||||
FAILED = ("failed", _("Failed"))
|
FAILED = ("failed", _("Failed"))
|
||||||
|
|
||||||
class Meta:
|
|
||||||
ordering = ("-created",)
|
|
||||||
verbose_name = _("share link bundle")
|
|
||||||
verbose_name_plural = _("share link bundles")
|
|
||||||
|
|
||||||
created = models.DateTimeField(
|
created = models.DateTimeField(
|
||||||
_("created"),
|
_("created"),
|
||||||
default=timezone.now,
|
default=timezone.now,
|
||||||
@@ -842,6 +837,11 @@ class ShareLinkBundle(SoftDeleteModel):
|
|||||||
verbose_name=_("documents"),
|
verbose_name=_("documents"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
ordering = ("-created",)
|
||||||
|
verbose_name = _("share link bundle")
|
||||||
|
verbose_name_plural = _("share link bundles")
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return _("Share link bundle %(slug)s") % {"slug": self.slug}
|
return _("Share link bundle %(slug)s") % {"slug": self.slug}
|
||||||
|
|
||||||
@@ -866,10 +866,6 @@ class ShareLinkBundle(SoftDeleteModel):
|
|||||||
self.remove_file()
|
self.remove_file()
|
||||||
return super().delete(using=using, keep_parents=keep_parents)
|
return super().delete(using=using, keep_parents=keep_parents)
|
||||||
|
|
||||||
def hard_delete(self, using=None, *, keep_parents=False):
|
|
||||||
self.remove_file()
|
|
||||||
return super().hard_delete(using=using, keep_parents=keep_parents)
|
|
||||||
|
|
||||||
|
|
||||||
class CustomField(models.Model):
|
class CustomField(models.Model):
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -736,7 +736,6 @@ def build_share_link_bundle(bundle_id: int):
|
|||||||
def cleanup_expired_share_link_bundles():
|
def cleanup_expired_share_link_bundles():
|
||||||
now = timezone.now()
|
now = timezone.now()
|
||||||
expired_qs = ShareLinkBundle.objects.filter(
|
expired_qs = ShareLinkBundle.objects.filter(
|
||||||
deleted_at__isnull=True,
|
|
||||||
expiration__isnull=False,
|
expiration__isnull=False,
|
||||||
expiration__lt=now,
|
expiration__lt=now,
|
||||||
)
|
)
|
||||||
@@ -744,7 +743,7 @@ def cleanup_expired_share_link_bundles():
|
|||||||
for bundle in expired_qs.iterator():
|
for bundle in expired_qs.iterator():
|
||||||
count += 1
|
count += 1
|
||||||
try:
|
try:
|
||||||
bundle.hard_delete()
|
bundle.delete()
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logger.warning(
|
logger.warning(
|
||||||
"Failed to delete expired share link bundle %s: %s",
|
"Failed to delete expired share link bundle %s: %s",
|
||||||
|
|||||||
@@ -278,7 +278,7 @@ class ShareLinkBundleTaskTests(DirectoriesMixin, APITestCase):
|
|||||||
|
|
||||||
with mock.patch.object(
|
with mock.patch.object(
|
||||||
ShareLinkBundle,
|
ShareLinkBundle,
|
||||||
"hard_delete",
|
"delete",
|
||||||
side_effect=RuntimeError("fail"),
|
side_effect=RuntimeError("fail"),
|
||||||
):
|
):
|
||||||
with self.assertLogs("paperless.tasks", level="WARNING") as logs:
|
with self.assertLogs("paperless.tasks", level="WARNING") as logs:
|
||||||
@@ -536,7 +536,7 @@ class ShareLinkBundleModelTests(DirectoriesMixin, APITestCase):
|
|||||||
|
|
||||||
self.assertTrue(bundle_path.exists())
|
self.assertTrue(bundle_path.exists())
|
||||||
|
|
||||||
def test_delete_and_hard_delete_call_remove_file(self):
|
def test_delete_calls_remove_file(self):
|
||||||
bundle_path = (
|
bundle_path = (
|
||||||
Path(settings.MEDIA_ROOT)
|
Path(settings.MEDIA_ROOT)
|
||||||
/ "documents"
|
/ "documents"
|
||||||
@@ -554,23 +554,6 @@ class ShareLinkBundleModelTests(DirectoriesMixin, APITestCase):
|
|||||||
bundle.delete()
|
bundle.delete()
|
||||||
self.assertFalse(bundle_path.exists())
|
self.assertFalse(bundle_path.exists())
|
||||||
|
|
||||||
bundle2_path = (
|
|
||||||
Path(settings.MEDIA_ROOT)
|
|
||||||
/ "documents"
|
|
||||||
/ "share_link_bundles"
|
|
||||||
/ "harddelete.zip"
|
|
||||||
)
|
|
||||||
bundle2_path.parent.mkdir(parents=True, exist_ok=True)
|
|
||||||
bundle2_path.write_bytes(b"remove-me")
|
|
||||||
bundle2 = ShareLinkBundle.objects.create(
|
|
||||||
slug="harddelete-bundle",
|
|
||||||
file_version=ShareLink.FileVersion.ORIGINAL,
|
|
||||||
file_path=str(bundle2_path.relative_to(settings.MEDIA_ROOT)),
|
|
||||||
)
|
|
||||||
|
|
||||||
bundle2.hard_delete()
|
|
||||||
self.assertFalse(bundle2_path.exists())
|
|
||||||
|
|
||||||
|
|
||||||
class ShareLinkBundleSerializerTests(DirectoriesMixin, APITestCase):
|
class ShareLinkBundleSerializerTests(DirectoriesMixin, APITestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user