Skip to content
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
34 changes: 33 additions & 1 deletion contentcuration/contentcuration/db/models/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,35 @@ def log_lock_time_spent(timespent):
logging.debug("Spent {} seconds inside an mptt lock".format(timespent))


# Fields that are allowed to be overridden on copies coming from a source that the user
# does not have edit rights to.
ALLOWED_OVERRIDES = {
"node_id",
"title",
"description",
"aggregator",
"provider",
"language_id",
"grade_levels",
"resource_types",
"learning_activities",
"accessibility_labels",
"categories",
"learner_needs",
"role",
"extra_fields",
"suggested_duration",
}

EDIT_ALLOWED_OVERRIDES = ALLOWED_OVERRIDES.union({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With these 3 words all in the variable name, the variable's purpose took me a moment to decipher (thinking 'overrides' already feels like an 'edit'). Not sure if EDITOR makes it clearer?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was not at the race for my variable naming this day. EDITOR does make a bit more sense, definitely.

"license_id",
"license_description",
"extra_fields",
"copyright_holder",
"author",
})


class CustomContentNodeTreeManager(TreeManager.from_queryset(CustomTreeQuerySet)):
# Added 7-31-2018. We can remove this once we are certain we have eliminated all cases
# where root nodes are getting prepended rather than appended to the tree list.
Expand Down Expand Up @@ -262,7 +291,10 @@ def _clone_node(
copy.update(self.get_source_attributes(source))

if isinstance(mods, dict):
copy.update(mods)
allowed_keys = EDIT_ALLOWED_OVERRIDES if can_edit_source_channel else ALLOWED_OVERRIDES
for key, value in mods.items():
if key in copy and key in allowed_keys:
copy[key] = value

# There might be some legacy nodes that don't have these, so ensure they are added
if (
Expand Down
4 changes: 1 addition & 3 deletions contentcuration/contentcuration/tests/test_exportchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from .testdata import create_studio_file
from .testdata import node as create_node
from .testdata import slideshow
from .testdata import thumbnail_bytes
from contentcuration import models as cc
from contentcuration.utils.publish import convert_channel_thumbnail
from contentcuration.utils.publish import create_content_database
Expand All @@ -39,9 +40,6 @@
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
3 changes: 3 additions & 0 deletions contentcuration/contentcuration/tests/testdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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 video():
"""
Create a video content kind entry.
Expand Down
Loading