diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index 180dc097cf..f0708f32cf 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -20,6 +20,7 @@ from common.djangoapps.student.models import CourseEnrollment from common.djangoapps.student.roles import CourseInstructorRole, CourseStaffRole from openedx.core.djangoapps.course_apps.toggles import proctoring_settings_modal_view_enabled from openedx.core.djangoapps.discussions.config.waffle import ENABLE_PAGES_AND_RESOURCES_MICROFRONTEND +from openedx.core.djangoapps.discussions.models import DiscussionTopicLink, Provider from openedx.core.djangoapps.django_comment_common.models import assign_default_role from openedx.core.djangoapps.django_comment_common.utils import seed_permissions_roles from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers @@ -731,3 +732,38 @@ def translation_language(language): translation.activate(previous) else: yield + + +def mark_verticals_discussion_enabled(course_structure, course_key): + """ + Adds has_discussion attribute on verticals of course_structure + """ + topics = [] + topics_query = DiscussionTopicLink.objects.filter( + context_key=course_key, + provider_id=Provider.OPEN_EDX, + ) + for topic in topics_query: + topics.append({ + "usage_key": str(topic.usage_key) + }) + + sub_sections_reference = [] + if course_structure.get('has_children'): + chapters = course_structure['child_info'].get('children') + for section in chapters: + if section.get('has_children'): + sub_sections = section.get('child_info').get('children') + for sub_section in sub_sections: + sub_sections_reference.append(sub_section) + + for sub_section in sub_sections_reference: + if sub_section.get('has_children'): + verticals = sub_section.get('child_info').get('children') + for vertical in verticals: + vertical_id = vertical.get('id') + vertical['has_discussion'] = False + for topic in topics: + if topic.get('usage_key') == vertical_id: + vertical['has_discussion'] = True + return course_structure diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index 92a8e7dbeb..4fbf4add83 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -34,6 +34,7 @@ from organizations.api import add_organization_course, ensure_organization from organizations.exceptions import InvalidOrganizationException from rest_framework.exceptions import ValidationError +from cms.djangoapps.contentstore.utils import mark_verticals_discussion_enabled from cms.djangoapps.course_creators.views import add_user_with_status_unrequested, get_course_creator_status from cms.djangoapps.models.settings.course_grading import CourseGradingModel from cms.djangoapps.models.settings.course_metadata import CourseMetadata @@ -66,6 +67,7 @@ from openedx.core import toggles as core_toggles from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.credit.api import get_credit_requirements, is_credit_course from openedx.core.djangoapps.credit.tasks import update_credit_course_requirements +from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, Provider from openedx.core.djangoapps.models.course_details import CourseDetails from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangolib.js_utils import dump_js_escaped_json @@ -724,6 +726,11 @@ def course_index(request, course_key): advanced_dict = CourseMetadata.fetch(course_module) proctoring_errors = CourseMetadata.validate_proctoring_settings(course_module, advanced_dict, request.user) + configuration = DiscussionsConfiguration.get(course_key) + provider = configuration.provider_type + if provider == Provider.OPEN_EDX: + mark_verticals_discussion_enabled(course_structure, course_key) + return render_to_response('course_outline.html', { 'language_code': request.LANGUAGE_CODE, 'context_course': course_module, diff --git a/cms/templates/js/course-outline.underscore b/cms/templates/js/course-outline.underscore index df43d0913b..1d9e628ff0 100644 --- a/cms/templates/js/course-outline.underscore +++ b/cms/templates/js/course-outline.underscore @@ -114,7 +114,11 @@ if (is_proctored_exam) { > <% } else { %> -

+ <% if (xblockType == "unit") { %> +

+ <% } else { %> +

+ <% } %> <% } %> <% if (xblockInfo.isVertical()) { %> @@ -128,8 +132,19 @@ if (is_proctored_exam) { <% } %>

-
+ <% if (xblockType == "unit") {%> +
+ <% } else { %> +
+ <% } %>
    + <% if (xblockInfo.isVertical()) { %> + <% if (xblockInfo.get('has_discussion')) {%> +
  • + Discussions enabled +
  • + <% } %> + <% } %> <% if (xblockInfo.isSequential() && xblockInfo.get('proctoring_exam_configuration_link')) { %>