diff --git a/apps/accounts/views/oauth2_profile.py b/apps/accounts/views/oauth2_profile.py index ef118772d..f79c5eb3c 100644 --- a/apps/accounts/views/oauth2_profile.py +++ b/apps/accounts/views/oauth2_profile.py @@ -9,7 +9,7 @@ from apps.fhir.bluebutton.models import Crosswalk from apps.fhir.bluebutton.permissions import ApplicationActivePermission -from apps.constants import Versions +from apps.versions import Versions def _get_userinfo(user, version=Versions.NOT_AN_API_VERSION): @@ -46,8 +46,6 @@ def _get_userinfo(user, version=Versions.NOT_AN_API_VERSION): def _openidconnect_userinfo(request, version=Versions.NOT_AN_API_VERSION): # NOTE: The **kwargs are not used anywhere down the callchain, and are being ignored. - # BB2-4166-TODO: will the request have a version? do we get here from redirects or is this - # a straight url that we need to get the version from the url (like we do in the fhir app) return JsonResponse(_get_userinfo(request.resource_owner, version)) diff --git a/apps/authorization/permissions.py b/apps/authorization/permissions.py index c762dcbbf..2b0d89dca 100644 --- a/apps/authorization/permissions.py +++ b/apps/authorization/permissions.py @@ -1,5 +1,6 @@ from django.conf import settings from rest_framework import (permissions, exceptions) +from apps.versions import Versions, VersionNotMatched from .models import DataAccessGrant @@ -32,8 +33,10 @@ def has_object_permission(self, request, view, obj): # Patient resources were taken care of above # Return 404 on error to avoid notifying unauthorized user the object exists - # BB2-4166-TODO: this is hardcoded to be version 2 - return is_resource_for_patient(obj, request.crosswalk.fhir_id(2)) + if view.version in Versions.supported_versions(): + return is_resource_for_patient(obj, request.crosswalk.fhir_id(view.version)) + else: + raise VersionNotMatched() def is_resource_for_patient(obj, patient_id): diff --git a/apps/authorization/views.py b/apps/authorization/views.py index 2f5a6dcd3..4832df9a4 100644 --- a/apps/authorization/views.py +++ b/apps/authorization/views.py @@ -14,10 +14,11 @@ from oauth2_provider.views.base import OAuthLibMixin from oauth2_provider.views.generic import ClientProtectedResourceView +from apps.versions import VersionNotMatched, Versions from apps.dot_ext.authentication import SLSAuthentication -from .models import DataAccessGrant -from ..dot_ext.utils import get_application_from_meta -from ..fhir.bluebutton.models import Crosswalk +from apps.authorization.models import DataAccessGrant +from apps.dot_ext.utils import get_application_from_meta, get_api_version_number_from_url +from apps.fhir.bluebutton.models import Crosswalk Application = get_application_model() @@ -68,9 +69,21 @@ class ExpireDataAccessGrantView(ClientProtectedResourceView, OAuthLibMixin): @staticmethod def post(request, *args, **kwargs): try: + path_info = request.__dict__.get('path_info') + version = get_api_version_number_from_url(path_info) patient_id = kwargs.pop('patient_id', None) - # BB2-4166-TODO: currently hardcoded for v2, might need to not be static - user = Crosswalk.objects.get(fhir_id_v2=patient_id).user + + # V1 is treated as the same as V2 since their pathways are very similar and use the same fhir_id_v2 despite the name + match version: + case Versions.V1: + user = Crosswalk.objects.get(fhir_id_v2=patient_id).user + case Versions.V2: + user = Crosswalk.objects.get(fhir_id_v2=patient_id).user + case Versions.V3: + user = Crosswalk.objects.get(fhir_id_v3=patient_id).user + case _: + raise VersionNotMatched(f"{version} is not a valid version constant") + client = get_application_from_meta(request) DataAccessGrant.objects.get(beneficiary=user.id, application=client).delete() except Crosswalk.DoesNotExist: diff --git a/apps/bb2_tools/admin.py b/apps/bb2_tools/admin.py index b7f8c435f..75faca7f4 100644 --- a/apps/bb2_tools/admin.py +++ b/apps/bb2_tools/admin.py @@ -21,7 +21,7 @@ DummyAdminObject, UserStats, ) -from apps.fhir.bluebutton.utils import get_patient_by_id +from apps.fhir.bluebutton.utils import get_v2_patient_by_id ADMIN_PREPEND = getattr(settings, "ADMIN_PREPEND_URL", "") BB2_TOOLS_PATH = ( @@ -332,8 +332,7 @@ class BeneficiaryDashboardAdmin(ReadOnlyAdmin): "get_connected_applications", "date_created", ) - # BB2-4166-TODO: add support for v3 - search_fields = ('user__username', 'fhir_id_v2', '_user_id_hash', '_user_mbi') + search_fields = ('user__username', 'fhir_id_v2', 'fhir_id_v3', '_user_id_hash', '_user_mbi') readonly_fields = ('date_created',) raw_id_fields = ('user',) @@ -361,10 +360,9 @@ def get_access_tokens(self, obj): ordering="MyIdentities", ) def get_identities(self, obj): - # BB2-4166-TODO: add support for v3 return format_html( - '