Skip to content

Commit

Permalink
fix: course progress url returned based on the course_home_mfe_progre…
Browse files Browse the repository at this point in the history
…ss_tab waffle flag
  • Loading branch information
FatemeKhodayari committed Mar 31, 2024
1 parent cb6801d commit fad574f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lms/djangoapps/learner_home/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from common.djangoapps.course_modes.models import CourseMode
from openedx.features.course_experience import course_home_url
from xmodule.data import CertificatesDisplayBehaviors
from lms.djangoapps.learner_home.utils import course_progress_url


class LiteralField(serializers.Field):
Expand Down Expand Up @@ -116,7 +117,7 @@ def get_homeUrl(self, instance):
return course_home_url(instance.course_id)

def get_progressUrl(self, instance):
return reverse("progress", kwargs={"course_id": instance.course_id})
return course_progress_url(instance.course_id)

def get_unenrollUrl(self, instance):
return reverse("course_run_refund_status", args=[instance.course_id])
Expand Down
13 changes: 13 additions & 0 deletions lms/djangoapps/learner_home/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from openedx.core.djangoapps.content.course_overviews.tests.factories import (
CourseOverviewFactory,
)
from lms.djangoapps.course_home_api.toggles import course_home_mfe_progress_tab_is_active
from lms.djangoapps.learner_home.serializers import (
CertificateSerializer,
CourseProviderSerializer,
Expand Down Expand Up @@ -224,6 +225,18 @@ def test_missing_resume_url(self):
# Then the resumeUrl is None, which is allowed
self.assertIsNone(output_data["resumeUrl"])

def test_progress_url(self):
input_data = self.create_test_enrollment()
input_context = self.create_test_context(input_data.course.id)
output_data = CourseRunSerializer(input_data, context=input_context).data

# Generate expected progress URL based on the status of the course_home_mfe_progress_tab waffle flag
if course_home_mfe_progress_tab_is_active(input_data.course.id):
expected_progress_url = f'{settings.LEARNING_MICROFRONTEND_URL}/course/{input_data.course.id}/progress'
else:
expected_progress_url = f'/courses/{input_data.course.id}/progress'
self.assertEqual(output_data['progressUrl'], expected_progress_url)


@ddt.ddt
class TestCoursewareAccessSerializer(LearnerDashboardBaseTest):
Expand Down
14 changes: 14 additions & 0 deletions lms/djangoapps/learner_home/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

import logging

from django.urls import reverse
from django.contrib.auth import get_user_model
from django.core.exceptions import MultipleObjectsReturned
from rest_framework.exceptions import PermissionDenied, NotFound

from common.djangoapps.student.models import (
get_user_by_username_or_email,
)
from lms.djangoapps.course_home_api.toggles import course_home_mfe_progress_tab_is_active
from openedx.features.course_experience.url_helpers import get_learning_mfe_home_url

log = logging.getLogger(__name__)
User = get_user_model()
Expand Down Expand Up @@ -54,3 +57,14 @@ def get_masquerade_user(request):
)
log.info(success_msg)
return masquerade_user


def course_progress_url(course_key) -> str:
"""
Returns the course progress page's URL for the current user.
Arguments:
course_key (CourseKey): The course key for which the home url is being requested.
"""
if course_home_mfe_progress_tab_is_active(course_key):
return get_learning_mfe_home_url(course_key, url_fragment='progress')
return reverse('progress', kwargs={'course_id': course_key})

0 comments on commit fad574f

Please sign in to comment.