From 1bcf25f22b064a157fe633400ee1698917c09e37 Mon Sep 17 00:00:00 2001 From: ruzniaievdm Date: Mon, 18 Mar 2024 22:09:47 +0200 Subject: [PATCH] feat: manage Tags on block level (#34361) --- .../rest_api/v1/serializers/vertical_block.py | 14 +++++++++++ .../v1/views/tests/test_vertical_block.py | 23 +++++++++++++++++-- .../rest_api/v1/views/vertical_block.py | 13 +++++++++-- 3 files changed, 46 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 2a16ccf2dbb0..881e62e42fc7 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py +++ b/cms/djangoapps/contentstore/rest_api/v1/serializers/vertical_block.py @@ -5,6 +5,7 @@ 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): 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 7d9dcaa7e3d8..983205ff6a68 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 @@ -3,8 +3,10 @@ """ 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 @@ def test_xblock_is_published(self): 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 @@ def test_children_content(self): "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 @@ def test_children_content(self): "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 @@ def test_not_valid_usage_key_string(self): ) 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"]) 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 69768ad0b5eb..a084886cf344 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py @@ -192,6 +192,9 @@ def get(self, request: Request, usage_key_string: str): "block_type": "drag-and-drop-v2", "user_partition_info": {}, "user_partitions": {} + "actions": { + "can_manage_tags": true, + } }, { "name": "Video", @@ -199,14 +202,20 @@ def get(self, request: Request, usage_key_string: str): "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 }