From 1368f3767aaabe1ce05e430a57d08b105011a3ee Mon Sep 17 00:00:00 2001 From: Jacob Nesbitt Date: Tue, 27 Aug 2024 12:30:50 -0400 Subject: [PATCH] Disable GUI unembargo button if there are active uploads --- dandiapi/api/models/version.py | 4 ++++ dandiapi/api/tests/test_dandiset.py | 4 ++++ dandiapi/api/tests/test_version.py | 4 ++++ dandiapi/api/views/serializers.py | 1 + web/src/types/index.ts | 1 + web/src/views/DandisetLandingView/DandisetUnembargo.vue | 6 ++++-- 6 files changed, 18 insertions(+), 2 deletions(-) diff --git a/dandiapi/api/models/version.py b/dandiapi/api/models/version.py index a5767b7ec..c134b7285 100644 --- a/dandiapi/api/models/version.py +++ b/dandiapi/api/models/version.py @@ -71,6 +71,10 @@ def size(self): or 0 ) + @property + def active_uploads(self): + return self.dandiset.uploads.count() if self.version == 'draft' else 0 + @property def publishable(self) -> bool: if self.status != Version.Status.VALID: diff --git a/dandiapi/api/tests/test_dandiset.py b/dandiapi/api/tests/test_dandiset.py index 06ac8b807..1dbf86355 100644 --- a/dandiapi/api/tests/test_dandiset.py +++ b/dandiapi/api/tests/test_dandiset.py @@ -343,6 +343,7 @@ def test_dandiset_rest_create(api_client, user): 'version': 'draft', 'name': name, 'asset_count': 0, + 'active_uploads': 0, 'size': 0, 'dandiset': { 'identifier': DANDISET_ID_RE, @@ -436,6 +437,7 @@ def test_dandiset_rest_create_with_identifier(api_client, admin_user): 'version': 'draft', 'name': name, 'asset_count': 0, + 'active_uploads': 0, 'size': 0, 'dandiset': { 'identifier': identifier, @@ -543,6 +545,7 @@ def test_dandiset_rest_create_with_contributor(api_client, admin_user): 'version': 'draft', 'name': name, 'asset_count': 0, + 'active_uploads': 0, 'size': 0, 'dandiset': { 'identifier': identifier, @@ -633,6 +636,7 @@ def test_dandiset_rest_create_embargoed(api_client, user): 'version': 'draft', 'name': name, 'asset_count': 0, + 'active_uploads': 0, 'size': 0, 'dandiset': { 'identifier': DANDISET_ID_RE, diff --git a/dandiapi/api/tests/test_version.py b/dandiapi/api/tests/test_version.py index ffeab68f6..a85445164 100644 --- a/dandiapi/api/tests/test_version.py +++ b/dandiapi/api/tests/test_version.py @@ -423,6 +423,7 @@ def test_version_rest_list(api_client, version, draft_version_factory): 'created': TIMESTAMP_RE, 'modified': TIMESTAMP_RE, 'asset_count': 0, + 'active_uploads': 0, 'size': 0, 'status': 'Pending', } @@ -460,6 +461,7 @@ def test_version_rest_info(api_client, version): 'created': TIMESTAMP_RE, 'modified': TIMESTAMP_RE, 'asset_count': 0, + 'active_uploads': 0, 'metadata': version.metadata, 'size': version.size, 'status': 'Pending', @@ -510,6 +512,7 @@ def test_version_rest_info_with_asset( 'created': TIMESTAMP_RE, 'modified': TIMESTAMP_RE, 'asset_count': 1, + 'active_uploads': 0, 'metadata': version.metadata, 'size': version.size, 'status': Asset.Status.VALID, @@ -586,6 +589,7 @@ def test_version_rest_update(api_client, user, draft_version): 'created': TIMESTAMP_RE, 'modified': TIMESTAMP_RE, 'asset_count': draft_version.asset_count, + 'active_uploads': draft_version.active_uploads, 'metadata': saved_metadata, 'size': draft_version.size, 'status': 'Pending', diff --git a/dandiapi/api/views/serializers.py b/dandiapi/api/views/serializers.py index 3f96c37b9..fb9ff03a0 100644 --- a/dandiapi/api/views/serializers.py +++ b/dandiapi/api/views/serializers.py @@ -88,6 +88,7 @@ class Meta: 'version', 'name', 'asset_count', + 'active_uploads', 'size', 'status', 'created', diff --git a/web/src/types/index.ts b/web/src/types/index.ts index 1e2f9b384..7e6caaf69 100644 --- a/web/src/types/index.ts +++ b/web/src/types/index.ts @@ -38,6 +38,7 @@ export interface Version { version: string, name: string, asset_count: number, + active_uploads: number size: number, status: 'Pending' | 'Validating' | 'Valid' | 'Invalid' | 'Published', validation_error?: string, diff --git a/web/src/views/DandisetLandingView/DandisetUnembargo.vue b/web/src/views/DandisetLandingView/DandisetUnembargo.vue index e1fbfc520..d7d7cfe42 100644 --- a/web/src/views/DandisetLandingView/DandisetUnembargo.vue +++ b/web/src/views/DandisetLandingView/DandisetUnembargo.vue @@ -65,7 +65,7 @@ > This dandiset is being unembargoed, please wait. + This dandiset has active uploads. Please complete or clear these uploads before proceeding. @@ -127,6 +128,7 @@ const store = useDandisetStore(); const currentDandiset = computed(() => store.dandiset); const unembargo_in_progress = computed(() => currentDandiset.value?.dandiset.embargo_status === 'UNEMBARGOING'); +const unembargoDisabled = computed(() => !!(unembargo_in_progress.value || currentDandiset.value === null || currentDandiset.value.active_uploads)); const showWarningDialog = ref(false); const confirmationPhrase = ref('');