Skip to content

Commit

Permalink
Prohibit un-embargo if dandiset has active uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
jjnesbitt committed Jun 17, 2024
1 parent ef7c530 commit b789645
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
9 changes: 8 additions & 1 deletion dandiapi/api/services/embargo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
from dandiapi.api.services.asset.exceptions import DandisetOwnerRequiredError
from dandiapi.api.storage import get_boto_client

from .exceptions import AssetBlobEmbargoedError, DandisetNotEmbargoedError
from .exceptions import (
AssetBlobEmbargoedError,
DandisetActiveUploadsError,
DandisetNotEmbargoedError,
)

if TYPE_CHECKING:
from django.contrib.auth.models import User
Expand Down Expand Up @@ -75,6 +79,9 @@ def unembargo_dandiset(*, user: User, dandiset: Dandiset):
if not user.has_perm('owner', dandiset):
raise DandisetOwnerRequiredError

if dandiset.uploads.count():
raise DandisetActiveUploadsError

# A scheduled task will pick up any new dandisets with this status and email the admins to
# initiate the un-embargo process
dandiset.embargo_status = Dandiset.EmbargoStatus.UNEMBARGOING
Expand Down
5 changes: 5 additions & 0 deletions dandiapi/api/services/embargo/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ class AssetBlobEmbargoedError(DandiError):
class DandisetNotEmbargoedError(DandiError):
http_status_code = status.HTTP_400_BAD_REQUEST
message = 'Dandiset not embargoed'


class DandisetActiveUploadsError(DandiError):
http_status_code = status.HTTP_400_BAD_REQUEST
message = 'Dandiset un-embargo not allowed with active uploads'
15 changes: 15 additions & 0 deletions dandiapi/api/tests/test_unembargo.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,18 @@ def test_unembargo_dandiset_sends_emails(
assert 'un-embargo' in mailoutbox[0].subject
assert dandiset.identifier in mailoutbox[0].message().get_payload()
assert user.username in mailoutbox[0].message().get_payload()


@pytest.mark.django_db()
def test_unembargo_dandiset_lingering_uploads(
api_client, user, dandiset_factory, draft_version_factory, upload_factory
):
dandiset = dandiset_factory(embargo_status=Dandiset.EmbargoStatus.EMBARGOED)
draft_version_factory(dandiset=dandiset)
upload_factory(dandiset=dandiset)

assign_perm('owner', user, dandiset)
api_client.force_authenticate(user=user)

resp = api_client.post(f'/api/dandisets/{dandiset.identifier}/unembargo/')
assert resp.status_code == 400

0 comments on commit b789645

Please sign in to comment.