Skip to content

Commit

Permalink
feat(badges): Only show badge progress when enabled for the course.
Browse files Browse the repository at this point in the history
This update sends back no badge progress to the frontend whenever the `Badge` tab is disabled for the course no matter if the learner has earned badge progress.
  • Loading branch information
becdavid committed Jan 18, 2024
1 parent f1ce896 commit 1290b72
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def test_queries(self):

# Fetch the view and verify the query counts
# TODO: decrease query count as part of REVO-28
with self.assertNumQueries(66, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST):
with self.assertNumQueries(70, table_ignorelist=QUERY_COUNT_TABLE_IGNORELIST):
with check_mongo_calls(3):
url = course_home_url(self.course)
self.client.get(url)
Expand Down
12 changes: 11 additions & 1 deletion openedx/features/course_experience/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from opaque_keys.edx.keys import CourseKey

from lms.djangoapps.badges.models import BlockEventBadgesConfiguration
from lms.djangoapps.courseware.tabs import get_course_tab_list
from lms.djangoapps.course_api.blocks.api import get_blocks
from lms.djangoapps.course_blocks.api import get_course_blocks
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
Expand Down Expand Up @@ -114,8 +115,10 @@ def recurse_mark_badge_progress(block):
for block_event_badge_config in BlockEventBadgesConfiguration.config_for_block_event(
course_id=course_key, event_type='chapter_complete'
):
# Indicate the a module has completed badge progress if configured and badges tab
# is enabled for the course.
if block.get('block_id', False) == block_event_badge_config.usage_key.block_id and \
block_event_badge_config.badge_class:
block_event_badge_config.badge_class and course_badge_tab_exists:
block['badge_progress'] = True
return True

Expand Down Expand Up @@ -154,6 +157,13 @@ def recurse_mark_badge_progress(block):
)

course_outline_root_block = all_blocks['blocks'].get(all_blocks['root'], None)

# Identify if the `Badges` tab is enabled.
course_badge_tab_exists = False
for tab in get_course_tab_list(user, CourseOverview.objects.get(id=str(course_key))):
if tab.tab_id == "badges_progress":
course_badge_tab_exists = True

if course_outline_root_block:
populate_children(course_outline_root_block, all_blocks['blocks'])
recurse_mark_scored(course_outline_root_block)
Expand Down

0 comments on commit 1290b72

Please sign in to comment.