Skip to content

Commit

Permalink
Merge pull request #2295 from openedx/saleem-latif/ENT-9612
Browse files Browse the repository at this point in the history
refactor: Removed "plotly_token/" API endpoint and related views from enterprise API.
  • Loading branch information
saleem-latif authored Dec 2, 2024
2 parents ec072b8 + 4d5ba22 commit 12f3e25
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 131 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
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.33.1"
__version__ = "5.0.0"
6 changes: 0 additions & 6 deletions enterprise/api/v1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
notifications,
pending_enterprise_customer_admin_user,
pending_enterprise_customer_user,
plotly_auth,
)

router = DefaultRouter()
Expand Down Expand Up @@ -131,11 +130,6 @@
coupon_codes.CouponCodesView.as_view(),
name='request-codes'
),
re_path(
r'^plotly_token/(?P<enterprise_uuid>[A-Za-z0-9-]+)$',
plotly_auth.PlotlyAuthView.as_view(),
name='plotly-token'
),
re_path(
r'^enterprise_report_types/(?P<enterprise_uuid>[A-Za-z0-9-]+)$',
enterprise_customer_reporting.EnterpriseCustomerReportTypesView.as_view(),
Expand Down
62 changes: 0 additions & 62 deletions enterprise/api/v1/views/plotly_auth.py

This file was deleted.

62 changes: 0 additions & 62 deletions tests/test_enterprise/api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down

0 comments on commit 12f3e25

Please sign in to comment.