Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions lms/djangoapps/courseware/toggles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
Toggles for courseware in-course experience.
"""

from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag, WaffleFlagNamespace

# Namespace for courseware waffle flags.
WAFFLE_FLAG_NAMESPACE = WaffleFlagNamespace(name='courseware')

# Waffle flag to redirect to another learner profile experience.
# .. toggle_name: courseware.redirect_to_microfrontend
# .. toggle_implementation: CourseWaffleFlag
# .. toggle_default: False
# .. toggle_description: Supports staged rollout of a new micro-frontend-based implementation of the courseware page.
# .. toggle_category: micro-frontend
# .. toggle_use_cases: incremental_release, open_edx
# .. toggle_creation_date: 2020-01-29
# .. toggle_expiration_date: 2020-12-31
# .. toggle_warnings: Also set settings.LEARNING_MICROFRONTEND_URL and ENABLE_COURSEWARE_MICROFRONTEND.
# .. toggle_tickets: TNL-6982
# .. toggle_status: supported
REDIRECT_TO_COURSEWARE_MICROFRONTEND = CourseWaffleFlag(WAFFLE_FLAG_NAMESPACE, 'redirect_to_microfrontend')


def should_redirect_to_courseware_microfrontend(course_key):
return (
configuration_helpers.get_value('ENABLE_COURSEWARE_MICROFRONTEND') and
REDIRECT_TO_COURSEWARE_MICROFRONTEND.is_enabled(course_key)
)
44 changes: 44 additions & 0 deletions lms/djangoapps/courseware/url_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


import six
from django.conf import settings
from django.urls import reverse
from six.moves.urllib.parse import urlencode # pylint: disable=import-error

Expand Down Expand Up @@ -52,3 +53,46 @@ def get_redirect_url(course_key, usage_key, request=None):
)
redirect_url += "?{}".format(urlencode({'activate_block_id': six.text_type(final_target_id)}))
return redirect_url


def get_microfrontend_redirect_url(course_key, path=None):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who is the caller of this? Is path always derived from sanitized information that we have (i.e. real blocks), or does it sometimes get provided by the browser calling?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be that I should just remove this method from the PR. It was being called by redirects which I removed from this PR, and will be again when we put those back in. It's not currently in use, which now that I say it out loud, probably means I should just pull it for now. 😄

The path is derived from path_to_location when it's used, so yes, I believe it's always sanitized.

"""
The micro-frontend determines the user's position in the vertical via
a separate API call, so all we need here is the course_key, section, and vertical
IDs to format it's URL.

It is also capable of determining our section and vertical if they're not present. Fully
specifying it all is preferable, though, as the micro-frontend can save itself some work,
resulting in a better user experience.

We're building a URL like this:

http://localhost:2000/course-v1:edX+DemoX+Demo_Course/block-v1:edX+DemoX+Demo_Course+type@sequential+block@19a30717eff543078a5d94ae9d6c18a5/block-v1:edX+DemoX+Demo_Course+type@vertical+block@4a1bba2a403f40bca5ec245e945b0d76
"""

redirect_url = '{base_url}/{prefix}/{course_key}'.format(
base_url=settings.LEARNING_MICROFRONTEND_URL,
prefix='course',
course_key=course_key
)

if path is None:
return redirect_url

# The first four elements of the path list are the ones we care about here:
# - course
# - chapter
# - sequence
# - vertical
# We skip course because we already have it from our argument above, and we skip chapter
# because the micro-frontend URL doesn't include it.
if len(path) > 2:
redirect_url += '/{sequence_key}'.format(
sequence_key=path[2]
)
if len(path) > 3:
redirect_url += '/{vertical_key}'.format(
vertical_key=path[3]
)

return redirect_url
2 changes: 1 addition & 1 deletion lms/envs/devstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,4 +295,4 @@ def should_show_debug_toolbar(request):
EDXNOTES_CLIENT_NAME = 'edx_notes_api-backend-service'

############## Settings for Microfrontends #########################
LEARNING_MICROFRONTEND_URL = 'http://localhost:2000/'
LEARNING_MICROFRONTEND_URL = 'http://localhost:2000'
1 change: 1 addition & 0 deletions lms/envs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@
PROFILE_MICROFRONTEND_URL = "http://profile-mfe/abc/"
ORDER_HISTORY_MICROFRONTEND_URL = "http://order-history-mfe/"
ACCOUNT_MICROFRONTEND_URL = "http://account-mfe/"
LEARNING_MICROFRONTEND_URL = "http://learning-mfe"

########################## limiting dashboard courses ######################

Expand Down