diff --git a/server/vcr-server/agent_webhooks/utils/credential_type.py b/server/vcr-server/agent_webhooks/utils/credential_type.py index 95aca0f62..25867aa2b 100644 --- a/server/vcr-server/agent_webhooks/utils/credential_type.py +++ b/server/vcr-server/agent_webhooks/utils/credential_type.py @@ -94,6 +94,7 @@ def _build_processor_config( processor_config = { "cardinality_fields": credential_type_def.get("cardinality_fields"), "credential": credential_type_def.get("credential"), + "mapping": credential_type_def.get('mapping'), "mappings": credential_type_def.get("mappings"), "topic": credential_type_def.get("topic"), } diff --git a/server/vcr-server/api/v4/serializers/rest/credential.py b/server/vcr-server/api/v4/serializers/rest/credential.py index f5d3523ab..5d92835e0 100644 --- a/server/vcr-server/api/v4/serializers/rest/credential.py +++ b/server/vcr-server/api/v4/serializers/rest/credential.py @@ -82,7 +82,6 @@ class Meta: "claim_descriptions", "logo_b64", "processor_config", - "schema", ) diff --git a/server/vcr-server/api/v4/urls.py b/server/vcr-server/api/v4/urls.py index 621af228d..06c5451fb 100644 --- a/server/vcr-server/api/v4/urls.py +++ b/server/vcr-server/api/v4/urls.py @@ -13,7 +13,7 @@ # DEPRECATED: this should not be used in new code and will be removed imminently autocomplete as search_autocomplete, ) -from api.v4.views.rest import credential_type, issuer, topic, schemas +from api.v4.views.rest import credential_type, issuer, topic, schema from api.v4.views.misc.contact import send_contact from api.v4.views.misc.feedback import send_feedback @@ -38,8 +38,8 @@ router.register(r"credential-type", credential_type.RestView, "Credential Type") router.register(r"issuer", issuer.RestView, "Issuer") -router.register(r"schemas", schemas.RestView) -router.register(r"topic", topic.RestView) +router.register(r"schema", schema.RestView, "Schema") +router.register(r"topic", topic.RestView, "Topic") router.register(r"search/credential", search_credential.SearchView, "Credential Search") router.register(r"search/topic", search_topic.SearchView, "Topic Search") diff --git a/server/vcr-server/api/v4/views/rest/schemas.py b/server/vcr-server/api/v4/views/rest/schema.py similarity index 100% rename from server/vcr-server/api/v4/views/rest/schemas.py rename to server/vcr-server/api/v4/views/rest/schema.py diff --git a/server/vcr-server/api/v4/views/rest/topic.py b/server/vcr-server/api/v4/views/rest/topic.py index 935982294..ab988b4e2 100644 --- a/server/vcr-server/api/v4/views/rest/topic.py +++ b/server/vcr-server/api/v4/views/rest/topic.py @@ -1,4 +1,3 @@ - from django.conf import settings from django.http import Http404 from django.shortcuts import get_object_or_404 @@ -28,16 +27,15 @@ def list(self, request): @swagger_auto_schema(responses={200: CredentialSetSerializer(many=True)}) @action(detail=True, url_path="credential-set", methods=["get"]) - def list_credential_sets(self, request, pk=None): + def credential_set_list(self, request, *args, **kwargs): item = self.get_object() credential_sets = ( - item.credential_sets - .prefetch_related( + item.credential_sets.prefetch_related( "credentials__attributes", "credentials__names", "credentials__credential_type", - "credentials__credential_type__issuer" + "credentials__credential_type__issuer", ) .order_by("first_effective_date") .all() @@ -46,15 +44,27 @@ def list_credential_sets(self, request, pk=None): data = [ { "id": credential_set.id, - "create_timestamp": credential_set.create_timestamp.isoformat() - if credential_set.create_timestamp is not None else None, - "update_timestamp": credential_set.update_timestamp.isoformat() - if credential_set.update_timestamp is not None else None, + "create_timestamp": ( + credential_set.create_timestamp.isoformat() + if credential_set.create_timestamp is not None + else None + ), + "update_timestamp": ( + credential_set.update_timestamp.isoformat() + if credential_set.update_timestamp is not None + else None + ), "latest_credential_id": credential_set.latest_credential_id, - "first_effective_date": credential_set.first_effective_date.isoformat() - if credential_set.first_effective_date is not None else None, - "last_effective_date": credential_set.last_effective_date.isoformat() - if credential_set.last_effective_date is not None else None, + "first_effective_date": ( + credential_set.first_effective_date.isoformat() + if credential_set.first_effective_date is not None + else None + ), + "last_effective_date": ( + credential_set.last_effective_date.isoformat() + if credential_set.last_effective_date is not None + else None + ), "credentials": [ CredentialSerializer(credential).data for credential in credential_set.credentials.all() @@ -67,21 +77,50 @@ def list_credential_sets(self, request, pk=None): response["item_count"] = len(data) return response + @swagger_auto_schema(operation_id="topic_type_read") + @action( + detail=False, + url_path="(?P[^/.]+)/type/(?P[^/]+)", + methods=["get"], + ) + def read(self, request, *args, **kwargs): + item = self.get_object() + return Response(self.get_serializer(item).data) + + @action( + detail=False, + methods=["get"], + url_path="(?P[^/.]+)/type/(?P[^/]+)/credential/(?P[^/.]+)", + ) + def raw_credential_read(self, request, *args, **kwargs): + item = self.get_object() + + credential_id = self.kwargs.get("credential_id") + + credential = item.credentials.filter( + format="vc_di", credential_id=credential_id, revoked=False + ).first() + + if not (credential and credential.raw_data): + raise Http404() + + return Response(credential.raw_data, content_type="application/ld+json") + def get_object(self): if self.kwargs.get("pk"): return super(RestView, self).get_object() - type = self.kwargs.get("type") source_id = self.kwargs.get("source_id") + type = self.kwargs.get("type") if not type or not source_id: raise Http404() - # map type to a schema name, if an "old style" type is used + # Map type to a schema name, if an "old style" type is used if settings.CRED_TYPE_SYNONYMS and type.lower() in settings.CRED_TYPE_SYNONYMS: type = settings.CRED_TYPE_SYNONYMS[type.lower()] queryset = self.filter_queryset(self.get_queryset()) - obj = get_object_or_404(queryset, type=type, source_id=source_id) + obj = get_object_or_404(queryset, source_id=source_id, type=type) # May raise a permission denied self.check_object_permissions(self.request, obj)