diff --git a/lms/envs/common.py b/lms/envs/common.py index 3c66c429d4..d036ccf029 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -3469,6 +3469,9 @@ WRITABLE_GRADEBOOK_URL = None # completely removed and this redirect is no longer needed, we can remove this. PROFILE_MICROFRONTEND_URL = "http://some.profile.spa/u/" +# URL configuration for new microfrontends. +ORDER_HISTORY_MICROFRONTEND_URL = "http://some.order_history.spa/" + ############### Settings for django-fernet-fields ################## FERNET_KEYS = [ 'DUMMY KEY CHANGE BEFORE GOING TO PRODUCTION', diff --git a/lms/static/js/spec/student_account/account_settings_factory_spec.js b/lms/static/js/spec/student_account/account_settings_factory_spec.js index a0be3c7d0a..15447a03ff 100644 --- a/lms/static/js/spec/student_account/account_settings_factory_spec.js +++ b/lms/static/js/spec/student_account/account_settings_factory_spec.js @@ -17,6 +17,7 @@ define(['backbone', var createAccountSettingsPage = function() { var context = AccountSettingsPage( Helpers.FIELDS_DATA, + false, [], Helpers.AUTH_DATA, Helpers.PASSWORD_RESET_SUPPORT_LINK, @@ -153,6 +154,7 @@ define(['backbone', var createEnterpriseLearnerAccountSettingsPage = function() { var context = AccountSettingsPage( Helpers.FIELDS_DATA, + false, [], Helpers.AUTH_DATA, Helpers.PASSWORD_RESET_SUPPORT_LINK, diff --git a/lms/static/js/student_account/views/account_settings_factory.js b/lms/static/js/student_account/views/account_settings_factory.js index 1d7b348924..670f039914 100644 --- a/lms/static/js/student_account/views/account_settings_factory.js +++ b/lms/static/js/student_account/views/account_settings_factory.js @@ -12,6 +12,7 @@ AccountSettingsFieldViews, AccountSettingsView, StringUtils, HtmlUtils) { return function( fieldsData, + disableOrderHistoryTab, ordersHistoryData, authData, passwordResetSupportUrl, @@ -421,6 +422,7 @@ ordersTabSections: ordersSectionData }, userPreferencesModel: userPreferencesModel, + disableOrderHistoryTab: disableOrderHistoryTab, betaLanguage: betaLanguage }); diff --git a/lms/static/js/student_account/views/account_settings_view.js b/lms/static/js/student_account/views/account_settings_view.js index d3dcba2724..bd057d7318 100644 --- a/lms/static/js/student_account/views/account_settings_view.js +++ b/lms/static/js/student_account/views/account_settings_view.js @@ -13,33 +13,6 @@ navLink: '.account-nav-link', activeTab: 'aboutTabSections', - accountSettingsTabs: [ - { - name: 'aboutTabSections', - id: 'about-tab', - label: gettext('Account Information'), - class: 'active', - tabindex: 0, - selected: true, - expanded: true - }, - { - name: 'accountsTabSections', - id: 'accounts-tab', - label: gettext('Linked Accounts'), - tabindex: -1, - selected: false, - expanded: false - }, - { - name: 'ordersTabSections', - id: 'orders-tab', - label: gettext('Order History'), - tabindex: -1, - selected: false, - expanded: false - } - ], events: { 'click .account-nav-link': 'switchTab', 'keydown .account-nav-link': 'keydownHandler', @@ -54,6 +27,36 @@ render: function() { var tabName, betaLangMessage, helpTranslateText, helpTranslateLink, betaLangCode, oldLangCode, view = this; + var accountSettingsTabs = [ + { + name: 'aboutTabSections', + id: 'about-tab', + label: gettext('Account Information'), + class: 'active', + tabindex: 0, + selected: true, + expanded: true + }, + { + name: 'accountsTabSections', + id: 'accounts-tab', + label: gettext('Linked Accounts'), + tabindex: -1, + selected: false, + expanded: false + } + ]; + if (!view.options.disableOrderHistoryTab) { + accountSettingsTabs.push({ + name: 'ordersTabSections', + id: 'orders-tab', + label: gettext('Order History'), + tabindex: -1, + selected: false, + expanded: false + }); + } + if (!_.isEmpty(view.options.betaLanguage) && $.cookie('old-pref-lang')) { betaLangMessage = HtmlUtils.interpolateHtml( gettext('You have set your language to {beta_language}, which is currently not fully translated. You can help us translate this language fully by joining the Transifex community and adding translations from English for learners that speak {beta_language}.'), // eslint-disable-line max-len @@ -77,14 +80,14 @@ $.cookie('focus_id', '#beta-language-message'); } HtmlUtils.setHtml(this.$el, HtmlUtils.template(accountSettingsTemplate)({ - accountSettingsTabs: this.accountSettingsTabs, + accountSettingsTabs: accountSettingsTabs, HtmlUtils: HtmlUtils, message: betaLangMessage, helpTranslateText: helpTranslateText, helpTranslateLink: helpTranslateLink, oldLangCode: oldLangCode })); - _.each(view.accountSettingsTabs, function(tab) { + _.each(accountSettingsTabs, function(tab) { tabName = tab.name; view.renderSection(view.options.tabSections[tabName], tabName, tab.label); }); diff --git a/lms/templates/header/user_dropdown.html b/lms/templates/header/user_dropdown.html index 5fabdb49b0..c4a379e614 100644 --- a/lms/templates/header/user_dropdown.html +++ b/lms/templates/header/user_dropdown.html @@ -3,10 +3,12 @@ <%namespace name='static' file='static_content.html'/> <%! +from django.conf import settings from django.urls import reverse from django.utils.translation import ugettext as _ 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 REDIRECT_TO_ORDER_HISTORY_MICROFRONTEND from openedx.core.djangoapps.user_api.accounts.utils import retrieve_last_sitewide_block_completed from openedx.features.enterprise_support.utils import get_enterprise_learner_generic_name %> @@ -38,6 +40,9 @@ displayname = get_enterprise_learner_generic_name(request) or username + % if REDIRECT_TO_ORDER_HISTORY_MICROFRONTEND.is_enabled(): + + % endif diff --git a/lms/templates/student_account/account_settings.html b/lms/templates/student_account/account_settings.html index 39e1e4db27..4de6bcf944 100644 --- a/lms/templates/student_account/account_settings.html +++ b/lms/templates/student_account/account_settings.html @@ -51,6 +51,7 @@ from openedx.core.djangoapps.user_api.accounts.utils import is_secondary_email_f AccountSettingsFactory( fieldsData, + ${ disable_order_history_tab | n, dump_js_escaped_json }, ordersHistoryData, authData, '${ password_reset_support_link | n, js_escaped_string }', diff --git a/openedx/core/djangoapps/user_api/accounts/settings_views.py b/openedx/core/djangoapps/user_api/accounts/settings_views.py index ea64db1f3c..6442980764 100644 --- a/openedx/core/djangoapps/user_api/accounts/settings_views.py +++ b/openedx/core/djangoapps/user_api/accounts/settings_views.py @@ -19,6 +19,7 @@ from openedx.core.djangoapps.dark_lang.models import DarkLangConfig from openedx.core.djangoapps.lang_pref.api import all_languages, released_languages from openedx.core.djangoapps.programs.models import ProgramsApiConfig from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.djangoapps.user_api.accounts.toggles import REDIRECT_TO_ORDER_HISTORY_MICROFRONTEND from openedx.core.djangoapps.user_api.preferences.api import get_user_preferences from openedx.core.lib.edx_api_utils import get_edx_api_data from openedx.core.lib.time_zone_utils import TIME_ZONE_CHOICES @@ -118,11 +119,12 @@ def account_settings_context(request): 'show_program_listing': ProgramsApiConfig.is_enabled(), 'show_dashboard_tabs': True, 'order_history': user_orders, + 'disable_order_history_tab': REDIRECT_TO_ORDER_HISTORY_MICROFRONTEND.is_enabled(), 'enable_account_deletion': configuration_helpers.get_value( 'ENABLE_ACCOUNT_DELETION', settings.FEATURES.get('ENABLE_ACCOUNT_DELETION', False) ), 'extended_profile_fields': _get_extended_profile_fields(), - 'beta_language': beta_language + 'beta_language': beta_language, } enterprise_customer = get_enterprise_customer_for_learner(site=request.site, user=request.user) diff --git a/openedx/core/djangoapps/user_api/accounts/toggles.py b/openedx/core/djangoapps/user_api/accounts/toggles.py new file mode 100644 index 0000000000..24ecaaae1d --- /dev/null +++ b/openedx/core/djangoapps/user_api/accounts/toggles.py @@ -0,0 +1,18 @@ +""" +Toggles for accounts related code. +""" +from openedx.core.djangoapps.waffle_utils import WaffleFlag + + +# .. toggle_name: REDIRECT_TO_ORDER_HISTORY_MICROFRONTEND +# .. toggle_type: waffle_flag +# .. toggle_default: False +# .. toggle_description: Supports staged rollout of a new micro-frontend-based implementation of the order history page. +# .. toggle_category: micro-frontend +# .. toggle_use_cases: incremental_release, open_edx +# .. toggle_creation_date: 2019-04-11 +# .. toggle_expiration_date: 2020-12-31 +# .. toggle_warnings: Remember to also set ORDER_HISTORY_MICROFRONTEND_URL before this toggle is enabled. +# .. toggle_tickets: DEPR-17 +# .. toggle_status: supported +REDIRECT_TO_ORDER_HISTORY_MICROFRONTEND = WaffleFlag('order_history', 'redirect_to_microfrontend') diff --git a/openedx/core/djangoapps/waffle_utils/__init__.py b/openedx/core/djangoapps/waffle_utils/__init__.py index 4a2eebc8e1..276e72e75c 100644 --- a/openedx/core/djangoapps/waffle_utils/__init__.py +++ b/openedx/core/djangoapps/waffle_utils/__init__.py @@ -305,12 +305,15 @@ class WaffleFlag(object): Initializes the waffle flag instance. Arguments: - waffle_namespace (WaffleFlagNamespace): Provides a cached namespace - for this flag. + waffle_namespace (WaffleFlagNamespace | String): Namespace for this flag. flag_name (String): The name of the flag (without namespacing). flag_undefined_default (Boolean): A default value to be returned if the waffle flag is to be checked, but doesn't exist. """ + if isinstance(waffle_namespace, six.string_types): + waffle_namespace = WaffleFlagNamespace(name=waffle_namespace) + + self.waffle_namespace = waffle_namespace self.waffle_namespace = waffle_namespace self.flag_name = flag_name self.flag_undefined_default = flag_undefined_default