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

chore!: remove now unused public_dataset endpoint #547

Merged
merged 2 commits into from
Oct 1, 2024
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
2 changes: 1 addition & 1 deletion chord_metadata_service/authz/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# be protected by the gateway.
include_pattern_public = (
re.compile(r"^(GET|POST|PUT|DELETE)$"),
re.compile(r"^/api/(projects|datasets|public|public_overview|public_search_fields|public_dataset|public_rules)$"),
re.compile(r"^/api/(projects|datasets|public|public_overview|public_search_fields|public_rules)$"),
)
include_pattern_workflows = (pattern_get, re.compile(r"^(/workflows$|/workflows/)"))
include_pattern_si = (pattern_get, re.compile(r"^/service-info"))
Expand Down
38 changes: 3 additions & 35 deletions chord_metadata_service/discovery/api_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from adrf.decorators import api_view
from bento_lib.responses import errors
from django.conf import settings
from drf_spectacular.utils import extend_schema, inline_serializer
from functools import partial
from operator import is_not
Expand All @@ -11,12 +10,11 @@
from rest_framework.request import Request as DrfRequest
from rest_framework.response import Response

from chord_metadata_service.authz.permissions import BentoAllowAny
from chord_metadata_service.chord import data_types as dts
from chord_metadata_service.discovery.exceptions import DiscoveryScopeException
from chord_metadata_service.discovery.utils import get_request_discovery_scope, get_public_model_scoped_queryset

from ..authz.permissions import BentoAllowAny
from ..chord import data_types as dts, models as cm
from ..logger import logger
from chord_metadata_service.logger import logger

from .fields import get_field_options, get_range_stats, get_categorical_stats, get_date_stats
from .model_lookups import PUBLIC_MODEL_NAMES_TO_DATA_TYPE, PUBLIC_MODEL_NAMES_TO_MODEL, PublicModelName
Expand Down Expand Up @@ -203,36 +201,6 @@ async def _get_field_response(field: str) -> dict:
return Response(response)


@api_view(["GET"])
@permission_classes([BentoAllowAny])
async def public_dataset(_request: DrfRequest):
"""
get:
Properties of the datasets
"""

# For now, we don't have any permissions checks for this.
# In the future, we could introduce a view:dataset permission or something.

if not settings.CONFIG_PUBLIC:
return Response(dres.NO_PUBLIC_DATA_AVAILABLE, status=status.HTTP_404_NOT_FOUND)

# Datasets provenance metadata
datasets = cm.Dataset.objects.values(
"title", "description", "contact_info",
"dates", "stored_in", "spatial_coverage",
"types", "privacy", "distributions",
"dimensions", "primary_publications", "citations",
"produced_by", "creators", "licenses",
"acknowledges", "keywords", "version", "dats_file",
"extra_properties", "identifier", "discovery"
)

return Response({
"datasets": datasets
})


@api_view(["GET"])
@permission_classes([BentoAllowAny])
async def discovery_schema(_request: DrfRequest):
Expand Down
45 changes: 0 additions & 45 deletions chord_metadata_service/discovery/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import json
import os
from copy import deepcopy
import uuid

Expand Down Expand Up @@ -428,49 +426,6 @@ def test_overview_response(self):
self.assertEqual(8, response_obj["fields"]["baseline_creatinine"]["data"][-1]["value"])


class PublicDatasetsMetadataTest(AuthzAPITestCase):

def setUp(self) -> None:
project = ch_m.Project.objects.create(title="Test project", description="test description")
dats_path = os.path.join(os.path.dirname(__file__), "example_dats_provenance.json")
with open(dats_path) as f:
dats_content = json.loads(f.read())

ch_m.Dataset.objects.create(
title="Dataset 1",
description="Test dataset",
contact_info="Test contact info",
types=["test type 1", "test type 2"],
privacy="Open",
keywords=["test keyword 1", "test keyword 2"],
data_use=ch_c.VALID_DATA_USE_1,
project=project,
dats_file=dats_content
)

@override_settings(CONFIG_PUBLIC=DISCOVERY_CONFIG_TEST)
def test_public_dataset(self):
response = self.dt_authz_counts_get(reverse("public-dataset"))
response_obj = response.json()
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertIsInstance(response_obj, dict)

# datasets
self.assertIsInstance(response_obj["datasets"], list)
for i, dataset in enumerate(response_obj["datasets"]):
self.assertIn("title", dataset.keys())
self.assertIsNotNone(dataset["title"])
if i == 0:
self.assertTrue("keywords" in dataset["dats_file"])

@override_settings(CONFIG_PUBLIC={})
def test_public_dataset_response_no_config(self):
response = self.dt_authz_counts_get(reverse("public-dataset"))
response_obj = response.json()
self.assertIsInstance(response_obj, dict)
self.assertEqual(response_obj, dres.NO_PUBLIC_DATA_AVAILABLE)


class DiscoverySchemaTest(AuthzAPITestCase):
@override_settings(CONFIG_PUBLIC=DISCOVERY_CONFIG_TEST)
def test_discover_schema(self):
Expand Down
2 changes: 0 additions & 2 deletions chord_metadata_service/restapi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
public_rules,
public_search_fields,
public_overview,
public_dataset,
discovery_schema
)
from chord_metadata_service.experiments import api_views as experiment_views
Expand Down Expand Up @@ -89,6 +88,5 @@
name='public',),
path('public_search_fields', public_search_fields, name='public-search-fields'),
path('public_overview', public_overview, name='public-overview',),
path('public_dataset', public_dataset, name='public-dataset'),
path('public_rules', public_rules, name='public-rules'),
]