Commit 0251e8e1 by Brian Beggs

Merge pull request #11545 from mitocw/feature/aq/support_mutiple_instances_ccx_mitocw#175

Allow multiple instances of ccx
parents 71e0ce7a 2ee91050
......@@ -185,7 +185,7 @@ class TestCoachDashboard(CcxTestCase, LoginEnrollmentTestCase):
'<form action=".+create_ccx"',
response.content))
def test_create_ccx(self):
def test_create_ccx(self, ccx_name='New CCX'):
"""
Create CCX. Follow redirect to coach dashboard, confirm we see
the coach dashboard for the new CCX.
......@@ -196,7 +196,7 @@ class TestCoachDashboard(CcxTestCase, LoginEnrollmentTestCase):
'create_ccx',
kwargs={'course_id': unicode(self.course.id)})
response = self.client.post(url, {'name': 'New CCX'})
response = self.client.post(url, {'name': ccx_name})
self.assertEqual(response.status_code, 302)
url = response.get('location') # pylint: disable=no-member
response = self.client.get(url)
......@@ -221,6 +221,10 @@ class TestCoachDashboard(CcxTestCase, LoginEnrollmentTestCase):
role = CourseCcxCoachRole(course_key)
self.assertTrue(role.has_user(self.coach, refresh=True))
@ddt.data("CCX demo 1", "CCX demo 2", "CCX demo 3")
def test_create_multiple_ccx(self, ccx_name):
self.test_create_ccx(ccx_name)
def test_get_date(self):
"""
Assert that get_date returns valid date.
......
......@@ -127,6 +127,30 @@ def get_ccx_for_coach(course, coach):
return None
def get_ccx_by_ccx_id(course, coach, ccx_id):
"""
Finds a CCX of given coach on given master course.
Arguments:
course (CourseDescriptor): Master course
coach (User): Coach to ccx
ccx_id (long): Id of ccx
Returns:
ccx (CustomCourseForEdX): Instance of CCX.
"""
try:
ccx = CustomCourseForEdX.objects.get(
id=ccx_id,
course_id=course.id,
coach=coach
)
except CustomCourseForEdX.DoesNotExist:
return None
return ccx
def get_valid_student_email(identifier):
"""
Helper function to get an user email from an identifier and validate it.
......
......@@ -56,6 +56,7 @@ from lms.djangoapps.ccx.utils import (
ccx_course,
ccx_students_enrolling_center,
get_ccx_for_coach,
get_ccx_by_ccx_id,
get_date,
parse_date,
prep_course_for_grading,
......@@ -93,8 +94,8 @@ def coach_dashboard(view):
# if there is a ccx, we must validate that it is the ccx for this coach
if ccx is not None:
coach_ccx = get_ccx_for_coach(course, request.user)
if coach_ccx is None or coach_ccx.id != ccx.id:
coach_ccx = get_ccx_by_ccx_id(course, request.user, ccx.id)
if coach_ccx is None:
return HttpResponseForbidden(
_('You must be the coach for this ccx to access this view')
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment