Skip to content

Commit

Permalink
feat: add mfe control setting
Browse files Browse the repository at this point in the history
To use the learning mfe now you also need the setting
`USE_LEGACY_FRONTEND` by tenant.

feat: use function to verify lgacy frontend

feat: improve docstring

style: add type hints

feat: update long line for large conditional

feat: move imports for good practices

move the import for utils and toogles and seems withou problems
  • Loading branch information
johanseto authored and MaferMazu committed Nov 29, 2023
1 parent d21ef9e commit 0255636
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lms/djangoapps/course_home_api/toggles.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from edx_toggles.toggles import LegacyWaffleFlagNamespace

from lms.lib.utils import use_learning_legacy_frontend
from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag

WAFFLE_FLAG_NAMESPACE = LegacyWaffleFlagNamespace(name='course_home')
Expand All @@ -26,7 +27,10 @@


def course_home_legacy_is_active(course_key):
return COURSE_HOME_USE_LEGACY_FRONTEND.is_enabled(course_key) or course_key.deprecated
return (
use_learning_legacy_frontend() and
(COURSE_HOME_USE_LEGACY_FRONTEND.is_enabled(course_key) or course_key.deprecated)
)


def course_home_mfe_progress_tab_is_active(course_key):
Expand Down
3 changes: 2 additions & 1 deletion lms/djangoapps/courseware/toggles.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from edx_toggles.toggles import LegacyWaffleFlagNamespace, SettingToggle
from opaque_keys.edx.keys import CourseKey

from lms.lib.utils import use_learning_legacy_frontend
from openedx.core.djangoapps.waffle_utils import CourseWaffleFlag

# Namespace for courseware waffle flags.
Expand Down Expand Up @@ -140,7 +141,7 @@ def courseware_mfe_is_active(course_key: CourseKey) -> bool:
return False
# NO: MFE courseware can be disabled for users/courses/globally via this
# Waffle flag.
if COURSEWARE_USE_LEGACY_FRONTEND.is_enabled(course_key):
if use_learning_legacy_frontend() and COURSEWARE_USE_LEGACY_FRONTEND.is_enabled(course_key):
return False
# NO: Course preview doesn't work in the MFE
if in_preview_mode():
Expand Down
14 changes: 14 additions & 0 deletions lms/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Helper methods for the LMS.
"""

from django.conf import settings


def get_parent_unit(xblock):
"""
Expand Down Expand Up @@ -44,3 +46,15 @@ def is_unit(xblock):
"""

return get_parent_unit(xblock) is None and xblock.get_parent()


def use_learning_legacy_frontend() -> bool:
"""
Checks in django settings if use the learning legacy
frontend instead the learning mfe.
Returns:
True if the legacy frontend setting is activated, by default
legacy would be activated.
"""
return bool(getattr(settings, "USE_LEARNING_LEGACY_FRONTEND", True))

0 comments on commit 0255636

Please sign in to comment.