Skip to content

Commit

Permalink
feat: [AXIMST-611] Create a feature flag to disable sidebar in MFE (#…
Browse files Browse the repository at this point in the history
…2512)

* feat: [AXIMST-611] Create a feature flag to disable sidebar in MFE

* test: [AXIMST-611] Create a tests to feature flag view
  • Loading branch information
NiedielnitsevIvan authored Mar 12, 2024
1 parent b5b6291 commit 24659c8
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 1 deletion.
37 changes: 37 additions & 0 deletions lms/djangoapps/courseware/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
from lms.djangoapps.courseware.testutils import RenderXBlockTestMixin
from lms.djangoapps.courseware.toggles import (
COURSEWARE_MICROFRONTEND_SEARCH_ENABLED,
COURSEWARE_MICROFRONTEND_SIDEBAR_DISABLED,
COURSEWARE_OPTIMIZED_RENDER_XBLOCK,
)
from lms.djangoapps.courseware.user_state_client import DjangoXBlockUserStateClient
Expand Down Expand Up @@ -3784,3 +3785,39 @@ def test_is_mfe_search_disabled(self):

self.assertEqual(response.status_code, 200)
self.assertEqual(body, {'enabled': False})


class TestCoursewareMFESidebarEnabledAPI(SharedModuleStoreTestCase):
"""
Tests the endpoint to fetch the Courseware Sidebar waffle flag status.
"""

def setUp(self):
super().setUp()

self.course = CourseFactory.create()

self.client = APIClient()
self.apiUrl = reverse('courseware_sidebar_enabled_view', kwargs={'course_id': str(self.course.id)})

@override_waffle_flag(COURSEWARE_MICROFRONTEND_SIDEBAR_DISABLED, active=True)
def test_courseware_mfe_sidebar_disabled(self):
"""
Getter to check if user is allowed to show the Courseware navigation sidebar.
"""
response = self.client.get(self.apiUrl, content_type='application/json')
body = json.loads(response.content.decode('utf-8'))

self.assertEqual(response.status_code, 200)
self.assertEqual(body, {'enabled': False})

@override_waffle_flag(COURSEWARE_MICROFRONTEND_SIDEBAR_DISABLED, active=False)
def test_is_mfe_search_sidebar_enabled(self):
"""
Getter to check if user is allowed to show the Courseware navigation sidebar.
"""
response = self.client.get(self.apiUrl, content_type='application/json')
body = json.loads(response.content.decode('utf-8'))

self.assertEqual(response.status_code, 200)
self.assertEqual(body, {'enabled': True})
20 changes: 20 additions & 0 deletions lms/djangoapps/courseware/toggles.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,19 @@
f'{WAFFLE_FLAG_NAMESPACE}.mfe_courseware_search', __name__
)

# .. toggle_name: courseware.disable_navigation_sidebar
# .. toggle_implementation: WaffleFlag
# .. toggle_default: False
# .. toggle_description: Disable navi sidebar on Learning MFE
# .. toggle_use_cases: temporary
# .. toggle_creation_date: 2024-03-07
# .. toggle_target_removal_date: None
# .. toggle_tickets: AXIMST-611
# .. toggle_warning: None.
COURSEWARE_MICROFRONTEND_SIDEBAR_DISABLED = CourseWaffleFlag(
f'{WAFFLE_FLAG_NAMESPACE}.disable_navigation_sidebar', __name__
)

# .. toggle_name: courseware.mfe_progress_milestones_streak_discount_enabled
# .. toggle_implementation: CourseWaffleFlag
# .. toggle_default: False
Expand Down Expand Up @@ -186,3 +199,10 @@ def courseware_mfe_search_is_enabled(course_key=None):
Return whether the courseware.mfe_courseware_search flag is on.
"""
return COURSEWARE_MICROFRONTEND_SEARCH_ENABLED.is_enabled(course_key)


def courseware_mfe_sidebar_is_disabled(course_key=None):
"""
Return whether the courseware.disable_navigation_sidebar flag is on.
"""
return COURSEWARE_MICROFRONTEND_SIDEBAR_DISABLED.is_enabled(course_key)
18 changes: 17 additions & 1 deletion lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@
from lms.djangoapps.courseware.model_data import FieldDataCache
from lms.djangoapps.courseware.models import BaseStudentModuleHistory, StudentModule
from lms.djangoapps.courseware.permissions import MASQUERADE_AS_STUDENT, VIEW_COURSE_HOME, VIEW_COURSEWARE
from lms.djangoapps.courseware.toggles import course_is_invitation_only, courseware_mfe_search_is_enabled
from lms.djangoapps.courseware.toggles import (
course_is_invitation_only,
courseware_mfe_search_is_enabled,
courseware_mfe_sidebar_is_disabled
)
from lms.djangoapps.courseware.user_state_client import DjangoXBlockUserStateClient
from lms.djangoapps.courseware.utils import (
_use_new_financial_assistance_flow,
Expand Down Expand Up @@ -2269,3 +2273,15 @@ def courseware_mfe_search_enabled(request, course_id=None):

payload = {"enabled": courseware_mfe_search_is_enabled(course_key)}
return JsonResponse(payload)


@api_view(['GET'])
def courseware_mfe_sidebar_enabled(request, course_id=None):
"""
Simple GET endpoint to expose whether the course may display navigation sidebar.
"""
course_key = CourseKey.from_string(course_id) if course_id else None

return JsonResponse({
"enabled": not courseware_mfe_sidebar_is_disabled(course_key)
})
5 changes: 5 additions & 0 deletions lms/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,11 @@
courseware_views.courseware_mfe_search_enabled,
name='courseware_search_enabled_view',
),
re_path(
fr'^courses/{settings.COURSE_ID_PATTERN}/courseware-sidebar/enabled/$',
courseware_views.courseware_mfe_sidebar_enabled,
name='courseware_sidebar_enabled_view',
),
]

urlpatterns += [
Expand Down

0 comments on commit 24659c8

Please sign in to comment.