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: adds unmark_copied_tags method to tagging API [FC-0076] #276

Merged
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
2 changes: 1 addition & 1 deletion openedx_learning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Open edX Learning ("Learning Core").
"""

__version__ = "0.18.2"
__version__ = "0.18.3"
7 changes: 7 additions & 0 deletions openedx_tagging/core/tagging/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,3 +516,10 @@ def copy_tags(source_object_id: str, dest_object_id: str):
defaults={"is_copied": True},
# Note: _value and _export_id are set automatically
)


def unmark_copied_tags(object_id: str) -> None:
"""
Update copied object tags on the given object to mark them as "not copied".
"""
ObjectTag.objects.filter(object_id=object_id).update(is_copied=False)
2 changes: 1 addition & 1 deletion tests/openedx_tagging/core/fixtures/tagging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
name: System defined taxonomy
description: Generic System defined taxonomy
enabled: true
allow_multiple: false
allow_multiple: true
allow_free_text: false
export_id: system_defined_taxonomy
_taxonomy_class: openedx_tagging.core.tagging.models.system_defined.SystemDefinedTaxonomy
Expand Down
24 changes: 24 additions & 0 deletions tests/openedx_tagging/core/tagging/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,3 +1046,27 @@ def test_copy_tags_with_non_copied(self) -> None:
assert object_tag.taxonomy == expected_tags[index]["taxonomy"]
assert object_tag.object_id == obj2
assert object_tag.is_copied == expected_tags[index]["copied"]

def test_unmark_copied_tags(self) -> None:
obj1 = "object_id1"
obj2 = "object_id2"

# Put 2 tags on obj1
tagging_api.tag_object(object_id=obj1, taxonomy=self.language_taxonomy, tags=["English"])
tagging_api.tag_object(object_id=obj1, taxonomy=self.system_taxonomy, tags=["System Tag 1"])

# Copy tags from obj1 to obj2
tagging_api.copy_tags(obj1, obj2)

# Update obj2's tags to include one non-copied tag
tagging_api.tag_object(object_id=obj2, taxonomy=self.system_taxonomy, tags=["System Tag 1", "System Tag 2"])

tags = tagging_api.get_object_tags(obj2)
assert tags.filter(is_copied=False).count() == 1
assert tags.filter(is_copied=True).count() == 2

tagging_api.unmark_copied_tags(obj2)

tags = tagging_api.get_object_tags(obj2)
assert tags.filter(is_copied=False).count() == 3
assert tags.filter(is_copied=True).count() == 0