Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set assets to pending during unembargo #2117

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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