Skip to content

Commit

Permalink
fix: discussion errors in the demo course for Palm (#32464)
Browse files Browse the repository at this point in the history
Discussion:
 - openedx/wg-build-test-release#276

Co-authored-by: Edward Zarecor <[email protected]>
  • Loading branch information
DmytroAlipov and e0d committed Aug 1, 2023
1 parent 08f6fa6 commit 085987e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
7 changes: 7 additions & 0 deletions lms/djangoapps/courseware/tests/test_discussion_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
35 changes: 20 additions & 15 deletions xmodule/discussion_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 085987e

Please sign in to comment.