-
Notifications
You must be signed in to change notification settings - Fork 11
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: Copy object tags [FC-0062] #236
Merged
bradenmacdonald
merged 11 commits into
openedx:main
from
open-craft:chris/FAL-3616-copy-tags
Oct 16, 2024
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d653a8e
feat: Copy tags function and read_only Object tags
ChrisChV 3e985d6
refactor: copy_tags function to keep not-copied tags
ChrisChV fcd8437
refactor: Update `ObjectTagsByTaxonomySerializer` to use context to g…
ChrisChV 6b73ec4
style: Update names of functions and variables
ChrisChV 3dc5b0d
Merge branch 'main' into chris/FAL-3616-copy-tags
ChrisChV 2bb68ee
chore: Update version
ChrisChV 744a539
refactor: Updates on copy_tags and some nits
ChrisChV adbf967
chore: Bump version to 0.16.0
ChrisChV 4f8c0d3
chore: fix merge conflicts
ChrisChV 6395019
style: Update comment
ChrisChV 7289b22
style: Add comment
ChrisChV File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
""" | ||
Open edX Learning ("Learning Core"). | ||
""" | ||
__version__ = "0.15.0" | ||
__version__ = "0.16.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
openedx_tagging/core/tagging/migrations/0018_objecttag_is_copied.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.16 on 2024-10-04 19:21 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('oel_tagging', '0017_alter_tagimporttask_status'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='objecttag', | ||
name='is_copied', | ||
field=models.BooleanField(default=False, help_text="True if this object tag has been copied from one object to another using 'copy_tags' api function"), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -913,3 +913,136 @@ def test_get_object_tag_counts_deleted_disabled(self) -> None: | |||
assert tagging_api.get_object_tag_counts("object_*") == {obj1: 1, obj2: 2} | ||||
tagging_api.add_tag_to_taxonomy(self.taxonomy, "DPANN", parent_tag_value="Archaea") | ||||
assert tagging_api.get_object_tag_counts("object_*") == {obj1: 2, obj2: 2} | ||||
|
||||
def test_copy_tags(self) -> None: | ||||
obj1 = "object_id1" | ||||
obj2 = "object_id2" | ||||
|
||||
tags_list = [ | ||||
{ | ||||
"value": "English", | ||||
"taxonomy": self.language_taxonomy, | ||||
}, | ||||
{ | ||||
"value": "DPANN", | ||||
"taxonomy": self.taxonomy, | ||||
}, | ||||
] | ||||
|
||||
for tag_object in tags_list: | ||||
tagging_api.tag_object(object_id=obj1, taxonomy=tag_object["taxonomy"], tags=[tag_object["value"]]) | ||||
|
||||
tagging_api.copy_tags(obj1, obj2) | ||||
|
||||
object_tags = tagging_api.get_object_tags(obj2) | ||||
|
||||
assert len(object_tags) == 2 | ||||
for index, object_tag in enumerate(object_tags): | ||||
object_tag.full_clean() | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||
assert object_tag.value == tags_list[index]["value"] | ||||
assert not object_tag.is_deleted | ||||
assert object_tag.taxonomy == tags_list[index]["taxonomy"] | ||||
assert object_tag.object_id == obj2 | ||||
assert object_tag.is_copied is True | ||||
|
||||
def test_copy_tags_with_non_copied(self) -> None: | ||||
obj1 = "object_id1" | ||||
obj2 = "object_id2" | ||||
|
||||
tagging_api.tag_object(object_id=obj1, taxonomy=self.language_taxonomy, tags=["English"]) | ||||
|
||||
tagging_api.tag_object(object_id=obj2, taxonomy=self.taxonomy, tags=["Chordata"]) | ||||
tagging_api.tag_object(object_id=obj2, taxonomy=self.free_text_taxonomy, tags=["has a notochord"]) | ||||
|
||||
tagging_api.copy_tags(obj1, obj2) | ||||
object_tags = tagging_api.get_object_tags(obj2) | ||||
|
||||
# Tags must be the non-copied and the copied tag. | ||||
expected_tags = [ | ||||
{ | ||||
"value": "has a notochord", | ||||
"taxonomy": self.free_text_taxonomy, | ||||
"copied": False, | ||||
}, | ||||
{ | ||||
"value": "English", | ||||
"taxonomy": self.language_taxonomy, | ||||
"copied": True, | ||||
}, | ||||
{ | ||||
"value": "Chordata", | ||||
"taxonomy": self.taxonomy, | ||||
"copied": False, | ||||
}, | ||||
] | ||||
assert len(object_tags) == 3 | ||||
for index, object_tag in enumerate(object_tags): | ||||
assert object_tag.value == expected_tags[index]["value"] | ||||
assert not object_tag.is_deleted | ||||
assert object_tag.taxonomy == expected_tags[index]["taxonomy"] | ||||
assert object_tag.object_id == obj2 | ||||
assert object_tag.is_copied == expected_tags[index]["copied"] | ||||
|
||||
# Delete tags of 'obj1' and add other | ||||
tagging_api.delete_object_tags(obj1) | ||||
tagging_api.tag_object(object_id=obj1, taxonomy=self.taxonomy, tags=["DPANN"]) | ||||
tagging_api.copy_tags(obj1, obj2) | ||||
object_tags = tagging_api.get_object_tags(obj2) | ||||
|
||||
# Tags must be the non-copied and the new copied tag. | ||||
# The previous copied tags must be deleted. | ||||
expected_tags = [ | ||||
{ | ||||
"value": "has a notochord", | ||||
"taxonomy": self.free_text_taxonomy, | ||||
"copied": False, | ||||
}, | ||||
{ | ||||
"value": "DPANN", | ||||
"taxonomy": self.taxonomy, | ||||
"copied": True, | ||||
}, | ||||
{ | ||||
"value": "Chordata", | ||||
"taxonomy": self.taxonomy, | ||||
"copied": False, | ||||
}, | ||||
] | ||||
assert len(object_tags) == 3 | ||||
for index, object_tag in enumerate(object_tags): | ||||
assert object_tag.value == expected_tags[index]["value"] | ||||
assert not object_tag.is_deleted | ||||
assert object_tag.taxonomy == expected_tags[index]["taxonomy"] | ||||
assert object_tag.object_id == obj2 | ||||
assert object_tag.is_copied == expected_tags[index]["copied"] | ||||
|
||||
# Add a tag used by 'obj2' | ||||
tagging_api.tag_object(object_id=obj1, taxonomy=self.free_text_taxonomy, tags=["has a notochord"]) | ||||
tagging_api.copy_tags(obj1, obj2) | ||||
object_tags = tagging_api.get_object_tags(obj2) | ||||
|
||||
# The non-copied tag 'has a notochord' must be copied now. | ||||
expected_tags = [ | ||||
{ | ||||
"value": "has a notochord", | ||||
"taxonomy": self.free_text_taxonomy, | ||||
"copied": True, | ||||
}, | ||||
{ | ||||
"value": "DPANN", | ||||
"taxonomy": self.taxonomy, | ||||
"copied": True, | ||||
}, | ||||
{ | ||||
"value": "Chordata", | ||||
"taxonomy": self.taxonomy, | ||||
"copied": False, | ||||
}, | ||||
] | ||||
assert len(object_tags) == 3 | ||||
for index, object_tag in enumerate(object_tags): | ||||
assert object_tag.value == expected_tags[index]["value"] | ||||
assert not object_tag.is_deleted | ||||
assert object_tag.taxonomy == expected_tags[index]["taxonomy"] | ||||
assert object_tag.object_id == obj2 | ||||
assert object_tag.is_copied == expected_tags[index]["copied"] |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should not be here. If the tagging app is reused in another project other than edx-platform, a copied tag does not necessarily mean it is read-only in the UI.