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
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.24 on 2025-09-23 19:47

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('contentstore', '0012_componentlink_top_level_parent_and_more'),
]

operations = [
migrations.AddField(
model_name='componentlink',
name='downstream_is_modified',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='containerlink',
name='downstream_is_modified',
field=models.BooleanField(default=False),
),
]
5 changes: 5 additions & 0 deletions cms/djangoapps/contentstore/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class EntityLinkBase(models.Model):
top_level_parent = models.ForeignKey("ContainerLink", on_delete=models.SET_NULL, null=True, blank=True)
version_synced = models.IntegerField()
version_declined = models.IntegerField(null=True, blank=True)
downstream_is_modified = models.BooleanField(default=False)
created = manual_date_time_field()
updated = manual_date_time_field()

Expand Down Expand Up @@ -257,6 +258,7 @@ def update_or_create(
version_synced: int,
top_level_parent_usage_key: UsageKey | None = None,
version_declined: int | None = None,
downstream_is_modified: bool = False,
created: datetime | None = None,
) -> "ComponentLink":
"""
Expand All @@ -281,6 +283,7 @@ def update_or_create(
'version_synced': version_synced,
'version_declined': version_declined,
'top_level_parent': top_level_parent,
'downstream_is_modified': downstream_is_modified,
}
if upstream_block:
new_values['upstream_block'] = upstream_block
Expand Down Expand Up @@ -482,6 +485,7 @@ def update_or_create(
version_synced: int,
top_level_parent_usage_key: UsageKey | None = None,
version_declined: int | None = None,
downstream_is_modified: bool = False,
created: datetime | None = None,
) -> "ContainerLink":
"""
Expand All @@ -506,6 +510,7 @@ def update_or_create(
'version_synced': version_synced,
'version_declined': version_declined,
'top_level_parent': top_level_parent,
'downstream_is_modified': downstream_is_modified,
}
if upstream_container_id:
new_values['upstream_container_id'] = upstream_container_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ def test_unit_sync(self):
'updated': date_format,
'upstream_key': self.upstream_html1["id"],
'upstream_type': 'component',
'downstream_is_modified': False,
},
{
'id': 2,
Expand All @@ -400,7 +401,8 @@ def test_unit_sync(self):
'created': date_format,
'updated': date_format,
'upstream_key': self.upstream_problem1["id"],
'upstream_type': 'component'
'upstream_type': 'component',
'downstream_is_modified': False,
},
{
'id': 3,
Expand All @@ -417,7 +419,8 @@ def test_unit_sync(self):
'created': date_format,
'updated': date_format,
'upstream_key': self.upstream_problem2["id"],
'upstream_type': 'component'
'upstream_type': 'component',
'downstream_is_modified': False,
},
{
'id': 1,
Expand All @@ -434,7 +437,8 @@ def test_unit_sync(self):
'created': date_format,
'updated': date_format,
'upstream_key': self.upstream_unit["id"],
'upstream_type': 'container'
'upstream_type': 'container',
'downstream_is_modified': False,
}
]
data = downstreams.json()
Expand Down Expand Up @@ -533,6 +537,7 @@ def test_unit_sync(self):
'updated': date_format,
'upstream_key': self.upstream_html1["id"],
'upstream_type': 'component',
'downstream_is_modified': False,
},
{
'id': 2,
Expand All @@ -549,7 +554,8 @@ def test_unit_sync(self):
'created': date_format,
'updated': date_format,
'upstream_key': self.upstream_problem1["id"],
'upstream_type': 'component'
'upstream_type': 'component',
'downstream_is_modified': False,
},
{
'id': 3,
Expand All @@ -566,7 +572,8 @@ def test_unit_sync(self):
'created': date_format,
'updated': date_format,
'upstream_key': self.upstream_problem2["id"],
'upstream_type': 'component'
'upstream_type': 'component',
'downstream_is_modified': False,
},
{
'id': 1,
Expand All @@ -583,7 +590,8 @@ def test_unit_sync(self):
'created': date_format,
'updated': date_format,
'upstream_key': self.upstream_unit["id"],
'upstream_type': 'container'
'upstream_type': 'container',
'downstream_is_modified': False,
}
]
data = downstreams.json()
Expand Down Expand Up @@ -681,6 +689,7 @@ def test_unit_sync(self):
'updated': date_format,
'upstream_key': self.upstream_html1["id"],
'upstream_type': 'component',
'downstream_is_modified': False,
},
{
'id': 2,
Expand All @@ -697,7 +706,8 @@ def test_unit_sync(self):
'created': date_format,
'updated': date_format,
'upstream_key': self.upstream_problem1["id"],
'upstream_type': 'component'
'upstream_type': 'component',
'downstream_is_modified': False,
},
{
'id': 4,
Expand All @@ -714,7 +724,8 @@ def test_unit_sync(self):
'created': date_format,
'updated': date_format,
'upstream_key': upstream_problem3["id"],
'upstream_type': 'component'
'upstream_type': 'component',
'downstream_is_modified': False,
},
{
'id': 1,
Expand All @@ -731,7 +742,8 @@ def test_unit_sync(self):
'created': date_format,
'updated': date_format,
'upstream_key': self.upstream_unit["id"],
'upstream_type': 'container'
'upstream_type': 'container',
'downstream_is_modified': False,
}
]
data = downstreams.json()
Expand Down Expand Up @@ -810,6 +822,7 @@ def test_unit_sync(self):
'updated': date_format,
'upstream_key': self.upstream_html1["id"],
'upstream_type': 'component',
'downstream_is_modified': False,
},
{
'id': 2,
Expand All @@ -826,7 +839,8 @@ def test_unit_sync(self):
'created': date_format,
'updated': date_format,
'upstream_key': self.upstream_problem1["id"],
'upstream_type': 'component'
'upstream_type': 'component',
'downstream_is_modified': False,
},
{
'id': 4,
Expand All @@ -843,7 +857,8 @@ def test_unit_sync(self):
'created': date_format,
'updated': date_format,
'upstream_key': upstream_problem3["id"],
'upstream_type': 'component'
'upstream_type': 'component',
'downstream_is_modified': False,
},
{
'id': 1,
Expand All @@ -860,7 +875,8 @@ def test_unit_sync(self):
'created': date_format,
'updated': date_format,
'upstream_key': self.upstream_unit["id"],
'upstream_type': 'container'
'upstream_type': 'container',
'downstream_is_modified': False,
}
]
data = downstreams.json()
Expand Down Expand Up @@ -1047,6 +1063,7 @@ def test_modified_html_copy_paste(self):
Test that we can sync a html from a library into a course.
"""
# 1️⃣ First, create the html in the course, using the upstream problem as a template:
date_format = self.now.isoformat().split("+")[0] + 'Z'
downstream_html1 = self._create_block_from_upstream(
block_category="html",
parent_usage_key=str(self.course_subsection.usage_key),
Expand Down Expand Up @@ -1079,6 +1096,34 @@ def test_modified_html_copy_paste(self):
>This is the HTML.</html>
""")

# Check that: The downstream links are created as expected for the component
downstreams = self._get_downstream_links(
course_id=str(self.course.id)
)
expected_downstreams = [
{
'id': 1,
'upstream_context_title': self.library_title,
'upstream_version': 2,
'ready_to_sync': False,
'ready_to_sync_from_children': False,
'upstream_context_key': self.library_id,
'downstream_usage_key': downstream_html1["locator"],
'downstream_context_key': str(self.course.id),
'top_level_parent_usage_key': None,
'version_synced': 2,
'version_declined': None,
'created': date_format,
'updated': date_format,
'upstream_key': self.upstream_html1["id"],
'upstream_type': 'component',
'downstream_is_modified': False,
},
]
data = downstreams.json()
self.assertEqual(data["count"], 1)
self.assertListEqual(data["results"], expected_downstreams)

# 2️⃣ Now, lets modify the upstream html AND the downstream display_name:
self._update_course_block_fields(downstream_html1["locator"], {
"display_name": "New Text Content",
Expand Down Expand Up @@ -1111,9 +1156,36 @@ def test_modified_html_copy_paste(self):
'version_declined': None,
'ready_to_sync': True, # <--- updated
'error_message': None,
'is_modified': True,
'is_modified': True, # <--- updated
})

downstreams = self._get_downstream_links(
course_id=str(self.course.id)
)
expected_downstreams = [
{
'id': 1,
'upstream_context_title': self.library_title,
'upstream_version': 3, # <--- updated
'ready_to_sync': True, # <--- updated
'ready_to_sync_from_children': False,
'upstream_context_key': self.library_id,
'downstream_usage_key': downstream_html1["locator"],
'downstream_context_key': str(self.course.id),
'top_level_parent_usage_key': None,
'version_synced': 2,
'version_declined': None,
'created': date_format,
'updated': date_format,
'upstream_key': self.upstream_html1["id"],
'upstream_type': 'component',
'downstream_is_modified': True, # <--- updated
},
]
data = downstreams.json()
self.assertEqual(data["count"], 1)
self.assertListEqual(data["results"], expected_downstreams)

# 3️⃣ Now, sync and check the resulting OLX of the downstream

self._sync_downstream(downstream_html1["locator"])
Expand Down
Loading
Loading