diff --git a/lms/djangoapps/gating/tests/test_integration.py b/lms/djangoapps/gating/tests/test_integration.py index 55ffd00083..2112f89523 100644 --- a/lms/djangoapps/gating/tests/test_integration.py +++ b/lms/djangoapps/gating/tests/test_integration.py @@ -100,6 +100,17 @@ class TestGatedContent(MilestonesTestCaseMixin, SharedModuleStoreTestCase): category='problem', display_name='gating problem 1', ) + # add a discussion block to the prerequisite subsection + # this should give us ability to test gating with blocks + # which needs to be excluded from completion tracking + ItemFactory.create( + parent_location=cls.seq1.location, + category="discussion", + discussion_id="discussion 1", + discussion_category="discussion category", + discussion_target="discussion target", + ) + cls.gated_prob2 = ItemFactory.create( parent_location=cls.seq2.location, category='problem', diff --git a/openedx/core/lib/gating/api.py b/openedx/core/lib/gating/api.py index 3e6ed5db77..60fd130333 100644 --- a/openedx/core/lib/gating/api.py +++ b/openedx/core/lib/gating/api.py @@ -16,6 +16,7 @@ from milestones import api as milestones_api from opaque_keys.edx.keys import UsageKey from openedx.core.lib.gating.exceptions import GatingValidationError from util import milestones_helpers +from xblock.completable import XBlockCompletionMode as CompletionMode from xmodule.modulestore.django import modulestore from xmodule.modulestore.exceptions import ItemNotFoundError @@ -463,10 +464,15 @@ def get_subsection_completion_percentage(subsection_usage_key, user): try: subsection_structure = get_course_blocks(user, subsection_usage_key) if any(subsection_structure): - completable_blocks = [ - block for block in subsection_structure - if block.block_type not in ['chapter', 'sequential', 'vertical'] - ] + completable_blocks = [] + for block in subsection_structure: + completion_mode = subsection_structure.get_xblock_field( + block, 'completion_mode' + ) + + if completion_mode not in (CompletionMode.AGGREGATOR, CompletionMode.EXCLUDED): + completable_blocks.append(block) + if not completable_blocks: return 0 subsection_completion_total = 0