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 172762c20fa9..a976b4954fac 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py +++ b/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py @@ -98,9 +98,9 @@ class ChildVerticalContainerSerializer(serializers.Serializer): Serializer for representing a xblock child of vertical container. """ - name = serializers.CharField(source="display_name_with_default") - block_id = serializers.CharField(source="location") - block_type = serializers.CharField(source="location.block_type") + name = serializers.CharField() + block_id = serializers.CharField() + block_type = serializers.CharField() actions = serializers.SerializerMethodField() user_partition_info = serializers.DictField() user_partitions = serializers.ListField() 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 9d37482c7bf5..063ba9ed5420 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 @@ -5,6 +5,7 @@ from rest_framework import status from cms.djangoapps.contentstore.tests.utils import CourseTestCase +from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID from xmodule.modulestore.django import ( modulestore, ) # lint-amnesty, pylint: disable=wrong-import-order @@ -154,6 +155,28 @@ def test_children_content(self): url = self.get_reverse_url(self.vertical.location) response = self.client.get(url) + expected_user_partition_info = { + "selectable_partitions": [], + "selected_partition_index": -1, + "selected_groups_label": "" + } + + expected_user_partitions = [ + { + "id": ENROLLMENT_TRACK_PARTITION_ID, + "name": "Enrollment Track Groups", + "scheme": "enrollment_track", + "groups": [ + { + "id": 1, + "name": "Audit", + "selected": False, + "deleted": False + } + ] + } + ] + expected_response = [ { "name": self.html_unit_first.display_name_with_default, @@ -165,7 +188,9 @@ def test_children_content(self): "can_move": True, "can_manage_access": True, "can_delete": True - } + }, + "user_partition_info": expected_user_partition_info, + "user_partitions": expected_user_partitions }, { "name": self.html_unit_second.display_name_with_default, @@ -177,7 +202,9 @@ def test_children_content(self): "can_move": True, "can_manage_access": True, "can_delete": True - } + }, + "user_partition_info": expected_user_partition_info, + "user_partitions": expected_user_partitions, }, ] 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 dba29c72f58f..a1e87e780bf3 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py @@ -229,18 +229,22 @@ 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) - # load course once to reuse it for user_partitions query - course = modulestore().get_course(current_xblock.location.course_key) 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) - setattr(child_info, 'user_partition_info', user_partition_info) - setattr(child_info, 'user_partitions', user_partitions) - children.append(child_info) + 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, + }) is_published = not modulestore().has_changes(current_xblock) container_data = {"children": children, "is_published": is_published}