Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport fix: disable submit button for archived courses (#34920) to redwood #35248

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
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
Loading