Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: get mfe urls from site configurations #444

Merged
merged 1 commit into from
Nov 3, 2023
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
6 changes: 5 additions & 1 deletion cms/djangoapps/contentstore/views/course.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,14 +579,18 @@ def format_in_process_course_view(uca):
active_courses, archived_courses = _process_courses_list(courses_iter, in_process_course_actions, split_archived)
in_process_course_actions = [format_in_process_course_view(uca) for uca in in_process_course_actions]

library_authoring_mfe_url = configuration_helpers.get_value(
'LIBRARY_AUTHORING_MICROFRONTEND_URL', LIBRARY_AUTHORING_MICROFRONTEND_URL
)

return render_to_response('index.html', {
'courses': active_courses,
'split_studio_home': split_library_view_on_dashboard(),
'archived_courses': archived_courses,
'in_process_course_actions': in_process_course_actions,
'libraries_enabled': LIBRARIES_ENABLED,
'redirect_to_library_authoring_mfe': should_redirect_to_library_authoring_mfe(),
'library_authoring_mfe_url': LIBRARY_AUTHORING_MICROFRONTEND_URL,
'library_authoring_mfe_url': library_authoring_mfe_url,
'libraries': [_format_library_for_view(lib, request) for lib in libraries],
'show_new_library_button': user_can_create_library(user) and not should_redirect_to_library_authoring_mfe(),
'user': user,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ def send_password_reset_email(self, user, site):
message_context = get_base_template_context(site)
email = user.email
if should_redirect_to_authn_microfrontend():
site_url = settings.AUTHN_MICROFRONTEND_URL
site_url = configuration_helpers.get_value(
"AUTHN_MICROFRONTEND_URL", settings.AUTHN_MICROFRONTEND_URL
)
else:
site_url = configuration_helpers.get_value('SITE_NAME', settings.SITE_NAME)
message_context.update({
Expand Down
5 changes: 4 additions & 1 deletion common/djangoapps/student/views/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,10 @@ def student_dashboard(request): # lint-amnesty, pylint: disable=too-many-statem
return redirect(reverse('account_settings'))

if should_redirect_to_learner_home_mfe(user):
return redirect(settings.LEARNER_HOME_MICROFRONTEND_URL)
learner_home_mfe_url = configuration_helpers.get_value(
"LEARNER_HOME_MICROFRONTEND_URL", settings.LEARNER_HOME_MICROFRONTEND_URL
)
return redirect(learner_home_mfe_url)

platform_name = configuration_helpers.get_value("platform_name", settings.PLATFORM_NAME)

Expand Down
5 changes: 4 additions & 1 deletion common/djangoapps/student/views/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,10 @@ def activate_account(request, key):
if redirect_url:
params['next'] = redirect_url
url_path = '/login?{}'.format(urllib.parse.urlencode(params))
return redirect(settings.AUTHN_MICROFRONTEND_URL + url_path)
authn_mfe_url = configuration_helpers.get_value(
"AUTHN_MICROFRONTEND_URL", settings.AUTHN_MICROFRONTEND_URL
)
return redirect(authn_mfe_url + url_path)

response = redirect(redirect_url) if redirect_url and is_enterprise_learner(request.user) else redirect('dashboard')
if show_account_activation_popup:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ def send_ace_message(goal):

course_home_url = get_learning_mfe_home_url(course_key=goal.course_key, url_fragment='home')

goals_unsubscribe_url = f'{settings.LEARNING_MICROFRONTEND_URL}/goal-unsubscribe/{goal.unsubscribe_token}'
learning_mfe_url = configuration_helpers.get_value(
"LEARNING_MICROFRONTEND_URL", settings.LEARNING_MICROFRONTEND_URL
)
goals_unsubscribe_url = f'{learning_mfe_url}/goal-unsubscribe/{goal.unsubscribe_token}'

language = get_user_preference(user, LANGUAGE_KEY)

Expand Down
13 changes: 10 additions & 3 deletions lms/djangoapps/discussion/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
from openedx.core.djangoapps.django_comment_common.utils import ThreadContext
from openedx.core.djangoapps.plugin_api.views import EdxFragmentView
from openedx.features.course_duration_limits.access import generate_course_expired_fragment
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers

User = get_user_model()
log = logging.getLogger("edx.discussions")
Expand Down Expand Up @@ -274,7 +275,9 @@ def redirect_forum_url_to_new_mfe(request, course_id):

redirect_url = None
if discussions_mfe_enabled:
mfe_base_url = settings.DISCUSSIONS_MICROFRONTEND_URL
mfe_base_url = configuration_helpers.get_value(
"DISCUSSIONS_MICROFRONTEND_URL", settings.DISCUSSIONS_MICROFRONTEND_URL
)
redirect_url = f"{mfe_base_url}/{str(course_key)}"
return redirect_url

Expand Down Expand Up @@ -334,7 +337,9 @@ def redirect_thread_url_to_new_mfe(request, course_id, thread_id):
discussions_mfe_enabled = ENABLE_DISCUSSIONS_MFE.is_enabled(course_key)
redirect_url = None
if discussions_mfe_enabled:
mfe_base_url = settings.DISCUSSIONS_MICROFRONTEND_URL
mfe_base_url = configuration_helpers.get_value(
"DISCUSSIONS_MICROFRONTEND_URL", settings.DISCUSSIONS_MICROFRONTEND_URL
)
if thread_id:
redirect_url = f"{mfe_base_url}/{str(course_key)}/posts/{thread_id}"
return redirect_url
Expand Down Expand Up @@ -654,7 +659,9 @@ def user_profile(request, course_key, user_id):
else:
discussions_mfe_enabled = ENABLE_DISCUSSIONS_MFE.is_enabled(course_key)
if discussions_mfe_enabled:
mfe_base_url = settings.DISCUSSIONS_MICROFRONTEND_URL
mfe_base_url = configuration_helpers.get_value(
"DISCUSSIONS_MICROFRONTEND_URL", settings.DISCUSSIONS_MICROFRONTEND_URL
)
return redirect(f"{mfe_base_url}/{str(course_key)}/learners")

tab_view = CourseTabView()
Expand Down
5 changes: 4 additions & 1 deletion lms/djangoapps/instructor/views/instructor_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,9 +700,12 @@ def _section_send_email(course, access):
),
}
if settings.FEATURES.get("ENABLE_NEW_BULK_EMAIL_EXPERIENCE", False) is not False:
communication_mfe_url = configuration_helpers.get_value(
"COMMUNICATIONS_MICROFRONTEND_URL", settings.COMMUNICATIONS_MICROFRONTEND_URL
)
section_data[
"communications_mfe_url"
] = f"{settings.COMMUNICATIONS_MICROFRONTEND_URL}/courses/{str(course_key)}/bulk_email"
] = f"{communication_mfe_url}/courses/{str(course_key)}/bulk_email"
return section_data


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,12 @@ def send_verification_expiry_email(self, batch_verifications, email_config):

site = Site.objects.get_current()
message_context = get_base_template_context(site)
account_mfe_url = configuration_helpers.get_value(
"ACCOUNT_MICROFRONTEND_URL", settings.ACCOUNT_MICROFRONTEND_URL
)
message_context.update({
'platform_name': settings.PLATFORM_NAME,
'lms_verification_link': f'{settings.ACCOUNT_MICROFRONTEND_URL}/id-verification',
'lms_verification_link': f'{account_mfe_url}/id-verification',
'help_center_link': settings.ID_VERIFICATION_SUPPORT_LINK
})

Expand Down
5 changes: 4 additions & 1 deletion lms/djangoapps/verify_student/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,10 @@ def get_verify_location(cls, course_id=None):
Returns a string:
Returns URL for IDV on Account Microfrontend
"""
location = f'{settings.ACCOUNT_MICROFRONTEND_URL}/id-verification'
account_mfe_url = configuration_helpers.get_value(
"ACCOUNT_MICROFRONTEND_URL", settings.ACCOUNT_MICROFRONTEND_URL
)
location = f'{account_mfe_url}/id-verification'
if course_id:
location += f'?course_id={quote(str(course_id))}'
return location
Expand Down
5 changes: 4 additions & 1 deletion lms/djangoapps/verify_student/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,9 +1120,12 @@ def results_callback(request): # lint-amnesty, pylint: disable=too-many-stateme
send_verification_approved_email(context=email_context)

elif result == "FAIL":
account_mfe_url = configuration_helpers.get_value(
"ACCOUNT_MICROFRONTEND_URL", settings.ACCOUNT_MICROFRONTEND_URL
)
log.debug("Denying verification for %s", receipt_id)
attempt.deny(json.dumps(reason), error_code=error_code)
reverify_url = f'{settings.ACCOUNT_MICROFRONTEND_URL}/id-verification'
reverify_url = f'{account_mfe_url}/id-verification'
verification_status_email_vars['reasons'] = reason
verification_status_email_vars['reverify_url'] = reverify_url
verification_status_email_vars['faq_url'] = settings.ID_VERIFICATION_SUPPORT_LINK
Expand Down
9 changes: 7 additions & 2 deletions lms/templates/header/navbar-not-authenticated.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from six import text_type

from openedx.core.djangoapps.user_authn.toggles import should_redirect_to_authn_microfrontend
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
%>

<%
Expand All @@ -21,6 +22,9 @@
can_discover_courses = settings.FEATURES.get('ENABLE_COURSE_DISCOVERY')
allow_public_account_creation = static.get_value('ALLOW_PUBLIC_ACCOUNT_CREATION', settings.FEATURES.get('ALLOW_PUBLIC_ACCOUNT_CREATION'))
should_redirect_to_authn_mfe = should_redirect_to_authn_microfrontend()
authn_mfe_url = configuration_helpers.get_value(
"AUTHN_MICROFRONTEND_URL", settings.AUTHN_MICROFRONTEND_URL
)
%>
<nav class="nav-links" aria-label=${_("Supplemental Links")}>
<div class="main">
Expand Down Expand Up @@ -51,7 +55,7 @@
% if allow_public_account_creation and not disable_register_button:
% if should_redirect_to_authn_mfe:
<div class="mobile-nav-item hidden-mobile nav-item">
<a class="register-btn btn" href="${settings.AUTHN_MICROFRONTEND_URL}/register${login_query()}">${_("Register for free")}</a>
<a class="register-btn btn" href="${authn_mfe_url}/register${login_query()}">${_("Register for free")}</a>
</div>
% else:
<div class="mobile-nav-item hidden-mobile nav-item">
Expand All @@ -61,7 +65,7 @@
% endif
% if should_redirect_to_authn_mfe:
<div class="mobile-nav-item hidden-mobile nav-item">
<a class="sign-in-btn btn" href="${settings.AUTHN_MICROFRONTEND_URL}/login${login_query()}">${_("Sign in")}</a>
<a class="sign-in-btn btn" href="${authn_mfe_url}/login${login_query()}">${_("Sign in")}</a>
</div>
% else:
<div class="mobile-nav-item hidden-mobile nav-item">
Expand All @@ -72,3 +76,4 @@
</div>
</div>
</nav>

6 changes: 5 additions & 1 deletion lms/templates/header/user_dropdown.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from openedx.core.djangoapps.user_api.accounts.image_helpers import get_profile_image_urls_for_user
from openedx.core.djangoapps.user_api.accounts.toggles import should_redirect_to_order_history_microfrontend
from openedx.features.enterprise_support.utils import get_enterprise_learner_generic_name, get_enterprise_learner_portal
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
%>

<%
Expand All @@ -24,6 +25,9 @@
## Enterprises with the learner portal enabled should not show order history, as it does
## not apply to the learner's method of purchasing content.
should_show_order_history = should_redirect_to_order_history_microfrontend() and not enterprise_customer_portal
order_history_mfe_url = configuration_helpers.get_value(
"ORDER_HISTORY_MICROFRONTEND_URL", settings.ORDER_HISTORY_MICROFRONTEND_URL
)
%>

<div class="nav-item hidden-mobile">
Expand All @@ -47,7 +51,7 @@
<div class="mobile-nav-item dropdown-item dropdown-nav-item"><a href="${reverse('learner_profile', kwargs={'username': username})}" role="menuitem">${_("Profile")}</a></div>
<div class="mobile-nav-item dropdown-item dropdown-nav-item"><a href="${reverse('account_settings')}" role="menuitem">${_("Account")}</a></div>
% if should_show_order_history:
<div class="mobile-nav-item dropdown-item dropdown-nav-item"><a href="${settings.ORDER_HISTORY_MICROFRONTEND_URL}" role="menuitem">${_("Order History")}</a></div>
<div class="mobile-nav-item dropdown-item dropdown-nav-item"><a href="${order_history_mfe_url}" role="menuitem">${_("Order History")}</a></div>
% endif
<div class="mobile-nav-item dropdown-item dropdown-nav-item"><a href="${reverse('logout')}" role="menuitem">${_("Sign Out")}</a></div>
</div>
Expand Down
8 changes: 6 additions & 2 deletions openedx/core/djangoapps/discussions/url_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from django.conf import settings
from opaque_keys.edx.keys import CourseKey
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers


def _get_url_with_view_query_params(path: str, view: Optional[str] = None) -> str:
Expand All @@ -20,9 +21,12 @@ def _get_url_with_view_query_params(path: str, view: Optional[str] = None) -> st
(str) URL link for MFE

"""
if settings.DISCUSSIONS_MICROFRONTEND_URL is None:
discussion_mfe_url = configuration_helpers.get_value(
"DISCUSSIONS_MICROFRONTEND_URL", settings.DISCUSSIONS_MICROFRONTEND_URL
)
if discussion_mfe_url is None:
return ''
url = f"{settings.DISCUSSIONS_MICROFRONTEND_URL}/{path}"
url = f"{discussion_mfe_url}/{path}"

query_params = {}
if view == "in_context":
Expand Down
4 changes: 3 additions & 1 deletion openedx/core/djangoapps/user_api/accounts/settings_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def account_settings(request):

"""
if should_redirect_to_account_microfrontend():
url = settings.ACCOUNT_MICROFRONTEND_URL
url = configuration_helpers.get_value(
"ACCOUNT_MICROFRONTEND_URL", settings.ACCOUNT_MICROFRONTEND_URL
)

duplicate_provider = pipeline.get_duplicate_provider(messages.get_messages(request))
if duplicate_provider:
Expand Down
5 changes: 4 additions & 1 deletion openedx/core/djangoapps/user_authn/views/login_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ def login_and_registration_form(request, initial_mode="login"):
initial_mode,
'?' + query_params if query_params else ''
)
return redirect(settings.AUTHN_MICROFRONTEND_URL + url_path)
authn_mfe_url = configuration_helpers.get_value(
"AUTHN_MICROFRONTEND_URL", settings.AUTHN_MICROFRONTEND_URL
)
return redirect(authn_mfe_url + url_path)

# Account activation message
account_activation_messages = [
Expand Down
18 changes: 14 additions & 4 deletions openedx/features/course_experience/url_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from lms.djangoapps.courseware.toggles import courseware_mfe_is_active
from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order
from xmodule.modulestore.search import navigation_index, path_to_location # lint-amnesty, pylint: disable=wrong-import-order
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers

User = get_user_model()

Expand Down Expand Up @@ -158,7 +159,10 @@ def make_learning_mfe_courseware_url(
strings. They're only ever used to concatenate a URL string.
`params` is an optional QueryDict object (e.g. request.GET)
"""
mfe_link = f'{settings.LEARNING_MICROFRONTEND_URL}/course/{course_key}'
learning_mfe_url = configuration_helpers.get_value(
"LEARNING_MICROFRONTEND_URL", settings.LEARNING_MICROFRONTEND_URL
)
mfe_link = f'{learning_mfe_url}/course/{course_key}'

if sequence_key:
mfe_link += f'/{sequence_key}'
Expand Down Expand Up @@ -188,7 +192,10 @@ def get_learning_mfe_home_url(
`url_fragment` is an optional string.
`params` is an optional QueryDict object (e.g. request.GET)
"""
mfe_link = f'{settings.LEARNING_MICROFRONTEND_URL}/course/{course_key}'
learning_mfe_url = configuration_helpers.get_value(
"LEARNING_MICROFRONTEND_URL", settings.LEARNING_MICROFRONTEND_URL
)
mfe_link = f'{learning_mfe_url}/course/{course_key}'

if url_fragment:
mfe_link += f'/{url_fragment}'
Expand All @@ -203,9 +210,12 @@ def is_request_from_learning_mfe(request: HttpRequest):
"""
Returns whether the given request was made by the frontend-app-learning MFE.
"""
if not settings.LEARNING_MICROFRONTEND_URL:
learning_mfe_url = configuration_helpers.get_value(
"LEARNING_MICROFRONTEND_URL", settings.LEARNING_MICROFRONTEND_URL
)
if not learning_mfe_url:
return False

url = urlparse(settings.LEARNING_MICROFRONTEND_URL)
url = urlparse(learning_mfe_url)
mfe_url_base = f'{url.scheme}://{url.netloc}'
return request.META.get('HTTP_REFERER', '').startswith(mfe_url_base)
5 changes: 4 additions & 1 deletion openedx/features/learner_profile/views/learner_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ def learner_profile(request, username):
GET /account/profile
"""
if should_redirect_to_profile_microfrontend():
profile_microfrontend_url = f"{settings.PROFILE_MICROFRONTEND_URL}{username}"
profile_mfe_url = configuration_helpers.get_value(
"PROFILE_MICROFRONTEND_URL", settings.PROFILE_MICROFRONTEND_URL
)
profile_microfrontend_url = f"{profile_mfe_url}{username}"
if request.GET:
profile_microfrontend_url += f'?{request.GET.urlencode()}'
return redirect(profile_microfrontend_url)
Expand Down
Loading