Skip to content
Draft
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
8 changes: 4 additions & 4 deletions dandiapi/api/services/asset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
AssetAlreadyExistsError,
AssetPathConflictError,
DandisetOwnerRequiredError,
DraftDandisetNotModifiableError,
PublishedDandisetNotModifiableError,
ZarrArchiveBelongsToDifferentDandisetError,
)
from dandiapi.api.services.permissions.dandiset import is_dandiset_owner
Expand Down Expand Up @@ -121,7 +121,7 @@ def change_asset( # noqa: PLR0913
if not is_dandiset_owner(version.dandiset, user):
raise DandisetOwnerRequiredError
if version.version != 'draft':
raise DraftDandisetNotModifiableError
raise PublishedDandisetNotModifiableError

path = new_metadata['path']
new_metadata_stripped = Asset.strip_metadata(new_metadata)
Expand Down Expand Up @@ -171,7 +171,7 @@ def add_asset_to_version(
if not is_dandiset_owner(version.dandiset, user):
raise DandisetOwnerRequiredError
if version.version != 'draft':
raise DraftDandisetNotModifiableError
raise PublishedDandisetNotModifiableError

# Check if there are already any assets with the same path
path = metadata['path']
Expand Down Expand Up @@ -203,7 +203,7 @@ def remove_asset_from_version(*, user, asset: Asset, version: Version) -> Versio
if not is_dandiset_owner(version.dandiset, user):
raise DandisetOwnerRequiredError
if version.version != 'draft':
raise DraftDandisetNotModifiableError
raise PublishedDandisetNotModifiableError

with transaction.atomic():
_remove_asset_from_version(asset=asset, version=version)
Expand Down
2 changes: 1 addition & 1 deletion dandiapi/api/services/asset/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class DandisetOwnerRequiredError(DandiError):
message = 'A dandiset owner is required to perform this action.'


class DraftDandisetNotModifiableError(DandiError):
class PublishedDandisetNotModifiableError(DandiError):
http_status_code = status.HTTP_405_METHOD_NOT_ALLOWED
message = 'Only draft versions can be modified.'

Expand Down
4 changes: 2 additions & 2 deletions dandiapi/api/views/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
change_asset,
remove_asset_from_version,
)
from dandiapi.api.services.asset.exceptions import DraftDandisetNotModifiableError
from dandiapi.api.services.asset.exceptions import PublishedDandisetNotModifiableError
from dandiapi.api.services.embargo.exceptions import DandisetUnembargoInProgressError
from dandiapi.api.services.permissions.dandiset import (
is_dandiset_owner,
Expand Down Expand Up @@ -360,7 +360,7 @@ def update(self, request, versions__dandiset__pk, versions__version, **kwargs):
version=versions__version,
)
if version.version != 'draft':
raise DraftDandisetNotModifiableError
raise PublishedDandisetNotModifiableError
if version.dandiset.unembargo_in_progress:
raise DandisetUnembargoInProgressError

Expand Down
6 changes: 2 additions & 4 deletions dandiapi/api/views/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from dandiapi.api.models import Dandiset, Version
from dandiapi.api.services import audit
from dandiapi.api.services.asset.exceptions import PublishedDandisetNotModifiableError
from dandiapi.api.services.embargo.exceptions import DandisetUnembargoInProgressError
from dandiapi.api.services.permissions.dandiset import (
is_dandiset_owner,
Expand Down Expand Up @@ -96,10 +97,7 @@ def update(self, request, **kwargs):
"""Update the metadata of a version."""
version: Version = self.get_object()
if version.version != 'draft':
return Response(
'Only draft versions can be modified.',
status=status.HTTP_405_METHOD_NOT_ALLOWED,
)
raise PublishedDandisetNotModifiableError
if version.dandiset.unembargo_in_progress:
raise DandisetUnembargoInProgressError

Expand Down
Loading