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

fix: curation API differentiates unpublished collections for revisions #3912

Merged
Merged
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: 3 additions & 1 deletion backend/portal/api/curation/curation-api.yml
Original file line number Diff line number Diff line change
@@ -582,7 +582,9 @@ components:
description: Collection metadata
properties:
collection_url:
description: The CELLxGENE Discover URL for the Collection.
description: |
The CELLxGENE Discover URL for the Collection. This points to the canonical link unless it's a revision,
in which case it points to the unpublished revision version.
type: string
contact_email:
$ref: "#/components/schemas/contact_email"
21 changes: 17 additions & 4 deletions backend/portal/api/curation/v1/curation/collections/common.py
Original file line number Diff line number Diff line change
@@ -69,6 +69,7 @@ def reshape_for_curation_api(
if is_published:
# Published
collection_id = collection_version.collection_id
collection_url = f"{get_collections_base_url()}/collections/{collection_id.id}"
revision_of = None
if not user_info.is_user_owner_or_allowed(collection_version.owner):
_revising_in = None
@@ -78,9 +79,21 @@ def reshape_for_curation_api(
)
revising_in = _revising_in.version_id.id if _revising_in else None
else:
# Unpublished
collection_id = collection_version.version_id
revision_of = collection_version.collection_id.id
# Unpublished - need to determine if it's a revision or first time collection
# For that, we look at whether the canonical collection is published
is_revision = collection_version.canonical_collection.originally_published_at is not None
if is_revision:
# If it's a revision, both collection_id and collection_url need to point to the version_id
collection_id = collection_version.version_id
collection_url = f"{get_collections_base_url()}/collections/{collection_id.id}"
revision_of = collection_version.collection_id.id
else:
# If it's an unpublished, unrevised collection, then collection_url will point to the permalink
# (aka the link to the canonical_id) and the collection_id will point to version_id.
# Also, revision_of should be None
collection_id = collection_version.version_id
collection_url = f"{get_collections_base_url()}/collections/{collection_version.collection_id}"
revision_of = None
revising_in = None

# get collection dataset attributes
@@ -94,7 +107,7 @@ def reshape_for_curation_api(
else:
revised_at = None
response = dict(
collection_url=f"{get_collections_base_url()}/collections/{collection_id.id}",
collection_url=collection_url,
contact_email=collection_version.metadata.contact_email,
contact_name=collection_version.metadata.contact_name,
created_at=collection_version.created_at,
4 changes: 2 additions & 2 deletions tests/unit/backend/layers/api/test_curation_api.py
Original file line number Diff line number Diff line change
@@ -349,11 +349,11 @@ def test__get_collections_with_auth__OK_5(self):

def test__get_collections_with_auth__OK_6(self):
"revision_of contains None if the collection is unpublished"
unpublished_collection_id = self.generate_unpublished_collection()
self.generate_unpublished_collection()
resp = self._test_response(visibility="PRIVATE", auth=True)
self.assertEqual(1, len(resp))
resp_collection = resp[0]
self.assertEqual(unpublished_collection_id.collection_id.id, resp_collection["revision_of"])
self.assertIsNone(resp_collection["revision_of"])

def test__get_collections_no_auth_visibility_private__403(self):
self._test_response(visibility="PRIVATE", status_code=403)