From 40e66b6a27e429c61c15d3cf2ef24cada05b2571 Mon Sep 17 00:00:00 2001 From: Sagirov Eugeniy Date: Wed, 31 Aug 2022 13:10:26 +0300 Subject: [PATCH] feat: add feature flag ENABLE_LIBRARY_DELETION --- cms/envs/common.py | 8 ++++++++ .../content_libraries/tests/test_content_libraries.py | 1 - openedx/core/djangoapps/content_libraries/views.py | 11 ++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index cdb597b6700d..3db8a2385cb5 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -516,6 +516,14 @@ # in the LMS and CMS. # .. toggle_tickets: 'https://github.com/open-craft/edx-platform/pull/429' 'DISABLE_UNENROLLMENT': False, + + # .. toggle_name: FEATURES['ENABLE_LIBRARY_DELETION'] + # .. toggle_implementation: DjangoSetting + # .. toggle_default: False + # .. toggle_description: Set to True to enable deletion functionality for library mfe. + # .. toggle_use_cases: open_edx + # .. toggle_creation_date: 2022-08-31 + 'ENABLE_LIBRARY_DELETION': False, } # .. toggle_name: ENABLE_COPPA_COMPLIANCE diff --git a/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py b/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py index 0e05413933bf..594c7b0f028c 100644 --- a/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py +++ b/openedx/core/djangoapps/content_libraries/tests/test_content_libraries.py @@ -216,7 +216,6 @@ def test_list_library(self, is_indexing_enabled): with override_settings(FEATURES={**settings.FEATURES, 'ENABLE_CONTENT_LIBRARY_INDEX': is_indexing_enabled}): lib1 = self._create_library(slug="some-slug-1", title="Existing Library") lib2 = self._create_library(slug="some-slug-2", title="Existing Library") - lib1['can_delete'] = lib2['can_delete'] = True if not is_indexing_enabled: lib1['num_blocks'] = lib2['num_blocks'] = None lib1['last_published'] = lib2['last_published'] = None diff --git a/openedx/core/djangoapps/content_libraries/views.py b/openedx/core/djangoapps/content_libraries/views.py index f98d253dbbe5..5eb9c6bc6c14 100644 --- a/openedx/core/djangoapps/content_libraries/views.py +++ b/openedx/core/djangoapps/content_libraries/views.py @@ -182,11 +182,12 @@ def get(self, request): serializer = ContentLibraryMetadataSerializer(result, many=True) # add permisson for deleting library in response - for library_data in serializer.data: - library_key = LibraryLocatorV2.from_string(library_data['id']) - library_obj = ContentLibrary.objects.get_by_key(library_key) - can_delete = request.user.has_perm(permissions.CAN_DELETE_THIS_CONTENT_LIBRARY, obj=library_obj) - library_data['can_delete'] = can_delete + if settings.FEATURES.get('ENABLE_LIBRARY_DELETION'): + for library_data in serializer.data: + library_key = LibraryLocatorV2.from_string(library_data['id']) + library_obj = ContentLibrary.objects.get_by_key(library_key) + can_delete = request.user.has_perm(permissions.CAN_DELETE_THIS_CONTENT_LIBRARY, obj=library_obj) + library_data['can_delete'] = can_delete # Verify `pagination` param to maintain compatibility with older # non pagination-aware clients