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 0fe983beb660..0900ba39d2b3 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py +++ b/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py @@ -100,6 +100,23 @@ class ChildVerticalContainerSerializer(serializers.Serializer): name = serializers.CharField(source="display_name_with_default") block_id = serializers.CharField(source="location") block_type = serializers.CharField(source="location.block_type") + actions = serializers.SerializerMethodField() + + def get_actions(self, obj): # pylint: disable=unused-argument + """ + Method to get actions for each child xlock of the unit. + """ + + # temporary decision defining the default value 'True' for each xblock. + actions = { + "can_copy": True, + "can_duplicate": True, + "can_move": True, + "can_manage_access": True, + "can_delete": True, + } + + return actions class VerticalContainerSerializer(serializers.Serializer): 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 6fec78b65077..9d37482c7bf5 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 @@ -159,11 +159,25 @@ def test_children_content(self): "name": self.html_unit_first.display_name_with_default, "block_id": str(self.html_unit_first.location), "block_type": self.html_unit_first.location.block_type, + "actions": { + "can_copy": True, + "can_duplicate": True, + "can_move": True, + "can_manage_access": True, + "can_delete": True + } }, { "name": self.html_unit_second.display_name_with_default, "block_id": str(self.html_unit_second.location), "block_type": self.html_unit_second.location.block_type, + "actions": { + "can_copy": True, + "can_duplicate": True, + "can_move": True, + "can_manage_access": True, + "can_delete": True + } }, ] self.assertEqual(response.data["children"], expected_response) 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 d2d832e9674b..a11380a08a66 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py @@ -180,17 +180,38 @@ def get(self, request: Request, usage_key_string: str): { "name": "Drag and Drop", "block_id": "block-v1:org+101+101+type@drag-and-drop-v2+block@7599275ace6b46f5a482078a2954ca16", - "block_type": "drag-and-drop-v2" + "block_type": "drag-and-drop-v2", + "actions": { + "can_copy": true, + "can_duplicate": true, + "can_move": true, + "can_manage_access": true, + "can_delete": true + } }, { "name": "Video", "block_id": "block-v1:org+101+101+type@video+block@0e3d39b12d7c4345981bda6b3511a9bf", - "block_type": "video" + "block_type": "video", + "actions": { + "can_copy": true, + "can_duplicate": true, + "can_move": true, + "can_manage_access": true, + "can_delete": true + } }, { "name": "Text", "block_id": "block-v1:org+101+101+type@html+block@3e3fa1f88adb4a108cd14e9002143690", - "block_type": "html" + "block_type": "html", + "actions": { + "can_copy": true, + "can_duplicate": true, + "can_move": true, + "can_manage_access": true, + "can_delete": true + } }, ], "is_published": false diff --git a/cms/djangoapps/contentstore/views/tests/test_container_page.py b/cms/djangoapps/contentstore/views/tests/test_container_page.py index 1d5b52905357..2f5183e086a5 100644 --- a/cms/djangoapps/contentstore/views/tests/test_container_page.py +++ b/cms/djangoapps/contentstore/views/tests/test_container_page.py @@ -14,15 +14,18 @@ from urllib.parse import quote import cms.djangoapps.contentstore.views.component as views +from common.djangoapps.xblock_django.user_service import DjangoXBlockUserService from cms.djangoapps.contentstore.tests.test_libraries import LibraryTestCase from xmodule.modulestore import ModuleStoreEnum # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.django import modulestore # lint-amnesty, pylint: disable=wrong-import-order from xmodule.modulestore.tests.factories import CourseFactory, BlockFactory # lint-amnesty, pylint: disable=wrong-import-order +from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID, UserPartition +from xmodule.partitions.tests.test_partitions import PartitionTestCase from .utils import StudioPageTestCase -class ContainerPageTestCase(StudioPageTestCase, LibraryTestCase): +class ContainerPageTestCase(StudioPageTestCase, LibraryTestCase, PartitionTestCase): """ Unit tests for the container page. """ @@ -34,10 +37,24 @@ def setUp(self): super().setUp() self.vertical = self._create_block(self.sequential, 'vertical', 'Unit') self.html = self._create_block(self.vertical, "html", "HTML") - self.child_container = self._create_block(self.vertical, 'split_test', 'Split Test') + self.user_partition = UserPartition( + ENROLLMENT_TRACK_PARTITION_ID, + self.TEST_NAME, + self.TEST_DESCRIPTION, + self.TEST_GROUPS + ) + self.child_container = self._create_block( + self.vertical, + 'split_test', + 'Split Test', + user_partition_id=ENROLLMENT_TRACK_PARTITION_ID, + user_partitions=[self.user_partition] + ) self.child_vertical = self._create_block(self.child_container, 'vertical', 'Child Vertical') self.video = self._create_block(self.child_vertical, "video", "My Video") self.store = modulestore() + user_service = DjangoXBlockUserService(self.user) + self.child_container.runtime._services['user'] = user_service # pylint: disable=protected-access past = datetime.datetime(1970, 1, 1, tzinfo=UTC) future = datetime.datetime.now(UTC) + datetime.timedelta(days=1) diff --git a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py index b3a8a091bcc4..ae4044e83264 100644 --- a/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py +++ b/cms/djangoapps/contentstore/xblock_storage_handlers/view_handlers.py @@ -1091,7 +1091,7 @@ def create_xblock_info( # lint-amnesty, pylint: disable=too-many-statements "group_access": xblock.group_access, "user_partitions": user_partitions, "show_correctness": xblock.show_correctness, - "xblock_type": get_icon(xblock), + "xblock_type": get_icon(xblock) if is_xblock_unit else None, } )