feat: Hide discussion block if non-legacy discussion provider is selected (#29259)
This commit is contained in:
@@ -25,6 +25,7 @@ from common.djangoapps.student.auth import has_course_author_access
|
||||
from common.djangoapps.xblock_django.api import authorable_xblocks, disabled_xblocks
|
||||
from common.djangoapps.xblock_django.models import XBlockStudioConfigurationFlag
|
||||
from openedx.core.lib.xblock_utils import get_aside_from_xblock, is_xblock_aside
|
||||
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore.exceptions import ItemNotFoundError
|
||||
|
||||
@@ -294,6 +295,9 @@ def get_component_templates(courselike, library=False): # lint-amnesty, pylint:
|
||||
|
||||
component_types = _filter_disabled_blocks(component_types)
|
||||
|
||||
# Filter out discussion component from component_types if non-legacy discussion provider is configured for course
|
||||
component_types = _filter_discussion_for_non_legacy_provider(component_types, courselike.location.course_key)
|
||||
|
||||
# Content Libraries currently don't allow opting in to unsupported xblocks/problem types.
|
||||
allow_unsupported = getattr(courselike, "allow_unsupported_xblocks", False)
|
||||
|
||||
@@ -438,6 +442,20 @@ def get_component_templates(courselike, library=False): # lint-amnesty, pylint:
|
||||
return component_templates
|
||||
|
||||
|
||||
def _filter_discussion_for_non_legacy_provider(all_components, course_key):
|
||||
"""
|
||||
Filter out Discussion component if non-legacy discussion provider is configured for course key
|
||||
"""
|
||||
discussion_provider = DiscussionsConfiguration.get(context_key=course_key).provider_type
|
||||
|
||||
if discussion_provider != 'legacy':
|
||||
filtered_components = [component for component in all_components if component != 'discussion']
|
||||
else:
|
||||
filtered_components = all_components
|
||||
|
||||
return filtered_components
|
||||
|
||||
|
||||
def _filter_disabled_blocks(all_blocks):
|
||||
"""
|
||||
Filter out disabled xblocks from the provided list of xblock names.
|
||||
|
||||
@@ -39,6 +39,7 @@ from common.djangoapps.xblock_django.models import (
|
||||
)
|
||||
from common.djangoapps.xblock_django.user_service import DjangoXBlockUserService
|
||||
from lms.djangoapps.lms_xblock.mixin import NONSENSICAL_ACCESS_RESTRICTION
|
||||
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration
|
||||
from xmodule.capa_module import ProblemBlock
|
||||
from xmodule.course_module import DEFAULT_START_DATE
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
@@ -2469,6 +2470,40 @@ class TestComponentTemplates(CourseTestCase):
|
||||
self.assertIsNone(get_xblock_problem('Staff Graded Points'))
|
||||
self.assertIsNone(get_xblock_problem('Drag and Drop'))
|
||||
|
||||
def test_discussion_button_present_no_provider(self):
|
||||
"""
|
||||
Test the Discussion button present when no discussion provider configured for course
|
||||
"""
|
||||
templates = get_component_templates(self.course)
|
||||
button_names = [template['display_name'] for template in templates]
|
||||
assert 'Discussion' in button_names
|
||||
|
||||
def test_discussion_button_present_legacy_provider(self):
|
||||
"""
|
||||
Test the Discussion button present when legacy discussion provider configured for course
|
||||
"""
|
||||
course_key = self.course.location.course_key
|
||||
|
||||
# Create a discussion configuration with discussion provider set as legacy
|
||||
DiscussionsConfiguration.objects.create(context_key=course_key, enabled=True, provider_type='legacy')
|
||||
|
||||
templates = get_component_templates(self.course)
|
||||
button_names = [template['display_name'] for template in templates]
|
||||
assert 'Discussion' in button_names
|
||||
|
||||
def test_discussion_button_absent_non_legacy_provider(self):
|
||||
"""
|
||||
Test the Discussion button not present when non-legacy discussion provider configured for course
|
||||
"""
|
||||
course_key = self.course.location.course_key
|
||||
|
||||
# Create a discussion configuration with discussion provider set as legacy
|
||||
DiscussionsConfiguration.objects.create(context_key=course_key, enabled=False, provider_type='ed-discuss')
|
||||
|
||||
templates = get_component_templates(self.course)
|
||||
button_names = [template['display_name'] for template in templates]
|
||||
assert 'Discussion' not in button_names
|
||||
|
||||
def _verify_advanced_xblocks(self, expected_xblocks, expected_support_levels):
|
||||
"""
|
||||
Verify the names of the advanced xblocks showing in the "new component" menu.
|
||||
|
||||
Reference in New Issue
Block a user