Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [AXIMST-629] waffle flag for displaying discussions tab in … #2514

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion 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_DISCUSSION_SIDEBAR_OPEN_DISABLED,
COURSEWARE_MICROFRONTEND_SEARCH_ENABLED,
COURSEWARE_MICROFRONTEND_SIDEBAR_DISABLED,
COURSEWARE_OPTIMIZED_RENDER_XBLOCK,
Expand Down Expand Up @@ -3812,7 +3813,7 @@ def test_courseware_mfe_sidebar_disabled(self):
self.assertEqual(body, {'enabled': False})

@override_waffle_flag(COURSEWARE_MICROFRONTEND_SIDEBAR_DISABLED, active=False)
def test_is_mfe_search_sidebar_enabled(self):
def test_is_mfe_sidebar_enabled(self):
"""
Getter to check if user is allowed to show the Courseware navigation sidebar.
"""
Expand All @@ -3821,3 +3822,39 @@ def test_is_mfe_search_sidebar_enabled(self):

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


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

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

self.course = CourseFactory.create()

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

@override_waffle_flag(COURSEWARE_MICROFRONTEND_DISCUSSION_SIDEBAR_OPEN_DISABLED, active=True)
def test_is_mfe_discussion_sidebar_opening_disabled(self):
"""
Getter to check if discussion sidebar shouldn't be opened by default.
"""
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_DISCUSSION_SIDEBAR_OPEN_DISABLED, active=False)
def test_is_mfe_discussion_sidebar_opening_enabled(self):
"""
Getter to check if discussion sidebar should be opened by default.
"""
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 @@ -81,6 +81,19 @@
f'{WAFFLE_FLAG_NAMESPACE}.disable_navigation_sidebar', __name__
)

# .. toggle_name: courseware.disable_default_opening_discussion_sidebar
# .. toggle_implementation: WaffleFlag
# .. toggle_default: False
# .. toggle_description: Disable opening the discussion sidebar by default on Learning MFE.
# .. toggle_use_cases: temporary
# .. toggle_creation_date: 2024-03-13
# .. toggle_target_removal_date: None
# .. toggle_tickets: AXIMST-629
# .. toggle_warning: None.
COURSEWARE_MICROFRONTEND_DISCUSSION_SIDEBAR_OPEN_DISABLED = CourseWaffleFlag(
f'{WAFFLE_FLAG_NAMESPACE}.disable_default_opening_discussion_sidebar', __name__
)

# .. toggle_name: courseware.mfe_progress_milestones_streak_discount_enabled
# .. toggle_implementation: CourseWaffleFlag
# .. toggle_default: False
Expand Down Expand Up @@ -206,3 +219,10 @@ 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_mfe_discussion_sidebar_opening_is_disabled(course_key=None):
"""
Return whether the courseware.disable_default_opening_discussion_sidebar flag is on.
"""
return COURSEWARE_MICROFRONTEND_DISCUSSION_SIDEBAR_OPEN_DISABLED.is_enabled(course_key)
15 changes: 14 additions & 1 deletion lms/djangoapps/courseware/views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@
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_discussion_sidebar_opening_is_disabled,
courseware_mfe_search_is_enabled,
courseware_mfe_sidebar_is_disabled
courseware_mfe_sidebar_is_disabled,
)
from lms.djangoapps.courseware.user_state_client import DjangoXBlockUserStateClient
from lms.djangoapps.courseware.utils import (
Expand Down Expand Up @@ -2285,3 +2286,15 @@ def courseware_mfe_sidebar_enabled(request, course_id=None):
return JsonResponse({
"enabled": not courseware_mfe_sidebar_is_disabled(course_key)
})


@api_view(['GET'])
def courseware_mfe_discussion_sidebar_opening_is_enabled(request, course_id=None):
"""
Simple GET endpoint to expose whether the course may open discussion sidebar by default.
"""
course_key = CourseKey.from_string(course_id) if course_id else None

return JsonResponse({
"enabled": not courseware_mfe_discussion_sidebar_opening_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 @@ -754,6 +754,11 @@
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_discussion_sidebar_opening_is_enabled,
name='discussion_sidebar_enabled_view',
),
]

urlpatterns += [
Expand Down
Loading