From 085987e9be5b4e9919773d6e6f85bbeb42b93ec3 Mon Sep 17 00:00:00 2001 From: Dmytro <98233552+DmytroAlipov@users.noreply.github.com> Date: Tue, 1 Aug 2023 16:01:44 +0300 Subject: [PATCH] fix: discussion errors in the demo course for Palm (#32464) Discussion: - https://github.com/openedx/wg-build-test-release/issues/276 Co-authored-by: Edward Zarecor --- .../tests/test_discussion_xblock.py | 7 ++++ xmodule/discussion_block.py | 35 +++++++++++-------- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/lms/djangoapps/courseware/tests/test_discussion_xblock.py b/lms/djangoapps/courseware/tests/test_discussion_xblock.py index 49f76be0f400..4ea3d12b4e63 100644 --- a/lms/djangoapps/courseware/tests/test_discussion_xblock.py +++ b/lms/djangoapps/courseware/tests/test_discussion_xblock.py @@ -12,6 +12,8 @@ from unittest import mock import ddt +from django.conf import settings +from django.test.utils import override_settings from django.urls import reverse from opaque_keys.edx.keys import CourseKey from web_fragments.fragment import Fragment @@ -167,6 +169,7 @@ def test_studio_view(self): } ) + @override_settings(FEATURES=dict(settings.FEATURES, ENABLE_DISCUSSION_SERVICE='True')) @ddt.data( (False, False, False), (True, False, False), @@ -231,6 +234,7 @@ def test_studio_view(self): fragment = self.block.author_view({}) assert f'data-discussion-id="{self.discussion_id}"' in fragment.content + @override_settings(FEATURES=dict(settings.FEATURES, ENABLE_DISCUSSION_SERVICE='True')) @ddt.data( (True, False, False), (False, True, False), @@ -290,6 +294,7 @@ def get_root(self, block): block = block.get_parent() return block + @override_settings(FEATURES=dict(settings.FEATURES, ENABLE_DISCUSSION_SERVICE='True')) def test_html_with_user(self): """ Test rendered DiscussionXBlock permissions. @@ -308,6 +313,7 @@ def test_html_with_user(self): assert 'data-user-create-comment="false"' in html assert 'data-user-create-subcomment="false"' in html + @override_settings(FEATURES=dict(settings.FEATURES, ENABLE_DISCUSSION_SERVICE='True')) def test_discussion_render_successfully_with_orphan_parent(self): """ Test that discussion xblock render successfully @@ -407,6 +413,7 @@ class TestXBlockQueryLoad(SharedModuleStoreTestCase): Test the number of queries executed when rendering the XBlock. """ + @override_settings(FEATURES=dict(settings.FEATURES, ENABLE_DISCUSSION_SERVICE='True')) def test_permissions_query_load(self): """ Tests that the permissions queries are cached when rendering numerous discussion XBlocks. diff --git a/xmodule/discussion_block.py b/xmodule/discussion_block.py index 84d5fdfb4afb..fdd8ea64717a 100644 --- a/xmodule/discussion_block.py +++ b/xmodule/discussion_block.py @@ -163,6 +163,9 @@ def student_view(self, context=None): """ Renders student view for LMS. """ + # to prevent a circular import issue + import lms.djangoapps.discussion.django_comment_client.utils as utils + fragment = Fragment() if not self.is_visible: @@ -189,21 +192,23 @@ def student_view(self, context=None): ), ) - context = { - 'discussion_id': self.discussion_id, - 'display_name': self.display_name if self.display_name else _("Discussion"), - 'user': self.django_user, - 'course_id': self.course_key, - 'discussion_category': self.discussion_category, - 'discussion_target': self.discussion_target, - 'can_create_thread': self.has_permission("create_thread"), - 'can_create_comment': self.has_permission("create_comment"), - 'can_create_subcomment': self.has_permission("create_sub_comment"), - 'login_msg': login_msg, - } - - fragment.add_content(self.runtime.service(self, 'mako').render_template('discussion/_discussion_inline.html', - context)) + if utils.is_discussion_enabled(self.course_key): + context = { + 'discussion_id': self.discussion_id, + 'display_name': self.display_name if self.display_name else _("Discussion"), + 'user': self.django_user, + 'course_id': self.course_key, + 'discussion_category': self.discussion_category, + 'discussion_target': self.discussion_target, + 'can_create_thread': self.has_permission("create_thread"), + 'can_create_comment': self.has_permission("create_comment"), + 'can_create_subcomment': self.has_permission("create_sub_comment"), + 'login_msg': login_msg, + } + fragment.add_content( + self.runtime.service(self, 'mako').render_template('discussion/_discussion_inline.html', context) + ) + fragment.initialize_js('DiscussionInlineBlock') return fragment