Skip to content

Commit

Permalink
feat: Add toggle to allow redirecting to courseware after enrollment.
Browse files Browse the repository at this point in the history
This change adds a new waffle switch to redirect a student to coursware after
enrolment instead of the dashboard.
  • Loading branch information
xitij2000 committed Feb 14, 2023
1 parent 2b6c0b4 commit dbce322
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
14 changes: 14 additions & 0 deletions common/djangoapps/student/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from django.test import TestCase, override_settings
from django.test.client import Client
from django.urls import reverse
from edx_toggles.toggles.testutils import override_waffle_switch
from markupsafe import escape
from opaque_keys.edx.keys import CourseKey
from opaque_keys.edx.locations import CourseLocator
Expand All @@ -35,6 +36,7 @@
user_by_anonymous_id
)
from common.djangoapps.student.tests.factories import CourseEnrollmentFactory, UserFactory
from common.djangoapps.student.toggles import REDIRECT_TO_COURSEWARE_AFTER_ENROLLMENT
from common.djangoapps.student.views import complete_course_mode_info
from common.djangoapps.util.model_utils import USER_SETTINGS_CHANGED_EVENT_NAME
from common.djangoapps.util.testing import EventTestMixin
Expand Down Expand Up @@ -900,6 +902,7 @@ def test_change_enrollment_modes(self):


@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
@ddt.ddt
class ChangeEnrollmentViewTest(ModuleStoreTestCase):
"""Tests the student.views.change_enrollment view"""

Expand All @@ -920,6 +923,17 @@ def _enroll_through_view(self, course):
)
return response

@ddt.data(
(True, 'courseware'),
(False, None),
)
@ddt.unpack
def test_enrollment_url(self, waffle_flag_enabled, returned_view):
with override_waffle_switch(REDIRECT_TO_COURSEWARE_AFTER_ENROLLMENT, waffle_flag_enabled):
response = self._enroll_through_view(self.course)
data = reverse(returned_view, args=[str(self.course.id)]) if returned_view else ''
assert response.content.decode('utf8') == data

def test_enroll_as_default(self):
"""Tests that a student can successfully enroll through this view"""
response = self._enroll_through_view(self.course)
Expand Down
24 changes: 24 additions & 0 deletions common/djangoapps/student/toggles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Toggles for Dashboard page.
"""
from edx_toggles.toggles import WaffleSwitch

# Namespace for student waffle flags.
WAFFLE_FLAG_NAMESPACE = 'student'

# Waffle flag to enable control redirecting after enrolment.
# .. toggle_name: student.redirect_to_courseware_after_enrollment
# .. toggle_implementation: WaffleSwitch
# .. toggle_default: False
# .. toggle_description: Redirect to courseware after enrollment instead of dashboard.
# .. toggle_use_cases: open_edx
# .. toggle_creation_date: 2023-02-06
# .. toggle_target_removal_date: None
# .. toggle_warning: None
REDIRECT_TO_COURSEWARE_AFTER_ENROLLMENT = WaffleSwitch(
f'{WAFFLE_FLAG_NAMESPACE}.redirect_to_courseware_after_enrollment', __name__
)


def should_redirect_to_courseware_after_enrollment():
return REDIRECT_TO_COURSEWARE_AFTER_ENROLLMENT.is_enabled()
7 changes: 5 additions & 2 deletions common/djangoapps/student/views/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from rest_framework.decorators import api_view, authentication_classes, permission_classes
from rest_framework.permissions import IsAuthenticated

from common.djangoapps.student.toggles import should_redirect_to_courseware_after_enrollment
from common.djangoapps.track import views as track_views
from lms.djangoapps.bulk_email.models import Optout
from common.djangoapps.course_modes.models import CourseMode
Expand Down Expand Up @@ -400,8 +401,10 @@ def change_enrollment(request, check_access=True):
reverse("course_modes_choose", kwargs={'course_id': str(course_id)})
)

# Otherwise, there is only one mode available (the default)
return HttpResponse()
if should_redirect_to_courseware_after_enrollment():
return HttpResponse(reverse('courseware', args=[str(course_id)]))
else:
return HttpResponse()
elif action == "unenroll":
if configuration_helpers.get_value(
"DISABLE_UNENROLLMENT",
Expand Down

0 comments on commit dbce322

Please sign in to comment.