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

fix: don't publish tags greater than 30 chars #3310

Merged
merged 5 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ docs/_build/
# PyBuilder
target/

# virtualenv
# virtualenv, pipenv
.env
venv
.venv
Pipfile
Pipfile.lock

Thumbs.db
.DS_Store
Expand Down
15 changes: 15 additions & 0 deletions contentcuration/contentcuration/tests/test_exportchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ def setUp(self):
new_video.parent = new_node
new_video.save()

# Add a node with tags greater than 30 chars to ensure they get excluded.
new_video = create_node({'kind_id': 'video', 'tags': [{'tag_name': 'kolbasdasdasrissadasdwzxcztudio'}, {'tag_name': 'kolbasdasdasrissadasdwzxcztudi'},
{'tag_name': 'kolbasdasdasrissadasdwzxc'}], 'title': 'kolibri tag test', 'children': []})
new_video.complete = True
new_video.parent = self.content_channel.main_tree
new_video.save()

set_channel_icon_encoding(self.content_channel)
self.tempdb = create_content_database(self.content_channel, True, None, True)

Expand Down Expand Up @@ -120,6 +127,14 @@ def test_contentnode_incomplete_not_published(self):
for node in incomplete_nodes:
assert kolibri_nodes.filter(pk=node.node_id).count() == 0

def test_tags_greater_than_30_excluded(self):
tag_node = kolibri_models.ContentNode.objects.filter(title='kolibri tag test').first()
published_tags = tag_node.tags.all()

assert published_tags.count() == 2
for t in published_tags:
assert len(t.tag_name) <= 30

def test_contentnode_channel_id_data(self):
channel = kolibri_models.ChannelMetadata.objects.first()
nodes = kolibri_models.ContentNode.objects.all()
Expand Down
13 changes: 13 additions & 0 deletions contentcuration/contentcuration/tests/views/test_views_internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def _make_node_data(self):
"source_domain": random_data.source_domain,
"source_id": random_data.source_id,
"author": random_data.author,
"tags": ["oer", "edtech"],
"files": [
{
"size": fileobj.file_size,
Expand Down Expand Up @@ -109,13 +110,19 @@ def setUp(self):
invalid_copyright_holder["title"] = "invalid_copyright_holder"
invalid_copyright_holder["copyright_holder"] = ""

# Node with tag greater than 30 characters
invalid_tag_length = self._make_node_data()
invalid_tag_length["title"] = "invalid_tag_length"
invalid_tag_length["tags"] = ["abcd abcd abcd abcd abcd abcd", "abcde abcd abcd abcd abcd abcd", "abcdef abcd abcd abcd abcd abcd"]

self.sample_data = {
"root_id": self.root_node.id,
"content_data": [
valid_node,
invalid_title_node,
invalid_license_description,
invalid_copyright_holder,
invalid_tag_length,
],
}
self.resp = self.admin_client().post(
Expand Down Expand Up @@ -176,6 +183,12 @@ def test_invalid_nodes_are_not_complete(self):
self.assertFalse(node_2.complete)
self.assertFalse(node_3.complete)

def test_tag_greater_than_30_chars_excluded(self):
node = ContentNode.objects.get(title="invalid_tag_length")
tags = node.tags.all()
for t in tags:
assert len(t.tag_name) <= 30


class ApiAddExerciseNodesToTreeTestCase(StudioTestCase):
"""
Expand Down
3 changes: 2 additions & 1 deletion contentcuration/contentcuration/utils/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,8 @@ def map_tags_to_node(kolibrinode, ccnode):

for tag in ccnode.tags.all():
t, _new = kolibrimodels.ContentTag.objects.get_or_create(pk=tag.pk, tag_name=tag.tag_name)
tags_to_add.append(t)
if len(t.tag_name) <= 30:
tags_to_add.append(t)

kolibrinode.tags.set(tags_to_add)
kolibrinode.save()
Expand Down
7 changes: 4 additions & 3 deletions contentcuration/contentcuration/views/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,9 +643,10 @@ def create_node(node_data, parent_node, sort_order): # noqa: C901
tag_data = node_data["tags"]
if tag_data is not None:
for tag in tag_data:
tags.append(
ContentTag.objects.get_or_create(tag_name=tag, channel=channel)[0]
)
if len(tag) <= 30:
vkWeb marked this conversation as resolved.
Show resolved Hide resolved
tags.append(
ContentTag.objects.get_or_create(tag_name=tag, channel=channel)[0]
)

if len(tags) > 0:
node.tags.set(tags)
Expand Down