Skip to content

Commit 5eaa4af

Browse files
authored
Merge pull request #4050 from rtibbles/i_think_im_a_clone_now
Adds capability to ricecooker endpoints to specify an existing node for which the ricecooker user has permissions to copy into tree
2 parents ec54f82 + e6886bc commit 5eaa4af

File tree

6 files changed

+521
-51
lines changed

6 files changed

+521
-51
lines changed

contentcuration/contentcuration/db/models/manager.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,35 @@ def log_lock_time_spent(timespent):
4747
logging.debug("Spent {} seconds inside an mptt lock".format(timespent))
4848

4949

50+
# Fields that are allowed to be overridden on copies coming from a source that the user
51+
# does not have edit rights to.
52+
ALLOWED_OVERRIDES = {
53+
"node_id",
54+
"title",
55+
"description",
56+
"aggregator",
57+
"provider",
58+
"language_id",
59+
"grade_levels",
60+
"resource_types",
61+
"learning_activities",
62+
"accessibility_labels",
63+
"categories",
64+
"learner_needs",
65+
"role",
66+
"extra_fields",
67+
"suggested_duration",
68+
}
69+
70+
EDIT_ALLOWED_OVERRIDES = ALLOWED_OVERRIDES.union({
71+
"license_id",
72+
"license_description",
73+
"extra_fields",
74+
"copyright_holder",
75+
"author",
76+
})
77+
78+
5079
class CustomContentNodeTreeManager(TreeManager.from_queryset(CustomTreeQuerySet)):
5180
# Added 7-31-2018. We can remove this once we are certain we have eliminated all cases
5281
# where root nodes are getting prepended rather than appended to the tree list.
@@ -262,7 +291,10 @@ def _clone_node(
262291
copy.update(self.get_source_attributes(source))
263292

264293
if isinstance(mods, dict):
265-
copy.update(mods)
294+
allowed_keys = EDIT_ALLOWED_OVERRIDES if can_edit_source_channel else ALLOWED_OVERRIDES
295+
for key, value in mods.items():
296+
if key in copy and key in allowed_keys:
297+
copy[key] = value
266298

267299
# There might be some legacy nodes that don't have these, so ensure they are added
268300
if (

contentcuration/contentcuration/tests/test_exportchannel.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from .testdata import create_studio_file
2828
from .testdata import node as create_node
2929
from .testdata import slideshow
30+
from .testdata import thumbnail_bytes
3031
from contentcuration import models as cc
3132
from contentcuration.utils.publish import convert_channel_thumbnail
3233
from contentcuration.utils.publish import create_content_database
@@ -39,9 +40,6 @@
3940
pytestmark = pytest.mark.django_db
4041

4142

42-
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
43-
44-
4543
def description():
4644
return "".join(random.sample(string.printable, 20))
4745

contentcuration/contentcuration/tests/testdata.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
pytestmark = pytest.mark.django_db
2323

2424

25+
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
26+
27+
2528
def video():
2629
"""
2730
Create a video content kind entry.

0 commit comments

Comments
 (0)