diff --git a/chord_metadata_service/authz/middleware.py b/chord_metadata_service/authz/middleware.py index 6574c6a4d..d4abda9a7 100644 --- a/chord_metadata_service/authz/middleware.py +++ b/chord_metadata_service/authz/middleware.py @@ -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")) diff --git a/chord_metadata_service/discovery/api_views.py b/chord_metadata_service/discovery/api_views.py index 3a9a7e516..e06d635ec 100644 --- a/chord_metadata_service/discovery/api_views.py +++ b/chord_metadata_service/discovery/api_views.py @@ -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 @@ -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 @@ -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): diff --git a/chord_metadata_service/discovery/tests/test_api.py b/chord_metadata_service/discovery/tests/test_api.py index a863ae81e..f3a13576f 100644 --- a/chord_metadata_service/discovery/tests/test_api.py +++ b/chord_metadata_service/discovery/tests/test_api.py @@ -1,5 +1,3 @@ -import json -import os from copy import deepcopy import uuid @@ -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): diff --git a/chord_metadata_service/restapi/urls.py b/chord_metadata_service/restapi/urls.py index 43078d229..da795ce96 100644 --- a/chord_metadata_service/restapi/urls.py +++ b/chord_metadata_service/restapi/urls.py @@ -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 @@ -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'), ]