Skip to content
Open
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
28 changes: 28 additions & 0 deletions openedx/core/djangoapps/discussions/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,37 @@ def update_discussions_settings_from_course(
plugin_configuration=provider_config,
contexts=contexts,
)

# Sync DiscussionsConfiguration.enabled from the discussion tab's
# is_hidden state. When a course is imported or rerun, course.tabs are
# copied verbatim from the source but DiscussionsConfiguration is not,
# so we reconcile here where we already have the course loaded.
_sync_enabled_from_discussion_tab(course_key, course)

return config_data
Comment on lines +100 to 107
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite what I meant. I meant that this function should extract the info from modulestore and add it config_data, and that the update_course_discussion_config should use the new config_data to update the DiscussionsConfiguration table.



def _sync_enabled_from_discussion_tab(course_key, course):
"""
Set DiscussionsConfiguration.enabled based on the discussion tab's is_hidden
value from the given course object.

This keeps the DB model in sync with the modulestore tab state, which is
especially important after course import or rerun where the tab state is
copied but the DiscussionsConfiguration record is not.
"""
enabled = True # default when no discussion tab is found
if course:
for tab in course.tabs:
if getattr(tab, 'tab_id', None) == 'discussion':
enabled = not tab.is_hidden
break

DiscussionsConfiguration.objects.filter(
context_key=course_key,
).update(enabled=enabled)


def get_discussable_units(course, enable_graded_units, discussable_units=None):
"""
Get all the units in the course that are discussable.
Expand Down
27 changes: 27 additions & 0 deletions openedx/core/djangoapps/discussions/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,33 @@ def test_custom_discussion_settings(self, settings, context_count, present_units
assert present_units <= units_in_config
assert not missing_units & units_in_config

@ddt.data(
# (initial_enabled, tab_is_hidden, expected_enabled)
(True, True, False), # import with hidden tab → disabled
(False, False, True), # import with visible tab → enabled
)
@ddt.unpack
def test_syncs_enabled_from_discussion_tab(self, initial_enabled, tab_is_hidden, expected_enabled):
"""
After update_discussions_settings_from_course, DiscussionsConfiguration.enabled
should match `not tab.is_hidden` from the course's discussion tab.
"""
discussion_config = DiscussionsConfiguration.get(self.course.id)
discussion_config.enabled = initial_enabled
discussion_config.save()

course = self.store.get_course(self.course.id)
for tab in course.tabs:
if getattr(tab, 'tab_id', None) == 'discussion':
tab['is_hidden'] = tab_is_hidden
break
self.store.update_item(course, self.user.id)

update_discussions_settings_from_course(self.course.id)

discussion_config = DiscussionsConfiguration.get(self.course.id)
assert discussion_config.enabled is expected_enabled


@ddt.ddt
class MigrateUnitDiscussionStateFromXBlockTestCase(ModuleStoreTestCase, DiscussionConfigUpdateMixin):
Expand Down
Loading