Skip to content
Snippets Groups Projects
Commit 5235fa7b authored by Calen Pennington's avatar Calen Pennington
Browse files

Respect masquerade status when resetting student schedules

parent 1fa29a60
No related merge requests found
......@@ -145,7 +145,79 @@ class TestCourseOutlinePage(SharedModuleStoreTestCase):
url = '{}{}'.format(course_home_url(course), 'reset_deadlines')
self.client.post(url)
updated_schedule = Schedule.objects.get(enrollment=enrollment)
self.assertEqual(updated_schedule.start_date.day, datetime.datetime.today().day)
self.assertEqual(updated_schedule.start_date.date(), datetime.datetime.today().date())
def test_reset_course_deadlines_masquerade_specific_student(self):
course = self.courses[0]
student_schedule = ScheduleFactory(
start_date=timezone.now() - datetime.timedelta(1),
enrollment=CourseEnrollment.objects.get(course_id=course.id, user=self.user),
)
staff = StaffFactory(course_key=course.id)
staff_schedule = ScheduleFactory(
start_date=timezone.now() - datetime.timedelta(1),
enrollment__course__id=course.id,
enrollment__user=staff,
)
self.client.login(username=staff.username, password=TEST_PASSWORD)
masquerade_url = reverse(
'masquerade_update',
kwargs={
'course_key_string': six.text_type(course.id),
}
)
response = self.client.post(
masquerade_url,
json.dumps({"role": 'student', "group_id": None, "user_name": self.user.username}),
"application/json"
)
assert response.status_code == 200
url = '{}{}'.format(course_home_url(course), 'reset_deadlines')
self.client.post(url)
updated_schedule = Schedule.objects.get(id=student_schedule.id)
self.assertEqual(updated_schedule.start_date.date(), datetime.datetime.today().date())
updated_staff_schedule = Schedule.objects.get(id=staff_schedule.id)
self.assertEqual(updated_staff_schedule.start_date, staff_schedule.start_date)
def test_reset_course_deadlines_masquerade_generic_student(self):
course = self.courses[0]
student_schedule = ScheduleFactory(
start_date=timezone.now() - datetime.timedelta(1),
enrollment=CourseEnrollment.objects.get(course_id=course.id, user=self.user),
)
staff = StaffFactory(course_key=course.id)
staff_schedule = ScheduleFactory(
start_date=timezone.now() - datetime.timedelta(1),
enrollment__course__id=course.id,
enrollment__user=staff,
)
self.client.login(username=staff.username, password=TEST_PASSWORD)
masquerade_url = reverse(
'masquerade_update',
kwargs={
'course_key_string': six.text_type(course.id),
}
)
response = self.client.post(
masquerade_url,
json.dumps({"role": 'student', "group_id": None, "user_name": None}),
"application/json"
)
assert response.status_code == 200
url = '{}{}'.format(course_home_url(course), 'reset_deadlines')
self.client.post(url)
updated_student_schedule = Schedule.objects.get(id=student_schedule.id)
self.assertEqual(updated_student_schedule.start_date, student_schedule.start_date)
updated_staff_schedule = Schedule.objects.get(id=staff_schedule.id)
self.assertEqual(updated_staff_schedule.start_date.date(), datetime.datetime.today().date())
class TestCourseOutlinePageWithPrerequisites(SharedModuleStoreTestCase, MilestonesTestCaseMixin):
......
......@@ -21,7 +21,9 @@ from pytz import UTC
from waffle.models import Switch
from web_fragments.fragment import Fragment
from lms.djangoapps.courseware.access import has_access
from lms.djangoapps.courseware.courses import get_course_overview_with_access
from lms.djangoapps.courseware.masquerade import setup_masquerade
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from openedx.core.djangoapps.plugin_api.views import EdxFragmentView
from student.models import CourseEnrollment
......@@ -168,11 +170,22 @@ def reset_course_deadlines(request, course_id):
Set the start_date of a schedule to today, which in turn will adjust due dates for
sequentials belonging to a self paced course
"""
course = CourseOverview.objects.get(id=course_id)
course_key = CourseKey.from_string(course_id)
course = CourseOverview.objects.get(id=course_key)
if course.self_paced:
enrollment = CourseEnrollment.objects.get(user=request.user, course=course_id)
masquerade_details, masquerade_user = setup_masquerade(
request,
course_key,
has_access(request.user, 'staff', course, course_key)
)
if masquerade_details and masquerade_details.role == 'student' and masquerade_details.user_name:
# Masquerading as a specific student, so reset that student's schedule
user = masquerade_user
else:
user = request.user
enrollment = CourseEnrollment.objects.get(user=user, course=course_key)
schedule = enrollment.schedule
if schedule:
schedule.start_date = datetime.datetime.now(pytz.utc)
schedule.save()
return redirect(reverse('openedx.course_experience.course_home', args=[six.text_type(course_id)]))
return redirect(reverse('openedx.course_experience.course_home', args=[six.text_type(course_key)]))
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