mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-01-26 22:49:01 -06:00
Dont automatically try to rebuild on request, simplify this
This commit is contained in:
@@ -156,57 +156,6 @@ class ShareLinkBundleAPITests(DirectoriesMixin, APITestCase):
|
|||||||
|
|
||||||
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
|
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
|
||||||
|
|
||||||
@mock.patch("documents.views.build_share_link_bundle.delay")
|
|
||||||
def test_download_failed_bundle_triggers_rebuild(self, delay_mock):
|
|
||||||
bundle_path = (
|
|
||||||
Path(settings.MEDIA_ROOT)
|
|
||||||
/ "documents"
|
|
||||||
/ "share_link_bundles"
|
|
||||||
/ "failed.zip"
|
|
||||||
)
|
|
||||||
bundle_path.parent.mkdir(parents=True, exist_ok=True)
|
|
||||||
bundle_path.write_bytes(b"old-content")
|
|
||||||
|
|
||||||
bundle = ShareLinkBundle.objects.create(
|
|
||||||
slug="failedslug",
|
|
||||||
file_version=ShareLink.FileVersion.ARCHIVE,
|
|
||||||
status=ShareLinkBundle.Status.FAILED,
|
|
||||||
file_path=str(bundle_path.relative_to(settings.MEDIA_ROOT)),
|
|
||||||
last_error={"message": "Boom"},
|
|
||||||
size_bytes=10,
|
|
||||||
)
|
|
||||||
bundle.documents.set([self.document])
|
|
||||||
|
|
||||||
self.client.logout()
|
|
||||||
response = self.client.get(f"/share/{bundle.slug}/")
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, status.HTTP_503_SERVICE_UNAVAILABLE)
|
|
||||||
bundle.refresh_from_db()
|
|
||||||
self.assertEqual(bundle.status, ShareLinkBundle.Status.PENDING)
|
|
||||||
self.assertIsNone(bundle.last_error)
|
|
||||||
self.assertIsNone(bundle.size_bytes)
|
|
||||||
self.assertEqual(bundle.file_path, "")
|
|
||||||
delay_mock.assert_called_once_with(bundle.pk)
|
|
||||||
self.assertFalse(bundle_path.exists())
|
|
||||||
|
|
||||||
@mock.patch("documents.views.build_share_link_bundle.delay")
|
|
||||||
def test_download_missing_file_triggers_rebuild(self, delay_mock):
|
|
||||||
bundle = ShareLinkBundle.objects.create(
|
|
||||||
slug="missingfileslug",
|
|
||||||
file_version=ShareLink.FileVersion.ARCHIVE,
|
|
||||||
status=ShareLinkBundle.Status.READY,
|
|
||||||
file_path=str(Path(self.dirs.media_dir) / "does-not-exist.zip"),
|
|
||||||
)
|
|
||||||
bundle.documents.set([self.document])
|
|
||||||
|
|
||||||
self.client.logout()
|
|
||||||
response = self.client.get(f"/share/{bundle.slug}/")
|
|
||||||
|
|
||||||
self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
|
|
||||||
bundle.refresh_from_db()
|
|
||||||
self.assertEqual(bundle.status, ShareLinkBundle.Status.PENDING)
|
|
||||||
delay_mock.assert_called_once_with(bundle.pk)
|
|
||||||
|
|
||||||
def test_expired_share_link_redirects(self):
|
def test_expired_share_link_redirects(self):
|
||||||
share_link = ShareLink.objects.create(
|
share_link = ShareLink.objects.create(
|
||||||
slug="expiredlink",
|
slug="expiredlink",
|
||||||
|
|||||||
@@ -2944,10 +2944,16 @@ class SharedLinkView(View):
|
|||||||
if bundle.expiration is not None and bundle.expiration < timezone.now():
|
if bundle.expiration is not None and bundle.expiration < timezone.now():
|
||||||
return HttpResponseRedirect("/accounts/login/?sharelink_expired=1")
|
return HttpResponseRedirect("/accounts/login/?sharelink_expired=1")
|
||||||
|
|
||||||
if bundle.status in {
|
file_path = bundle.absolute_file_path
|
||||||
ShareLinkBundle.Status.PENDING,
|
|
||||||
ShareLinkBundle.Status.PROCESSING,
|
if (
|
||||||
}:
|
bundle.status
|
||||||
|
in {
|
||||||
|
ShareLinkBundle.Status.PENDING,
|
||||||
|
ShareLinkBundle.Status.PROCESSING,
|
||||||
|
}
|
||||||
|
or file_path is None
|
||||||
|
):
|
||||||
return HttpResponse(
|
return HttpResponse(
|
||||||
_(
|
_(
|
||||||
"The share link bundle is still being prepared. Please try again later.",
|
"The share link bundle is still being prepared. Please try again later.",
|
||||||
@@ -2956,53 +2962,13 @@ class SharedLinkView(View):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if bundle.status == ShareLinkBundle.Status.FAILED:
|
if bundle.status == ShareLinkBundle.Status.FAILED:
|
||||||
bundle.remove_file()
|
|
||||||
bundle.status = ShareLinkBundle.Status.PENDING
|
|
||||||
bundle.last_error = None
|
|
||||||
bundle.size_bytes = None
|
|
||||||
bundle.built_at = None
|
|
||||||
bundle.file_path = ""
|
|
||||||
bundle.save(
|
|
||||||
update_fields=[
|
|
||||||
"status",
|
|
||||||
"last_error",
|
|
||||||
"size_bytes",
|
|
||||||
"built_at",
|
|
||||||
"file_path",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
build_share_link_bundle.delay(bundle.pk)
|
|
||||||
return HttpResponse(
|
return HttpResponse(
|
||||||
_(
|
_(
|
||||||
"The share link bundle is temporarily unavailable. A rebuild has been scheduled. Please try again later.",
|
"The share link bundle is unavailable.",
|
||||||
),
|
),
|
||||||
status=status.HTTP_503_SERVICE_UNAVAILABLE,
|
status=status.HTTP_503_SERVICE_UNAVAILABLE,
|
||||||
)
|
)
|
||||||
|
|
||||||
file_path = bundle.absolute_file_path
|
|
||||||
if file_path is None or not file_path.exists():
|
|
||||||
bundle.status = ShareLinkBundle.Status.PENDING
|
|
||||||
bundle.last_error = None
|
|
||||||
bundle.size_bytes = None
|
|
||||||
bundle.built_at = None
|
|
||||||
bundle.file_path = ""
|
|
||||||
bundle.save(
|
|
||||||
update_fields=[
|
|
||||||
"status",
|
|
||||||
"last_error",
|
|
||||||
"size_bytes",
|
|
||||||
"built_at",
|
|
||||||
"file_path",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
build_share_link_bundle.delay(bundle.pk)
|
|
||||||
return HttpResponse(
|
|
||||||
_(
|
|
||||||
"The share link bundle is being prepared. Please try again later.",
|
|
||||||
),
|
|
||||||
status=status.HTTP_202_ACCEPTED,
|
|
||||||
)
|
|
||||||
|
|
||||||
response = FileResponse(file_path.open("rb"), content_type="application/zip")
|
response = FileResponse(file_path.open("rb"), content_type="application/zip")
|
||||||
short_slug = bundle.slug[:12]
|
short_slug = bundle.slug[:12]
|
||||||
download_name = f"paperless-share-{short_slug}.zip"
|
download_name = f"paperless-share-{short_slug}.zip"
|
||||||
|
|||||||
Reference in New Issue
Block a user