diff --git a/dandiapi/api/services/embargo/__init__.py b/dandiapi/api/services/embargo/__init__.py index e7a8841ca..5299c156e 100644 --- a/dandiapi/api/services/embargo/__init__.py +++ b/dandiapi/api/services/embargo/__init__.py @@ -7,6 +7,7 @@ from dandiapi.api.mail import send_dandiset_unembargoed_message from dandiapi.api.models import AssetBlob, Dandiset, Version +from dandiapi.api.models.asset import Asset from dandiapi.api.services import audit from dandiapi.api.services.asset.exceptions import DandisetOwnerRequiredError from dandiapi.api.services.embargo.utils import _delete_object_tags, remove_dandiset_embargo_tags @@ -47,6 +48,8 @@ def unembargo_dandiset(ds: Dandiset, user: User): logger.info('Removing tags...') remove_dandiset_embargo_tags(ds) + # Set all assets to pending + updated_assets = Asset.objects.filter(versions__dandiset=ds).update(status=Asset.Status.PENDING) # Update embargoed flag on asset blobs and zarrs updated_blobs = AssetBlob.objects.filter(embargoed=True, assets__versions__dandiset=ds).update( embargoed=False @@ -54,6 +57,7 @@ def unembargo_dandiset(ds: Dandiset, user: User): updated_zarrs = ZarrArchive.objects.filter( embargoed=True, assets__versions__dandiset=ds ).update(embargoed=False) + logger.info('Set %s assets to PENDING', updated_assets) logger.info('Updated %s asset blobs', updated_blobs) logger.info('Updated %s zarrs', updated_zarrs) diff --git a/dandiapi/api/tests/test_unembargo.py b/dandiapi/api/tests/test_unembargo.py index 8fa6149f0..f8b9ce314 100644 --- a/dandiapi/api/tests/test_unembargo.py +++ b/dandiapi/api/tests/test_unembargo.py @@ -6,6 +6,7 @@ from guardian.shortcuts import assign_perm import pytest +from dandiapi.api.models.asset import Asset from dandiapi.api.models.dandiset import Dandiset from dandiapi.api.models.version import Version from dandiapi.api.services.embargo import ( @@ -249,7 +250,8 @@ def test_unembargo_dandiset( assign_perm('owner', user, ds) embargoed_blob: AssetBlob = embargoed_asset_blob_factory() - draft_version.assets.add(asset_factory(blob=embargoed_blob)) + blob_asset = asset_factory(blob=embargoed_blob, status=Asset.Status.VALID) + draft_version.assets.add(blob_asset) zarr_archive: ZarrArchive = embargoed_zarr_archive_factory( dandiset=ds, status=ZarrArchiveStatus.UPLOADED @@ -258,9 +260,11 @@ def test_unembargo_dandiset( zarr_file_factory(zarr_archive) ingest_zarr_archive(zarr_id=zarr_archive.zarr_id) zarr_archive.refresh_from_db() - draft_version.assets.add(asset_factory(zarr=zarr_archive, blob=None)) + zarr_asset = asset_factory(zarr=zarr_archive, blob=None, status=Asset.Status.VALID) + draft_version.assets.add(zarr_asset) assert all(asset.is_embargoed for asset in draft_version.assets.all()) + assert all(asset.status == Asset.Status.VALID for asset in draft_version.assets.all()) # Patch this function to check if it's been called, since we can't test the tagging directly patched = mocker.patch('dandiapi.api.services.embargo.utils._delete_object_tags') @@ -269,6 +273,7 @@ def test_unembargo_dandiset( assert patched.call_count == 1 + zarr_archive.file_count assert not any(asset.is_embargoed for asset in draft_version.assets.all()) + assert all(asset.status == Asset.Status.PENDING for asset in draft_version.assets.all()) ds.refresh_from_db() draft_version.refresh_from_db()