Skip to content
Snippets Groups Projects
Unverified Commit 598d110f authored by DawoudSheraz's avatar DawoudSheraz Committed by GitHub
Browse files

Merge pull request #19326 from edx/dsheraz/educator_3140

EDUCATOR-3140 prevent saving pre-1900 subsection due dates
parents e27a3992 05663098
No related branches found
No related tags found
No related merge requests found
......@@ -584,6 +584,7 @@ def _save_xblock(user, xblock, data=None, children_strings=None, metadata=None,
field.write_to(xblock, value)
validate_and_update_xblock_due_date(xblock)
# update the xblock and call any xblock callbacks
xblock = _update_with_callback(xblock, user, old_metadata, old_content)
......@@ -1453,6 +1454,14 @@ def _get_release_date(xblock, user=None):
return get_default_time_display(xblock.start) if xblock.start != DEFAULT_START_DATE else None
def validate_and_update_xblock_due_date(xblock):
"""
Validates the due date for the xblock, and set to None if pre-1900 due date provided
"""
if xblock.due and xblock.due.year < 1900:
xblock.due = None
def _get_release_date_from(xblock):
"""
Returns a string representation of the section or subsection that sets the xblock's release date
......
......@@ -1418,6 +1418,7 @@ class TestEditItemSetup(ItemTest):
self.course_update_url = reverse_usage_url("xblock_handler", self.usage_key)
@ddt.ddt
class TestEditItem(TestEditItemSetup):
"""
Test xblock update.
......@@ -1474,6 +1475,32 @@ class TestEditItem(TestEditItemSetup):
self.assertEqual(sequential.due, datetime(2010, 11, 22, 4, 0, tzinfo=UTC))
self.assertEqual(sequential.start, datetime(2010, 9, 12, 14, 0, tzinfo=UTC))
@ddt.data(
'1000-01-01T00:00Z',
'0150-11-21T14:45Z',
'1899-12-31T23:59Z',
'1789-06-06T22:10Z',
'1001-01-15T19:32Z',
)
def test_xblock_due_date_validity(self, date):
"""
Test due date for the subsection is not pre-1900
"""
self.client.ajax_post(
self.seq_update_url,
data={'metadata': {'due': date}}
)
sequential = self.get_item_from_modulestore(self.seq_usage_key)
xblock_info = create_xblock_info(
sequential,
include_child_info=True,
include_children_predicate=ALWAYS,
user=self.user
)
# Both display and actual value should be None
self.assertEquals(xblock_info['due_date'], u'')
self.assertIsNone(xblock_info['due'])
def test_update_generic_fields(self):
new_display_name = 'New Display Name'
new_max_attempts = 2
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment