From 65f0f6809d25337494138c7456c0f3b86ed67bd7 Mon Sep 17 00:00:00 2001
From: Diana Huang <dkh@edx.org>
Date: Thu, 31 May 2018 13:22:27 -0400
Subject: [PATCH] Add a configuration option for deleting student accounts.

---
 common/test/acceptance/tests/lms/test_account_settings.py   | 6 +++++-
 lms/djangoapps/student_account/views.py                     | 3 +++
 lms/envs/common.py                                          | 3 +++
 .../js/student_account/views/account_settings_factory.js    | 3 ++-
 lms/templates/student_account/account_settings.html         | 2 ++
 5 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/common/test/acceptance/tests/lms/test_account_settings.py b/common/test/acceptance/tests/lms/test_account_settings.py
index 9ab1139b851..d3b3c8c0c3a 100644
--- a/common/test/acceptance/tests/lms/test_account_settings.py
+++ b/common/test/acceptance/tests/lms/test_account_settings.py
@@ -196,7 +196,11 @@ class AccountSettingsPageTest(AccountSettingsTestMixin, AcceptanceTest):
                     'Facebook Link',
                     'LinkedIn Link',
                 ]
-            }
+            },
+            {
+                'title': 'Delete My Account',
+                'fields': []
+            },
         ]
 
         self.assertEqual(self.account_settings_page.sections_structure(), expected_sections_structure)
diff --git a/lms/djangoapps/student_account/views.py b/lms/djangoapps/student_account/views.py
index 1a9d0e9dfa0..38f9be8d994 100644
--- a/lms/djangoapps/student_account/views.py
+++ b/lms/djangoapps/student_account/views.py
@@ -568,6 +568,9 @@ def account_settings_context(request):
         'show_program_listing': ProgramsApiConfig.is_enabled(),
         'show_dashboard_tabs': True,
         'order_history': user_orders,
+        'enable_account_deletion': configuration_helpers.get_value(
+            'ENABLE_ACCOUNT_DELETION', settings.FEATURES.get('ENABLE_ACCOUNT_DELETION', False)
+        ),
         'extended_profile_fields': _get_extended_profile_fields(),
     }
 
diff --git a/lms/envs/common.py b/lms/envs/common.py
index f456bb7ca8e..338fbe798b7 100644
--- a/lms/envs/common.py
+++ b/lms/envs/common.py
@@ -402,6 +402,9 @@ FEATURES = {
 
     # Set this to true to make API docs available at /api-docs/.
     'ENABLE_API_DOCS': False,
+
+    # Whether to display the account deletion section the account settings page
+    'ENABLE_ACCOUNT_DELETION': True,
 }
 
 # Settings for the course reviews tool template and identification key, set either to None to disable course reviews
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 f1ed9b51923..28bb0b8e14d 100644
--- a/lms/static/js/student_account/views/account_settings_factory.js
+++ b/lms/static/js/student_account/views/account_settings_factory.js
@@ -27,6 +27,7 @@
             enterpriseReadonlyAccountFields,
             edxSupportUrl,
             extendedProfileFields,
+            displayAccountDeletion,
             enableGDPRFlag
         ) {
             var $accountSettingsElement, userAccountModel, userPreferencesModel, aboutSectionsData,
@@ -292,7 +293,7 @@
             aboutSectionsData.push(socialFields);
 
             // Add account deletion fields
-            if (enableGDPRFlag) {
+            if (displayAccountDeletion) {
                 accountDeletionFields = {
                     title: gettext('Delete My Account'),
                     fields: [],
diff --git a/lms/templates/student_account/account_settings.html b/lms/templates/student_account/account_settings.html
index 706c86b3a93..85b57b0eccc 100644
--- a/lms/templates/student_account/account_settings.html
+++ b/lms/templates/student_account/account_settings.html
@@ -48,6 +48,7 @@ from openedx.features.course_experience import ENABLE_GDPR_COMPAT_FLAG
         enterpriseReadonlyAccountFields = ${ enterprise_readonly_account_fields | n, dump_js_escaped_json },
         edxSupportUrl = '${ edx_support_url | n, js_escaped_string }',
         extendedProfileFields = ${ extended_profile_fields | n, dump_js_escaped_json },
+        displayAccountDeletion = ${ enable_account_deletion | n, dump_js_escaped_json};
         enableGDPRFlag = ${ ENABLE_GDPR_COMPAT_FLAG.is_enabled_without_course_context() | n, dump_js_escaped_json };
 
     AccountSettingsFactory(
@@ -68,6 +69,7 @@ from openedx.features.course_experience import ENABLE_GDPR_COMPAT_FLAG
         enterpriseReadonlyAccountFields,
         edxSupportUrl,
         extendedProfileFields,
+        displayAccountDeletion,
         enableGDPRFlag
     );
 </%static:require_module>
-- 
GitLab