From 95fa31f126b0d9e1c2c3ec402503d228997635d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrey=20Ca=C3=B1on?= <36200299+andrey-canon@users.noreply.github.com> Date: Tue, 3 Dec 2024 13:20:41 -0500 Subject: [PATCH] feat: control linked account by settings (#39) * feat: control linked account by settings This feature allows to control the tab linked_accounts in account settings to appear or not. Is controlled using `SHOW_LINKED_ACCOUNTS` (cherry picked from commit 95cad8db1ef9717b46d8c17fc98ce3a42d614715) * feat: don't support site_configuration use general settings instead --- .../student_account/views/account_settings_factory.js | 2 ++ .../js/student_account/views/account_settings_view.js | 9 ++++++--- lms/templates/student_account/account_settings.html | 1 + .../djangoapps/user_api/accounts/settings_views.py | 4 +++- openedx/core/djangoapps/user_api/accounts/toggles.py | 10 ++++++++-- 5 files changed, 20 insertions(+), 6 deletions(-) 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 70d3ad205c10..31164a6c10ed 100644 --- a/lms/static/js/student_account/views/account_settings_factory.js +++ b/lms/static/js/student_account/views/account_settings_factory.js @@ -15,6 +15,7 @@ return function( fieldsData, disableOrderHistoryTab, + showLinkedAccountsTab, ordersHistoryData, authData, passwordResetSupportUrl, @@ -442,6 +443,7 @@ }, userPreferencesModel: userPreferencesModel, disableOrderHistoryTab: disableOrderHistoryTab, + showLinkedAccountsTab: showLinkedAccountsTab, 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 6ee9c9101d6c..eb9c28e7eec3 100644 --- a/lms/static/js/student_account/views/account_settings_view.js +++ b/lms/static/js/student_account/views/account_settings_view.js @@ -39,15 +39,18 @@ selected: true, expanded: true }, - { + ]; + + if (view.options.showLinkedAccountsTab) { + accountSettingsTabs.push({ name: 'accountsTabSections', id: 'accounts-tab', label: gettext('Linked Accounts'), tabindex: -1, selected: false, expanded: false - } - ]; + }); + } if (!view.options.disableOrderHistoryTab) { accountSettingsTabs.push({ name: 'ordersTabSections', diff --git a/lms/templates/student_account/account_settings.html b/lms/templates/student_account/account_settings.html index 2748dc03792d..ed9de5da9ff1 100644 --- a/lms/templates/student_account/account_settings.html +++ b/lms/templates/student_account/account_settings.html @@ -53,6 +53,7 @@ AccountSettingsFactory( fieldsData, ${ disable_order_history_tab | n, dump_js_escaped_json }, + ${ show_linked_accounts_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 79e01e0bf043..1fac53e573a7 100644 --- a/openedx/core/djangoapps/user_api/accounts/settings_views.py +++ b/openedx/core/djangoapps/user_api/accounts/settings_views.py @@ -30,7 +30,8 @@ from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers from openedx.core.djangoapps.user_api.accounts.toggles import ( should_redirect_to_account_microfrontend, - should_redirect_to_order_history_microfrontend + should_redirect_to_order_history_microfrontend, + should_show_linked_accounts_tab ) from openedx.core.djangoapps.user_api.preferences.api import get_user_preferences from openedx.core.lib.edx_api_utils import get_api_data @@ -159,6 +160,7 @@ def account_settings_context(request): 'show_dashboard_tabs': True, 'order_history': user_orders, 'disable_order_history_tab': should_redirect_to_order_history_microfrontend(), + 'show_linked_accounts_tab': should_show_linked_accounts_tab(), 'enable_account_deletion': configuration_helpers.get_value( 'ENABLE_ACCOUNT_DELETION', settings.FEATURES.get('ENABLE_ACCOUNT_DELETION', False) ), diff --git a/openedx/core/djangoapps/user_api/accounts/toggles.py b/openedx/core/djangoapps/user_api/accounts/toggles.py index 80de4fa75692..0e14a63248d6 100644 --- a/openedx/core/djangoapps/user_api/accounts/toggles.py +++ b/openedx/core/djangoapps/user_api/accounts/toggles.py @@ -1,9 +1,8 @@ """ Toggles for accounts related code. """ - +from django.conf import settings from edx_toggles.toggles import WaffleFlag - from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers # .. toggle_name: order_history.redirect_to_microfrontend @@ -26,6 +25,13 @@ def should_redirect_to_order_history_microfrontend(): ) +def should_show_linked_accounts_tab(): + """Check if the the var `SHOW_LINKED_ACCOUNTS` + is defined in configuration helpers. + """ + return getattr(settings, 'SHOW_LINKED_ACCOUNTS', True) + + # .. toggle_name: account.redirect_to_microfrontend # .. toggle_implementation: WaffleFlag # .. toggle_default: False