Skip to content

Commit

Permalink
feat: add mfe control setting (#787)
Browse files Browse the repository at this point in the history
* feat: add mfe control setting

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

* fix: update py2neo

* docs: add deprecation message

---------

Co-authored-by: Johan Castiblanco <[email protected]>
Co-authored-by: Alejandro Cardenas <[email protected]>
  • Loading branch information
3 people authored Dec 6, 2023
1 parent d21ef9e commit 026c167
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 6 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
17 changes: 17 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,18 @@ def is_unit(xblock):
"""

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


def use_learning_legacy_frontend() -> bool:
"""
THIS WILL BE OBSOLETE FROM VERSIONS HIGHER THAN NUTMEG
https://docs.openedx.org/en/latest/community/release_notes/olive.html#learning-mfe-is-now-required
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))
2 changes: 1 addition & 1 deletion requirements/edx/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ openedx-filters # Open edX Filters from Hooks Extension Fram
ora2
piexif # Exif image metadata manipulation, used in the profile_images app
Pillow # Image manipulation library; used for course assets, profile images, invoice PDFs, etc.
py2neo # Driver for converting Python modulestore structures to Neo4j's schema (for Coursegraph).
py2neo @ https://github.com/overhangio/py2neo/releases/download/2021.2.3/py2neo-2021.2.3.tar.gz
pycountry
pycryptodomex
pygments # Used to support colors in paver command output
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ psutil==5.9.0
# via
# -r requirements/edx/paver.txt
# edx-django-utils
py2neo==2021.2.3
py2neo @ https://github.com/overhangio/py2neo/releases/download/2021.2.3/py2neo-2021.2.3.tar.gz
# via
# -c requirements/edx/../constraints.txt
# -r requirements/edx/base.in
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ py==1.11.0
# pytest
# pytest-forked
# tox
py2neo==2021.2.3
py2neo @ https://github.com/overhangio/py2neo/releases/download/2021.2.3/py2neo-2021.2.3.tar.gz
# via
# -c requirements/edx/../constraints.txt
# -r requirements/edx/testing.txt
Expand Down
2 changes: 1 addition & 1 deletion requirements/edx/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ py==1.11.0
# pytest
# pytest-forked
# tox
py2neo==2021.2.3
py2neo @ https://github.com/overhangio/py2neo/releases/download/2021.2.3/py2neo-2021.2.3.tar.gz
# via
# -c requirements/edx/../constraints.txt
# -r requirements/edx/base.txt
Expand Down

0 comments on commit 026c167

Please sign in to comment.