Skip to content

Commit

Permalink
Merge pull request #2080 from openedx/ammar/add-enterprise-audit-enro…
Browse files Browse the repository at this point in the history
…llment-reporting-in-plotly-token

fix: add enterprise audit enrollment reporting status in plotly auth token
  • Loading branch information
muhammad-ammar authored Apr 23, 2024
2 parents 56abeee + ff64011 commit d28e93f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Your project description goes here.
"""

__version__ = "4.16.0"
__version__ = "4.16.1"
14 changes: 14 additions & 0 deletions enterprise/api/v1/views/plotly_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from django.conf import settings
from django.http import JsonResponse

from enterprise.models import EnterpriseCustomer


class PlotlyAuthView(generics.GenericAPIView):
"""
Expand Down Expand Up @@ -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)
5 changes: 5 additions & 0 deletions tests/test_enterprise/api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -6958,13 +6959,17 @@ 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)

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):
"""
Expand Down

0 comments on commit d28e93f

Please sign in to comment.