diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 854beb342f..eeb04908c7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -16,6 +16,10 @@ Change Log Unreleased ---------- +[4.16.1] +--------- +* fix: add enterprise audit reporting status in plotly auth token + [4.16.0] --------- * feat: Adding python3.11 support. Dropped django32 support. diff --git a/enterprise/__init__.py b/enterprise/__init__.py index d98a432b25..c8a6de1876 100644 --- a/enterprise/__init__.py +++ b/enterprise/__init__.py @@ -2,4 +2,4 @@ Your project description goes here. """ -__version__ = "4.16.0" +__version__ = "4.16.1" diff --git a/enterprise/api/v1/views/plotly_auth.py b/enterprise/api/v1/views/plotly_auth.py index 123f223fa6..2f9005704f 100644 --- a/enterprise/api/v1/views/plotly_auth.py +++ b/enterprise/api/v1/views/plotly_auth.py @@ -12,6 +12,8 @@ from django.conf import settings from django.http import JsonResponse +from enterprise.models import EnterpriseCustomer + class PlotlyAuthView(generics.GenericAPIView): """ @@ -41,8 +43,20 @@ def get(self, request, enterprise_uuid): jwt_payload = dict({ 'enterprise_uuid': enterprise_uuid, + 'audit_data_reporting_enabled': self._is_audit_data_reporting_enabled(enterprise_uuid), }, **CLAIMS) token = jwt.encode(jwt_payload, secret_key, algorithm='HS512') json_payload = {'token': token} return JsonResponse(json_payload) + + @staticmethod + def _is_audit_data_reporting_enabled(enterprise_uuid): + """ + Check if audit data reporting is enabled for the enterprise. + + Args: + enterprise_uuid (str): UUID of the enterprise. + """ + enterprise = EnterpriseCustomer.objects.filter(uuid=enterprise_uuid).first() + return getattr(enterprise, 'enable_audit_data_reporting', False) diff --git a/tests/test_enterprise/api/test_views.py b/tests/test_enterprise/api/test_views.py index aee9f4aa16..cce0931388 100644 --- a/tests/test_enterprise/api/test_views.py +++ b/tests/test_enterprise/api/test_views.py @@ -14,6 +14,7 @@ from urllib.parse import parse_qs, urlencode, urljoin, urlsplit, urlunsplit import ddt +import jwt import pytz import responses from edx_toggles.toggles.testutils import override_waffle_flag @@ -6958,6 +6959,7 @@ def test_view_with_admin_user(self): """ Verify that an enterprise admin user having `enterprise.can_access_admin_dashboard` role can access the view. """ + EnterpriseCustomerFactory.create(uuid=self.enterprise_uuid, enable_audit_data_reporting=True) self.set_jwt_cookie(ENTERPRISE_ADMIN_ROLE, self.enterprise_uuid) self.client.login(username=self.user.username, password=TEST_PASSWORD) @@ -6965,6 +6967,9 @@ def test_view_with_admin_user(self): response = self.client.get(self.url) assert response.status_code == status.HTTP_200_OK assert 'token' in response.json() + token = response.json().get('token') + decoded_jwt = jwt.decode(token, settings.ENTERPRISE_PLOTLY_SECRET, algorithms=['HS512']) + assert decoded_jwt['audit_data_reporting_enabled'] is True def test_view_with_admin_user_tries(self): """