Skip to content

Commit

Permalink
feat: manage Tags on block level (#34361)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruzniaievdm authored Mar 18, 2024
1 parent 1247254 commit 1bcf25f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -183,14 +186,20 @@ 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,
"block_id": str(self.html_unit_second.location),
"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)
Expand All @@ -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"])
13 changes: 11 additions & 2 deletions cms/djangoapps/contentstore/rest_api/v1/views/vertical_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,21 +192,30 @@ 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",
"block_id": "block-v1:org+101+101+type@video+block@0e3d39b12d7c4345981bda6b3511a9bf",
"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
}
Expand Down

0 comments on commit 1bcf25f

Please sign in to comment.