diff --git a/organizations/__init__.py b/organizations/__init__.py index 74f7a2b3..c6c49e3b 100644 --- a/organizations/__init__.py +++ b/organizations/__init__.py @@ -1,4 +1,4 @@ """ edx-organizations app initialization module """ -__version__ = '2.2.0' # pragma: no cover +__version__ = '2.2.1' # pragma: no cover diff --git a/organizations/authentication.py b/organizations/authentication.py new file mode 100644 index 00000000..6c175e02 --- /dev/null +++ b/organizations/authentication.py @@ -0,0 +1,24 @@ +"""Temp auth class to see how often oauth2authentication class is used in organizations""" +from rest_framework_oauth.authentication import OAuth2Authentication +from edx_django_utils.monitoring import set_custom_metric + + +class OAuth2AuthenticationDeprecated(OAuth2Authentication): + """ + This child class was added to add new_relic metrics to OAuth2Authentication. This should be very temporary. + """ + + def authenticate(self, request): + """ + Returns two-tuple of (user, token) if access token authentication + succeeds, None if the user did not try to authenticate using an access + token, or raises an AuthenticationFailed (HTTP 401) if authentication + fails. + """ + set_custom_metric("OAuth2AuthenticationDeprecated", "Failed") + output = super(OAuth2AuthenticationDeprecated, self).authenticate(request) + if output is None: + set_custom_metric("OAuth2AuthenticationDeprecated", "None") + else: + set_custom_metric("OAuth2AuthenticationDeprecated", "Success") + return output diff --git a/organizations/v0/views.py b/organizations/v0/views.py index 689db251..0aaa2518 100644 --- a/organizations/v0/views.py +++ b/organizations/v0/views.py @@ -10,11 +10,11 @@ from rest_framework.authentication import SessionAuthentication from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response -from rest_framework_oauth.authentication import OAuth2Authentication from organizations.models import Organization from organizations.permissions import UserIsStaff from organizations.serializers import OrganizationSerializer +from organizations.authentication import OAuth2AuthenticationDeprecated class OrganizationsViewSet(mixins.UpdateModelMixin, viewsets.ReadOnlyModelViewSet): @@ -26,7 +26,7 @@ class OrganizationsViewSet(mixins.UpdateModelMixin, viewsets.ReadOnlyModelViewSe queryset = Organization.objects.filter(active=True) # pylint: disable=no-member serializer_class = OrganizationSerializer lookup_field = 'short_name' - authentication_classes = (OAuth2Authentication, JwtAuthentication, SessionAuthentication) + authentication_classes = (JwtAuthentication, OAuth2AuthenticationDeprecated, SessionAuthentication) permission_classes = (IsAuthenticated, UserIsStaff) def update(self, request, *args, **kwargs):