From aca3cfebdbae9c019764f4db713990a7023e3469 Mon Sep 17 00:00:00 2001 From: "adeel.tajamul" Date: Tue, 4 Jan 2022 16:29:27 +0500 Subject: [PATCH 1/3] changed fragment to show 404 when discussion tab is clicked --- lms/djangoapps/discussion/views.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lms/djangoapps/discussion/views.py b/lms/djangoapps/discussion/views.py index 824d71925670..77f82dd9e0f3 100644 --- a/lms/djangoapps/discussion/views.py +++ b/lms/djangoapps/discussion/views.py @@ -768,6 +768,7 @@ def render_to_fragment( # lint-amnesty, pylint: disable=arguments-differ else: html = render_to_string('discussion/discussion_board_fragment.html', context) + html = "Error 404: NOT Found" fragment = Fragment(html) self.add_fragment_resource_urls(fragment) inline_js = render_to_string('discussion/discussion_board_js.template', context) From 3699a845b7b9f4c48c33526a657ba497a8fb23a1 Mon Sep 17 00:00:00 2001 From: "adeel.tajamul" Date: Mon, 17 Jan 2022 12:06:17 +0500 Subject: [PATCH 2/3] Added a new flag 'discussion.disable_discussion_tab' to disable discussion for specified courses --- lms/djangoapps/discussion/plugins.py | 4 +++- lms/djangoapps/discussion/toggles.py | 1 + lms/djangoapps/discussion/views.py | 8 +++++--- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lms/djangoapps/discussion/plugins.py b/lms/djangoapps/discussion/plugins.py index 6574778a4831..7423877f7065 100644 --- a/lms/djangoapps/discussion/plugins.py +++ b/lms/djangoapps/discussion/plugins.py @@ -8,7 +8,7 @@ import lms.djangoapps.discussion.django_comment_client.utils as utils from lms.djangoapps.courseware.tabs import EnrolledTab -from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE +from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE, DISCUSSION_DISABLED from openedx.core.djangoapps.discussions.url_helpers import get_discussions_mfe_url from openedx.features.lti_course_tab.tab import DiscussionLtiCourseTab from xmodule.tabs import TabFragmentViewMixin # lint-amnesty, pylint: disable=wrong-import-order @@ -45,6 +45,8 @@ def link_func(course, reverse_func): @classmethod def is_enabled(cls, course, user=None): + if DISCUSSION_DISABLED.is_enabled(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 diff --git a/lms/djangoapps/discussion/toggles.py b/lms/djangoapps/discussion/toggles.py index 31a7f5ac16e9..0f7159bf71e9 100644 --- a/lms/djangoapps/discussion/toggles.py +++ b/lms/djangoapps/discussion/toggles.py @@ -13,3 +13,4 @@ # .. toggle_creation_date: 2021-11-05 # .. toggle_target_removal_date: 2022-03-05 ENABLE_DISCUSSIONS_MFE = CourseWaffleFlag(WAFFLE_FLAG_NAMESPACE, 'enable_discussions_mfe', __name__) +DISCUSSION_DISABLED = CourseWaffleFlag(WAFFLE_FLAG_NAMESPACE, 'disable_discussion_tab', __name__) diff --git a/lms/djangoapps/discussion/views.py b/lms/djangoapps/discussion/views.py index 77f82dd9e0f3..1b5fde54e261 100644 --- a/lms/djangoapps/discussion/views.py +++ b/lms/djangoapps/discussion/views.py @@ -45,7 +45,7 @@ strip_none, ) from lms.djangoapps.discussion.exceptions import TeamDiscussionHiddenFromUserException -from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE +from lms.djangoapps.discussion.toggles import ENABLE_DISCUSSIONS_MFE, DISCUSSION_DISABLED from lms.djangoapps.experiments.utils import get_experiment_user_metadata_context from lms.djangoapps.teams import api as team_api from openedx.core.djangoapps.discussions.url_helpers import get_discussions_mfe_url @@ -762,13 +762,15 @@ def render_to_fragment( # lint-amnesty, pylint: disable=arguments-differ context.update({ 'course_expiration_fragment': course_expiration_fragment, }) - if profile_page_context: + + if DISCUSSION_DISABLED.is_enabled(course_key): + html = "Error 404: NOT Found" + elif profile_page_context: # EDUCATOR-2119: styles are hard to reconcile if the profile page isn't also a fragment html = render_to_string('discussion/discussion_profile_page.html', profile_page_context) else: html = render_to_string('discussion/discussion_board_fragment.html', context) - html = "Error 404: NOT Found" fragment = Fragment(html) self.add_fragment_resource_urls(fragment) inline_js = render_to_string('discussion/discussion_board_js.template', context) From cc36006d1e069e14f9a4f3c5ecf26c946afac3b1 Mon Sep 17 00:00:00 2001 From: "adeel.tajamul" Date: Mon, 17 Jan 2022 17:58:29 +0500 Subject: [PATCH 3/3] Raising 404 error instead of printing 404 error when disabled discussion tab is accessed using url --- lms/djangoapps/discussion/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/djangoapps/discussion/views.py b/lms/djangoapps/discussion/views.py index 1b5fde54e261..3dedc5038a4a 100644 --- a/lms/djangoapps/discussion/views.py +++ b/lms/djangoapps/discussion/views.py @@ -764,7 +764,7 @@ def render_to_fragment( # lint-amnesty, pylint: disable=arguments-differ }) if DISCUSSION_DISABLED.is_enabled(course_key): - html = "Error 404: NOT Found" + raise Http404 elif profile_page_context: # EDUCATOR-2119: styles are hard to reconcile if the profile page isn't also a fragment html = render_to_string('discussion/discussion_profile_page.html', profile_page_context)