From 8b8f71e229832ef74e1a1350c5d1a7b8a8fecaaf Mon Sep 17 00:00:00 2001 From: monteri Date: Tue, 30 Jan 2024 18:52:54 +0200 Subject: [PATCH] feat: [AXIMST-418] Manage access API --- .../rest_api/v1/serializers/vertical_block.py | 2 ++ .../rest_api/v1/views/vertical_block.py | 20 +++++++++++++++---- 2 files changed, 18 insertions(+), 4 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 6aa1f1af27c0..172762c20fa9 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py +++ b/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py @@ -102,6 +102,8 @@ class ChildVerticalContainerSerializer(serializers.Serializer): block_id = serializers.CharField(source="location") block_type = serializers.CharField(source="location.block_type") actions = serializers.SerializerMethodField() + user_partition_info = serializers.DictField() + user_partitions = serializers.ListField() def get_actions(self, obj): # pylint: disable=unused-argument """ 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 584d21428854..dba29c72f58f 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py @@ -6,7 +6,11 @@ from rest_framework.response import Response from rest_framework.views import APIView -from cms.djangoapps.contentstore.utils import get_container_handler_context +from cms.djangoapps.contentstore.utils import ( + get_container_handler_context, + get_user_partition_info, + get_visibility_partition_info, +) from cms.djangoapps.contentstore.views.component import _get_item_in_course from cms.djangoapps.contentstore.xblock_storage_handlers.view_handlers import get_xblock from cms.djangoapps.contentstore.rest_api.v1.serializers import ( @@ -225,11 +229,19 @@ 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): - children = [ - modulestore().get_item(child) for child in current_xblock.children - ] + 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) + is_published = not modulestore().has_changes(current_xblock) container_data = {"children": children, "is_published": is_published} serializer = VerticalContainerSerializer(container_data)