feat: hide discussion tab when disabled (#32195)
This commit is contained in:
committed by
GitHub
parent
ab83771295
commit
d8db64cf2a
@@ -234,7 +234,7 @@ class TestFieldOverrideSplitPerformance(FieldOverridePerformanceTestCase):
|
||||
__test__ = True
|
||||
|
||||
# TODO: decrease query count as part of REVO-28
|
||||
QUERY_COUNT = 31
|
||||
QUERY_COUNT = 32
|
||||
|
||||
TEST_DATA = {
|
||||
('no_overrides', 1, True, False): (QUERY_COUNT, 2),
|
||||
|
||||
@@ -3,9 +3,11 @@ Tests for the Course Home Course Metadata API in the Course Home API
|
||||
"""
|
||||
|
||||
import ddt
|
||||
import json
|
||||
import mock
|
||||
from django.urls import reverse
|
||||
from edx_toggles.toggles.testutils import override_waffle_flag
|
||||
from unittest.mock import patch
|
||||
|
||||
from common.djangoapps.course_modes.models import CourseMode
|
||||
from common.djangoapps.student.models import CourseEnrollment
|
||||
@@ -17,6 +19,7 @@ from lms.djangoapps.courseware.toggles import (
|
||||
COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES,
|
||||
COURSEWARE_MICROFRONTEND_PROGRESS_MILESTONES_STREAK_CELEBRATION
|
||||
)
|
||||
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration
|
||||
from openedx.features.enterprise_support.tests.factories import (
|
||||
EnterpriseCourseEnrollmentFactory,
|
||||
EnterpriseCustomerUserFactory
|
||||
@@ -223,3 +226,21 @@ class CourseHomeMetadataTests(BaseCourseHomeTests):
|
||||
assert not enterprise_customer_user_2.active
|
||||
response = self.client.get(self.url)
|
||||
self._assert_course_access_response(response, False, 'incorrect_active_enterprise')
|
||||
|
||||
@patch.dict("django.conf.settings.FEATURES", {"ENABLE_DISCUSSION_SERVICE": True})
|
||||
@ddt.data(True, False)
|
||||
def test_discussion_tab_visible(self, visible):
|
||||
"""
|
||||
Tests if discussion tab is visible based on Configuration
|
||||
"""
|
||||
CourseInstructorRole(self.course.id).add_users(self.user)
|
||||
configuration = DiscussionsConfiguration.get(context_key=self.course.id)
|
||||
configuration.enabled = visible
|
||||
configuration.save()
|
||||
response = self.client.get(self.url)
|
||||
data = json.loads(response.content.decode())
|
||||
tab_ids = [tab['tab_id'] for tab in data['tabs']]
|
||||
if visible:
|
||||
assert 'discussion' in tab_ids
|
||||
else:
|
||||
assert 'discussion' not in tab_ids
|
||||
|
||||
@@ -354,7 +354,7 @@ class IndexQueryTestCase(ModuleStoreTestCase):
|
||||
self.client.login(username=self.user.username, password=self.user_password)
|
||||
CourseEnrollment.enroll(self.user, course.id)
|
||||
|
||||
with self.assertNumQueries(202, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST):
|
||||
with self.assertNumQueries(203, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST):
|
||||
with check_mongo_calls(3):
|
||||
url = reverse(
|
||||
'courseware_section',
|
||||
@@ -1487,8 +1487,8 @@ class ProgressPageTests(ProgressPageBaseTests):
|
||||
self.assertContains(resp, "earned a certificate for this course.")
|
||||
|
||||
@ddt.data(
|
||||
(True, 52),
|
||||
(False, 52),
|
||||
(True, 53),
|
||||
(False, 53),
|
||||
)
|
||||
@ddt.unpack
|
||||
def test_progress_queries_paced_courses(self, self_paced, query_count):
|
||||
@@ -1503,13 +1503,13 @@ class ProgressPageTests(ProgressPageBaseTests):
|
||||
ContentTypeGatingConfig.objects.create(enabled=True, enabled_as_of=datetime(2018, 1, 1))
|
||||
self.setup_course()
|
||||
with self.assertNumQueries(
|
||||
52, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST
|
||||
53, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST
|
||||
), check_mongo_calls(2):
|
||||
self._get_progress_page()
|
||||
|
||||
for _ in range(2):
|
||||
with self.assertNumQueries(
|
||||
36, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST
|
||||
37, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST
|
||||
), check_mongo_calls(2):
|
||||
self._get_progress_page()
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ from django.utils.translation import gettext_noop
|
||||
|
||||
|
||||
from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE
|
||||
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration
|
||||
from openedx.core.djangoapps.discussions.url_helpers import get_discussions_mfe_url
|
||||
from xmodule.tabs import TabFragmentViewMixin
|
||||
|
||||
@@ -34,6 +35,8 @@ class DiscussionTab(TabFragmentViewMixin, EnrolledTab):
|
||||
|
||||
@classmethod
|
||||
def is_enabled(cls, course, user=None):
|
||||
if not DiscussionsConfiguration.is_enabled(context_key=course.id):
|
||||
return False
|
||||
if not super().is_enabled(course, user):
|
||||
return False
|
||||
# Disable the regular discussion tab if LTI-based external Discussion forum is enabled
|
||||
|
||||
@@ -49,7 +49,7 @@ class TestCourseUpdatesPage(BaseCourseUpdatesTestCase):
|
||||
|
||||
# Fetch the view and verify that the query counts haven't changed
|
||||
# TODO: decrease query count as part of REVO-28
|
||||
with self.assertNumQueries(53, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST):
|
||||
with self.assertNumQueries(54, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST):
|
||||
with check_mongo_calls(3):
|
||||
url = course_updates_url(self.course)
|
||||
self.client.get(url)
|
||||
|
||||
Reference in New Issue
Block a user