Skip to content

Commit

Permalink
feat: [AXIMST-418] Manage access API
Browse files Browse the repository at this point in the history
  • Loading branch information
monteri committed Jan 30, 2024
1 parent 8ea0d75 commit 8b8f71e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
20 changes: 16 additions & 4 deletions cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 8b8f71e

Please sign in to comment.