Skip to content

Commit

Permalink
feat: add waffle flag to disable naigation sidebar
Browse files Browse the repository at this point in the history
  • Loading branch information
GlugovGrGlib committed May 2, 2024
1 parent 84a2116 commit af20b2d
Show file tree
Hide file tree
Showing 4 changed files with 78 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 @@ -78,6 +78,7 @@
from lms.djangoapps.courseware.tests.helpers import MasqueradeMixin, get_expiration_banner_text, set_preview_mode
from lms.djangoapps.courseware.testutils import RenderXBlockTestMixin
from lms.djangoapps.courseware.toggles import (
COURSEWARE_MICROFRONTEND_SIDEBAR_DISABLED,
COURSEWARE_MICROFRONTEND_SEARCH_ENABLED,
COURSEWARE_OPTIMIZED_RENDER_XBLOCK,
COURSEWARE_SHOW_DEFAULT_RIGHT_SIDEBAR,
Expand Down Expand Up @@ -3815,6 +3816,42 @@ def test_is_mfe_search_waffle_disabled(self):
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_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})


class TestMFEDiscussionSidebarEnabledAPI(SharedModuleStoreTestCase):
"""
Tests the endpoint to fetch the Courseware Discussion/Notifications Sidebar waffle flag status.
Expand Down
20 changes: 20 additions & 0 deletions lms/djangoapps/courseware/toggles.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@
f'{WAFFLE_FLAG_NAMESPACE}.disable_navigation_sidebar_blocks_caching', __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.show_default_right_sidebar
# .. toggle_implementation: WaffleFlag
# .. toggle_default: False
Expand Down Expand Up @@ -209,6 +222,13 @@ def courseware_disable_navigation_sidebar_blocks_caching(course_key=None):
return COURSEWARE_MICROFRONTEND_NAVIGATION_SIDEBAR_BLOCKS_DISABLE_CACHING.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)


def courseware_show_default_right_sidebar_is_enabled(course_key=None):
"""
Return whether the courseware.show_default_right_sidebar flag is on.
Expand Down
17 changes: 16 additions & 1 deletion lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
course_is_invitation_only,
courseware_mfe_search_is_enabled,
courseware_show_default_right_sidebar_is_enabled,
courseware_mfe_sidebar_is_disabled,
)
from lms.djangoapps.courseware.user_state_client import DjangoXBlockUserStateClient
from lms.djangoapps.courseware.utils import (
Expand Down Expand Up @@ -2288,6 +2289,21 @@ def courseware_mfe_search_enabled(request, course_id=None):
return JsonResponse(payload)


@api_view(['GET'])
def courseware_mfe_sidebar_enabled(request, course_id=None):
"""
GET endpoint to expose whether the course may display navigation sidebar.
"""
try:
course_key = CourseKey.from_string(course_id) if course_id else None
except InvalidKeyError:
return JsonResponse({"error": "Invalid course_id"})

return JsonResponse({
"enabled": not courseware_mfe_sidebar_is_disabled(course_key)
})


@api_view(['GET'])
def courseware_mfe_show_default_right_sidebar_is_enabled(request, course_id=None):
"""
Expand All @@ -2301,4 +2317,3 @@ def courseware_mfe_show_default_right_sidebar_is_enabled(request, course_id=None
return JsonResponse({
"enabled": courseware_show_default_right_sidebar_is_enabled(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',
),
re_path(
fr'^courses/{settings.COURSE_ID_PATTERN}/discussion-sidebar/enabled/$',
courseware_views.courseware_mfe_show_default_right_sidebar_is_enabled,
Expand Down

0 comments on commit af20b2d

Please sign in to comment.