Skip to content

Commit 9b75ba4

Browse files
authored
feat: adds unmark_copied_tags method to tagging API [FC-0076] (#276)
* feat: adds unmark_copied_tags method to tagging API * chore: bumps package version
1 parent 5448131 commit 9b75ba4

4 files changed

Lines changed: 33 additions & 2 deletions

File tree

openedx_learning/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
Open edX Learning ("Learning Core").
33
"""
44

5-
__version__ = "0.18.2"
5+
__version__ = "0.18.3"

openedx_tagging/core/tagging/api.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,3 +516,10 @@ def copy_tags(source_object_id: str, dest_object_id: str):
516516
defaults={"is_copied": True},
517517
# Note: _value and _export_id are set automatically
518518
)
519+
520+
521+
def unmark_copied_tags(object_id: str) -> None:
522+
"""
523+
Update copied object tags on the given object to mark them as "not copied".
524+
"""
525+
ObjectTag.objects.filter(object_id=object_id).update(is_copied=False)

tests/openedx_tagging/core/fixtures/tagging.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@
247247
name: System defined taxonomy
248248
description: Generic System defined taxonomy
249249
enabled: true
250-
allow_multiple: false
250+
allow_multiple: true
251251
allow_free_text: false
252252
export_id: system_defined_taxonomy
253253
_taxonomy_class: openedx_tagging.core.tagging.models.system_defined.SystemDefinedTaxonomy

tests/openedx_tagging/core/tagging/test_api.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,3 +1046,27 @@ def test_copy_tags_with_non_copied(self) -> None:
10461046
assert object_tag.taxonomy == expected_tags[index]["taxonomy"]
10471047
assert object_tag.object_id == obj2
10481048
assert object_tag.is_copied == expected_tags[index]["copied"]
1049+
1050+
def test_unmark_copied_tags(self) -> None:
1051+
obj1 = "object_id1"
1052+
obj2 = "object_id2"
1053+
1054+
# Put 2 tags on obj1
1055+
tagging_api.tag_object(object_id=obj1, taxonomy=self.language_taxonomy, tags=["English"])
1056+
tagging_api.tag_object(object_id=obj1, taxonomy=self.system_taxonomy, tags=["System Tag 1"])
1057+
1058+
# Copy tags from obj1 to obj2
1059+
tagging_api.copy_tags(obj1, obj2)
1060+
1061+
# Update obj2's tags to include one non-copied tag
1062+
tagging_api.tag_object(object_id=obj2, taxonomy=self.system_taxonomy, tags=["System Tag 1", "System Tag 2"])
1063+
1064+
tags = tagging_api.get_object_tags(obj2)
1065+
assert tags.filter(is_copied=False).count() == 1
1066+
assert tags.filter(is_copied=True).count() == 2
1067+
1068+
tagging_api.unmark_copied_tags(obj2)
1069+
1070+
tags = tagging_api.get_object_tags(obj2)
1071+
assert tags.filter(is_copied=False).count() == 3
1072+
assert tags.filter(is_copied=True).count() == 0

0 commit comments

Comments
 (0)