Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [AXIMST-688] Refactoring for the states #2521

Merged
merged 2 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
},
Expand All @@ -216,16 +213,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_manage_tags": True,
},
"user_partition_info": expected_user_partition_info,
"user_partitions": expected_user_partitions,
"validation_messages": [],
"render_error": "",
},
Expand Down
46 changes: 29 additions & 17 deletions cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
"""
Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions lms/djangoapps/courseware/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
Loading