Skip to content

Commit

Permalink
Merge pull request #2117 from dandi/set-assets-pending-during-unembargo
Browse files Browse the repository at this point in the history
Set assets to pending during unembargo
  • Loading branch information
jjnesbitt authored Jan 2, 2025
2 parents a53e3bf + 413c4d8 commit ee7ed6f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions dandiapi/api/services/embargo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -47,13 +48,16 @@ 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
)
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)

Expand Down
9 changes: 7 additions & 2 deletions dandiapi/api/tests/test_unembargo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand All @@ -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')
Expand All @@ -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()
Expand Down

0 comments on commit ee7ed6f

Please sign in to comment.