From ec072b88ff7ed7a8a138fe0aa18474d6cd7aa410 Mon Sep 17 00:00:00 2001 From: Demid Date: Thu, 28 Nov 2024 15:51:19 +0200 Subject: [PATCH 1/2] build: enable CI for pull requests (#1978) Co-authored-by: Braden MacDonald Co-authored-by: Arunmozhi --- .github/workflows/ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e5d46dcb7..00e6d02d0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,7 +4,6 @@ on: push: branches: [master] pull_request: - branches: [master] concurrency: group: ci-${{ github.event.pull_request.number || github.ref }} From 4d5ba22917cdffbb4e25bb26bbb7715226a3b166 Mon Sep 17 00:00:00 2001 From: Saleem Latif Date: Wed, 27 Nov 2024 16:35:31 +0500 Subject: [PATCH 2/2] refactor: Removed API endpoint and related views from enterprise API. --- CHANGELOG.rst | 4 ++ enterprise/__init__.py | 2 +- enterprise/api/v1/urls.py | 6 --- enterprise/api/v1/views/plotly_auth.py | 62 ------------------------- tests/test_enterprise/api/test_views.py | 62 ------------------------- 5 files changed, 5 insertions(+), 131 deletions(-) delete mode 100644 enterprise/api/v1/views/plotly_auth.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a44618d31..b6572c0b7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -17,6 +17,10 @@ Unreleased ---------- * nothing unreleased +[5.0.0] +-------- +* refactor: Removed `plotly_token/` API endpoint and related views from enterprise API. + [4.33.1] -------- * feat: Creating enterprise customer members endpoint for admin portal diff --git a/enterprise/__init__.py b/enterprise/__init__.py index 5c7d5784a..dee0e04d4 100644 --- a/enterprise/__init__.py +++ b/enterprise/__init__.py @@ -2,4 +2,4 @@ Your project description goes here. """ -__version__ = "4.33.1" +__version__ = "5.0.0" diff --git a/enterprise/api/v1/urls.py b/enterprise/api/v1/urls.py index 3d276bd93..f46d5b55d 100644 --- a/enterprise/api/v1/urls.py +++ b/enterprise/api/v1/urls.py @@ -27,7 +27,6 @@ notifications, pending_enterprise_customer_admin_user, pending_enterprise_customer_user, - plotly_auth, ) router = DefaultRouter() @@ -131,11 +130,6 @@ coupon_codes.CouponCodesView.as_view(), name='request-codes' ), - re_path( - r'^plotly_token/(?P[A-Za-z0-9-]+)$', - plotly_auth.PlotlyAuthView.as_view(), - name='plotly-token' - ), re_path( r'^enterprise_report_types/(?P[A-Za-z0-9-]+)$', enterprise_customer_reporting.EnterpriseCustomerReportTypesView.as_view(), diff --git a/enterprise/api/v1/views/plotly_auth.py b/enterprise/api/v1/views/plotly_auth.py deleted file mode 100644 index 2f9005704..000000000 --- a/enterprise/api/v1/views/plotly_auth.py +++ /dev/null @@ -1,62 +0,0 @@ -""" -Views for Plotly auth. -""" - -from time import time - -import jwt -from edx_rbac.decorators import permission_required -from rest_framework import generics -from rest_framework.permissions import IsAuthenticated - -from django.conf import settings -from django.http import JsonResponse - -from enterprise.models import EnterpriseCustomer - - -class PlotlyAuthView(generics.GenericAPIView): - """ - API to generate a signed token for an enterprise admin to use Plotly analytics. - """ - permission_classes = (IsAuthenticated,) - - @permission_required( - 'enterprise.can_access_admin_dashboard', - fn=lambda request, enterprise_uuid: enterprise_uuid - ) - def get(self, request, enterprise_uuid): - """ - Generate auth token for plotly. - """ - # This is a new secret key and will be only shared between LMS and our Plotly server. - secret_key = settings.ENTERPRISE_PLOTLY_SECRET - - now = int(time()) - expires_in = 3600 # time in seconds after which token will be expired - exp = now + expires_in - - CLAIMS = { - "exp": exp, - "iat": now - } - - 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 9391f4cff..7c474989d 100644 --- a/tests/test_enterprise/api/test_views.py +++ b/tests/test_enterprise/api/test_views.py @@ -14,7 +14,6 @@ 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 @@ -7755,67 +7754,6 @@ def test_same_enable_universal_link(self): self.assertEqual(response['detail'], 'No changes') -@mark.django_db -class TestPlotlyAuthView(APITest): - """ - Test PlotlyAuthView - """ - - PLOTLY_TOKEN_ENDPOINT = 'plotly-token' - - def setUp(self): - """ - Common setup for all tests. - """ - super().setUp() - self.client.login(username=self.user.username, password=TEST_PASSWORD) - self.enterprise_uuid = fake.uuid4() - self.enterprise_uuid2 = fake.uuid4() - self.url = settings.TEST_SERVER + reverse( - self.PLOTLY_TOKEN_ENDPOINT, kwargs={'enterprise_uuid': self.enterprise_uuid} - ) - - def test_view_with_normal_user(self): - """ - Verify that a user without having `enterprise.can_access_admin_dashboard` role can't access the view. - """ - response = self.client.get(self.url) - assert response.status_code == status.HTTP_403_FORBIDDEN - assert response.json() == {'detail': 'Missing: enterprise.can_access_admin_dashboard'} - - 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): - """ - Verify that an enterprise admin can create token for enterprise uuid present in jwt roles only. - """ - self.set_jwt_cookie(ENTERPRISE_ADMIN_ROLE, self.enterprise_uuid) - - url = settings.TEST_SERVER + reverse( - self.PLOTLY_TOKEN_ENDPOINT, kwargs={'enterprise_uuid': self.enterprise_uuid2} - ) - - self.client.login(username=self.user.username, password=TEST_PASSWORD) - - response = self.client.get(url) - assert response.status_code == status.HTTP_403_FORBIDDEN - assert response.json() == {'detail': 'Missing: enterprise.can_access_admin_dashboard'} - - @mark.django_db class TestAnalyticsSummaryView(APITest): """