Skip to content

Commit

Permalink
backport fix: disable submit button for archived courses (#34920) to …
Browse files Browse the repository at this point in the history
…redwood (#35248)

* fix: disable submit button for archived courses (#34920)
  • Loading branch information
Anas12091101 authored Aug 8, 2024
1 parent c5d7507 commit d5c84e9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
15 changes: 14 additions & 1 deletion xmodule/capa_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,12 +795,25 @@ def generate_report_data(self, user_state_iterator, limit_responses=None):
}
yield (user_state.username, report)

@property
def course_end_date(self):
"""
Return the end date of the problem's course
"""

try:
course_block_key = self.runtime.course_entry.structure['root']
return self.runtime.course_entry.structure['blocks'][course_block_key].fields['end']
except (AttributeError, KeyError):
return None

@property
def close_date(self):
"""
Return the date submissions should be closed from.
"""
due_date = self.due

due_date = self.due or self.course_end_date

if self.graceperiod is not None and due_date:
return due_date + self.graceperiod
Expand Down
33 changes: 32 additions & 1 deletion xmodule/tests/test_capa_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import random
import textwrap
import unittest
from unittest.mock import DEFAULT, Mock, patch
from unittest.mock import DEFAULT, Mock, patch, PropertyMock

import pytest
import ddt
Expand Down Expand Up @@ -656,6 +656,37 @@ def test_closed(self):
due=self.yesterday_str)
assert block.closed()

@patch.object(ProblemBlock, 'course_end_date', new_callable=PropertyMock)
def test_closed_for_archive(self, mock_course_end_date):

# Utility to create a datetime object in the past
def past_datetime(days):
return (datetime.datetime.now(UTC) - datetime.timedelta(days=days))

# Utility to create a datetime object in the future
def future_datetime(days):
return (datetime.datetime.now(UTC) + datetime.timedelta(days=days))

block = CapaFactory.create(max_attempts="1", attempts="0")

# For active courses without graceperiod
mock_course_end_date.return_value = future_datetime(10)
assert not block.closed()

# For archive courses without graceperiod
mock_course_end_date.return_value = past_datetime(10)
assert block.closed()

# For active courses with graceperiod
mock_course_end_date.return_value = future_datetime(10)
block.graceperiod = datetime.timedelta(days=2)
assert not block.closed()

# For archive courses with graceperiod
mock_course_end_date.return_value = past_datetime(2)
block.graceperiod = datetime.timedelta(days=3)
assert not block.closed()

def test_parse_get_params(self):

# Valid GET param dict
Expand Down

0 comments on commit d5c84e9

Please sign in to comment.