From 1a249ed6337e615335ae1bae0698ef1fb55ed474 Mon Sep 17 00:00:00 2001 From: ruzniaievdm Date: Thu, 28 Mar 2024 17:54:30 +0200 Subject: [PATCH 1/2] feat: [AXIMST-688] Refactoring for the states --- .../rest_api/v1/serializers/vertical_block.py | 22 ++++++--- .../rest_api/v1/views/vertical_block.py | 46 ++++++++++++------- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py b/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py index 3ea9c0b0461c..e2b158f1fbba 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py +++ b/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py @@ -123,14 +123,22 @@ def get_actions(self, obj): # pylint: disable=unused-argument """ can_manage_tags = use_tagging_taxonomy_list_page() - - # temporary decision defining the default value 'True' for each xblock. + xblock = obj["xblock"] + is_course = xblock.scope_ids.usage_id.context_key.is_course + xblock_url = xblock_studio_url(xblock) + # Responsible for the ability to edit container xblock(copy, duplicate, move and manage access). + # It was used in the legacy and transferred here with simplification. + # After the investigation it was determined that the "show_other_action" + # condition below is sufficient to enable/disable actions on each xblock. + show_inline = xblock.has_children and not xblock_url + # All except delete and manage tags + show_other_action = not show_inline and is_course actions = { - "can_copy": True, - "can_duplicate": True, - "can_move": True, - "can_manage_access": True, - "can_delete": True, + "can_copy": show_other_action, + "can_duplicate": show_other_action, + "can_move": show_other_action, + "can_manage_access": show_other_action, + "can_delete": is_course, "can_manage_tags": can_manage_tags, } diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py b/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py index 4a685d822a62..52abe5ea88b8 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py @@ -1,5 +1,6 @@ """ API Views for unit page """ +import logging import edx_api_doc_tools as apidocs from django.http import HttpResponseBadRequest from rest_framework.request import Request @@ -26,6 +27,9 @@ from cms.djangoapps.contentstore.rest_api.v1.mixins import ContainerHandlerMixin +log = logging.getLogger(__name__) + + @view_auth_classes(is_authenticated=True) class ContainerHandlerView(APIView, ContainerHandlerMixin): """ @@ -250,33 +254,41 @@ def get(self, request: Request, usage_key_string: str): """ usage_key = self.get_object(usage_key_string) current_xblock = get_xblock(usage_key, request.user) + is_course = current_xblock.scope_ids.usage_id.context_key.is_course with modulestore().bulk_operations(usage_key.course_key): # load course once to reuse it for user_partitions query course = modulestore().get_course(current_xblock.location.course_key) children = [] - for child in current_xblock.children: - child_info = modulestore().get_item(child) - user_partition_info = get_visibility_partition_info(child_info, course=course) - user_partitions = get_user_partition_info(child_info, course=course) - validation_messages = get_xblock_validation_messages(child_info) - render_error = get_xblock_render_error(request, child_info) + if hasattr(current_xblock, "children"): + for child in current_xblock.children: + child_info = modulestore().get_item(child) + user_partition_info = get_visibility_partition_info(child_info, course=course) + user_partitions = get_user_partition_info(child_info, course=course) + validation_messages = get_xblock_validation_messages(child_info) + render_error = get_xblock_render_error(request, child_info) + + children.append({ + "xblock": child_info, + "name": child_info.display_name_with_default, + "block_id": child_info.location, + "block_type": child_info.location.block_type, + "user_partition_info": user_partition_info, + "user_partitions": user_partitions, + "validation_messages": validation_messages, + "render_error": render_error, + }) - children.append({ - "name": child_info.display_name_with_default, - "block_id": child_info.location, - "block_type": child_info.location.block_type, - "user_partition_info": user_partition_info, - "user_partitions": user_partitions, - "validation_messages": validation_messages, - "render_error": render_error, - }) + is_published = False + try: + is_published = not modulestore().has_changes(current_xblock) + except ItemNotFoundError: + logging.error('Could not find any changes for block [%s]', usage_key) - is_published = not modulestore().has_changes(current_xblock) container_data = { "children": children, "is_published": is_published, - "can_paste_component": True, + "can_paste_component": is_course, } serializer = VerticalContainerSerializer(container_data) return Response(serializer.data) From 50a192157b07c609133db32056263e0c82597baf Mon Sep 17 00:00:00 2001 From: ruzniaievdm Date: Fri, 29 Mar 2024 14:07:18 +0200 Subject: [PATCH 2/2] fix: rebase artefacts --- .../rest_api/v1/views/tests/test_vertical_block.py | 8 +------- lms/djangoapps/courseware/tests/test_views.py | 1 + 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_vertical_block.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_vertical_block.py index 6393f83897f7..b141bdd2dba2 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_vertical_block.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_vertical_block.py @@ -196,16 +196,13 @@ def test_children_content(self): "user_partition_info": expected_user_partition_info, "user_partitions": expected_user_partitions, "actions": { - "can_manage_tags": True, "can_copy": True, "can_duplicate": True, "can_move": True, "can_manage_access": True, - "can_delete": True + "can_delete": True, "can_manage_tags": True, }, - "user_partition_info": expected_user_partition_info, - "user_partitions": expected_user_partitions, "validation_messages": [], "render_error": "", }, @@ -216,7 +213,6 @@ def test_children_content(self): "user_partition_info": expected_user_partition_info, "user_partitions": expected_user_partitions, "actions": { - "can_manage_tags": True, "can_copy": True, "can_duplicate": True, "can_move": True, @@ -224,8 +220,6 @@ def test_children_content(self): "can_delete": True, "can_manage_tags": True, }, - "user_partition_info": expected_user_partition_info, - "user_partitions": expected_user_partitions, "validation_messages": [], "render_error": "", }, diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index 5f8bd1c49f18..ed0b4bf5b7e0 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -79,6 +79,7 @@ from lms.djangoapps.courseware.testutils import RenderXBlockTestMixin from lms.djangoapps.courseware.toggles import ( COURSEWARE_MICROFRONTEND_DISCUSSION_SIDEBAR_OPEN_DISABLED, + COURSEWARE_MICROFRONTEND_SIDEBAR_DISABLED, COURSEWARE_MICROFRONTEND_SEARCH_ENABLED, COURSEWARE_OPTIMIZED_RENDER_XBLOCK, )