Skip to content

Commit

Permalink
Merge pull request #3804 from rtibbles/no_modify_publish
Browse files Browse the repository at this point in the history
Prevent modification of contentnode extra_fields during publish
  • Loading branch information
rtibbles committed Nov 9, 2022
2 parents b6d632f + 509f98c commit f47e6ab
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
45 changes: 45 additions & 0 deletions contentcuration/contentcuration/tests/test_exportchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from .base import StudioTestCase
from .helpers import clear_tasks
from .testdata import channel
from .testdata import create_studio_file
from .testdata import node as create_node
from .testdata import slideshow
from contentcuration import models as cc
Expand All @@ -38,6 +39,9 @@
pytestmark = pytest.mark.django_db


thumbnail_bytes = b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x06\x00\x00\x00\x1f\x15\xc4\x89\x00\x00\x00\nIDATx\x9cc\x00\x01\x00\x00\x05\x00\x01\r\n-\xb4\x00\x00\x00\x00IEND\xaeB`\x82' # noqa E501


def description():
return "".join(random.sample(string.printable, 20))

Expand Down Expand Up @@ -116,11 +120,35 @@ def setUp(self):
new_exercise.complete = True
new_exercise.parent = current_exercise.parent
new_exercise.save()
thumbnail_data = create_studio_file(thumbnail_bytes, preset="exercise_thumbnail", ext="png")
file_obj = thumbnail_data["db_file"]
file_obj.contentnode = new_exercise
file_obj.save()
for ai in current_exercise.assessment_items.all():
ai.id = None
ai.contentnode = new_exercise
ai.save()

legacy_extra_fields = {
'mastery_model': exercises.M_OF_N,
'randomize': True,
'm': 1,
'n': 2
}

legacy_exercise = create_node({'kind_id': 'exercise', 'title': 'Legacy Mastery test', 'extra_fields': legacy_extra_fields})
legacy_exercise.complete = True
legacy_exercise.parent = current_exercise.parent
legacy_exercise.save()
thumbnail_data = create_studio_file(thumbnail_bytes, preset="exercise_thumbnail", ext="png")
file_obj = thumbnail_data["db_file"]
file_obj.contentnode = legacy_exercise
file_obj.save()
for ai in current_exercise.assessment_items.all():
ai.id = None
ai.contentnode = legacy_exercise
ai.save()

first_topic = self.content_channel.main_tree.get_descendants().first()

# Add a publishable topic to ensure it does not inherit but that its children do
Expand Down Expand Up @@ -357,6 +385,23 @@ def test_child_no_inherit_learning_activity(self):
# Should only be the learning activities we set on the child directly, not any parent ones.
self.assertEqual(first_child.learning_activities, learning_activities.LISTEN)

def test_publish_no_modify_exercise_extra_fields(self):
exercise = cc.ContentNode.objects.get(title="Mastery test")
self.assertEqual(exercise.extra_fields["options"]["completion_criteria"]["threshold"], {
"m": 1,
"n": 2,
"mastery_model": exercises.M_OF_N,
})

def test_publish_no_modify_legacy_exercise_extra_fields(self):
current_exercise = cc.ContentNode.objects.get(title="Legacy Mastery test")
self.assertEqual(current_exercise.extra_fields, {
'mastery_model': exercises.M_OF_N,
'randomize': True,
'm': 1,
'n': 2
})


class ChannelExportUtilityFunctionTestCase(StudioTestCase):
@classmethod
Expand Down
2 changes: 1 addition & 1 deletion contentcuration/contentcuration/utils/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ def create_associated_thumbnail(ccnode, ccfilemodel):
"points": [],
"zoom": 0,
})
ccnode.save()
ccnode.save(update_fields=("thumbnail_encoding",))

return create_thumbnail_from_base64(
encoding,
Expand Down

0 comments on commit f47e6ab

Please sign in to comment.