Skip to content

Commit

Permalink
fix: disable submit button for archived courses (#34920)
Browse files Browse the repository at this point in the history
* fix: disable submit button for archived courses
  • Loading branch information
Anas12091101 authored Jul 26, 2024
1 parent 12569b4 commit 3b8973a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
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
31 changes: 31 additions & 0 deletions xmodule/tests/test_capa_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,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 3b8973a

Please sign in to comment.