feat: manage Tags on block level (#34361)

This commit is contained in:
ruzniaievdm
2024-03-18 22:09:47 +02:00
committed by GitHub
parent 1247254fbe
commit 1bcf25f22b
3 changed files with 46 additions and 4 deletions

View File

@@ -5,6 +5,7 @@ API Serializers for unit page
from django.urls import reverse
from rest_framework import serializers
from cms.djangoapps.contentstore.toggles import use_tagging_taxonomy_list_page
from cms.djangoapps.contentstore.helpers import (
xblock_studio_url,
xblock_type_display_name,
@@ -103,6 +104,19 @@ class ChildVerticalContainerSerializer(serializers.Serializer):
block_type = serializers.CharField()
user_partition_info = serializers.DictField()
user_partitions = serializers.ListField()
actions = serializers.SerializerMethodField()
def get_actions(self, obj): # pylint: disable=unused-argument
"""
Method to get actions for each child xlock of the unit.
"""
can_manage_tags = use_tagging_taxonomy_list_page()
actions = {
"can_manage_tags": can_manage_tags,
}
return actions
class VerticalContainerSerializer(serializers.Serializer):

View File

@@ -3,8 +3,10 @@ Unit tests for the vertical block.
"""
from django.urls import reverse
from rest_framework import status
from edx_toggles.toggles.testutils import override_waffle_flag
from cms.djangoapps.contentstore.tests.utils import CourseTestCase
from cms.djangoapps.contentstore.toggles import ENABLE_TAGGING_TAXONOMY_LIST_PAGE
from xmodule.partitions.partitions import ENROLLMENT_TRACK_PARTITION_ID
from xmodule.modulestore.django import (
modulestore,
@@ -148,6 +150,7 @@ class ContainerVerticalViewTest(BaseXBlockContainer):
response = self.client.get(url)
self.assertTrue(response.data["is_published"])
@override_waffle_flag(ENABLE_TAGGING_TAXONOMY_LIST_PAGE, True)
def test_children_content(self):
"""
Check that returns valid response with children of vertical container.
@@ -183,7 +186,10 @@ class ContainerVerticalViewTest(BaseXBlockContainer):
"block_id": str(self.html_unit_first.location),
"block_type": self.html_unit_first.location.block_type,
"user_partition_info": expected_user_partition_info,
"user_partitions": expected_user_partitions
"user_partitions": expected_user_partitions,
"actions": {
"can_manage_tags": True,
},
},
{
"name": self.html_unit_second.display_name_with_default,
@@ -191,6 +197,9 @@ class ContainerVerticalViewTest(BaseXBlockContainer):
"block_type": self.html_unit_second.location.block_type,
"user_partition_info": expected_user_partition_info,
"user_partitions": expected_user_partitions,
"actions": {
"can_manage_tags": True,
},
},
]
self.assertEqual(response.data["children"], expected_response)
@@ -204,4 +213,14 @@ class ContainerVerticalViewTest(BaseXBlockContainer):
)
url = self.get_reverse_url(usage_key_string)
response = self.client.get(url)
self.assertEqual(response.status_code, 404)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
@override_waffle_flag(ENABLE_TAGGING_TAXONOMY_LIST_PAGE, False)
def test_actions_with_turned_off_taxonomy_flag(self):
"""
Check that action manage_tags for each child item has the same value as taxonomy flag.
"""
url = self.get_reverse_url(self.vertical.location)
response = self.client.get(url)
for children in response.data["children"]:
self.assertFalse(children["actions"]["can_manage_tags"])

View File

@@ -192,6 +192,9 @@ class VerticalContainerView(APIView, ContainerHandlerMixin):
"block_type": "drag-and-drop-v2",
"user_partition_info": {},
"user_partitions": {}
"actions": {
"can_manage_tags": true,
}
},
{
"name": "Video",
@@ -199,14 +202,20 @@ class VerticalContainerView(APIView, ContainerHandlerMixin):
"block_type": "video",
"user_partition_info": {},
"user_partitions": {}
"actions": {
"can_manage_tags": true,
}
},
{
"name": "Text",
"block_id": "block-v1:org+101+101+type@html+block@3e3fa1f88adb4a108cd14e9002143690",
"block_type": "html",
"user_partition_info": {},
"user_partitions": {}
}
"user_partitions": {},
"actions": {
"can_manage_tags": true,
}
},
],
"is_published": false
}