Skip to content

Commit

Permalink
Enroll the coach and grant her staff access to the CCX on creation
Browse files Browse the repository at this point in the history
Make the course URL pattern more generic.

Comment newly added functionality.
  • Loading branch information
jamiefolsom committed Oct 19, 2015
1 parent b4ff9f8 commit 66b9c91
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
15 changes: 13 additions & 2 deletions lms/djangoapps/ccx/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
from django.test import RequestFactory
from edxmako.shortcuts import render_to_response
from request_cache.middleware import RequestCache
from student.roles import CourseCcxCoachRole
from opaque_keys.edx.locations import SlashSeparatedCourseKey
from instructor.access import allow_access
from student.roles import CourseStaffRole, CourseCcxCoachRole
from student.models import (
CourseEnrollment,
CourseEnrollmentAllowed,
Expand Down Expand Up @@ -210,17 +212,26 @@ def test_no_ccx_created(self):
def test_create_ccx(self):
"""
Create CCX. Follow redirect to coach dashboard, confirm we see
the coach dashboard for the new CCX.
the coach dashboard for the new CCX. Also, confirm that the coach
has staff access to it.
"""

self.make_coach()
url = reverse(
'create_ccx',
kwargs={'course_id': self.course.id.to_deprecated_string()})

response = self.client.post(url, {'name': 'New CCX'})
self.assertEqual(response.status_code, 302)
url = response.get('location') # pylint: disable=no-member
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
pattern = "http://[^\/]+/courses/([^\/]+)/ccx_coach"
results = re.match(pattern, url)
ccx_key = results.group(1)
course_key = SlashSeparatedCourseKey.from_deprecated_string(ccx_key)
self.assertTrue(CourseStaffRole(course_key).has_user(self.coach))
self.assertTrue(CourseEnrollment.is_enrolled(self.coach, course_key))
self.assertTrue(re.search('id="ccx-schedule"', response.content))

@SharedModuleStoreTestCase.modifies_courseware
Expand Down
23 changes: 21 additions & 2 deletions lms/djangoapps/ccx/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
from opaque_keys.edx.keys import CourseKey
from ccx_keys.locator import CCXLocator
from student.roles import CourseCcxCoachRole
from student.roles import (
CourseCcxCoachRole,
CourseStaffRole
)
from student.models import CourseEnrollment

from instructor.offline_gradecalc import student_grades
Expand All @@ -48,6 +52,9 @@
get_email_params,
)

from instructor.access import allow_access
from courseware.access import has_access

from .models import CustomCourseForEdX
from .overrides import (
get_override_for_ccx,
Expand All @@ -56,7 +63,6 @@
bulk_delete_ccx_override_fields,
)


log = logging.getLogger(__name__)
TODAY = datetime.datetime.today # for patching in tests

Expand Down Expand Up @@ -183,9 +189,22 @@ def create_ccx(request, course, ccx=None):
override_field_for_ccx(ccx, vertical, hidden, True)

ccx_id = CCXLocator.from_course_locator(course.id, ccx.id) # pylint: disable=no-member
ccx_course = get_course_by_id(ccx_id)
url = reverse('ccx_coach_dashboard', kwargs={'course_id': ccx_id})
return redirect(url)

# Enroll the coach in the course
email_params = get_email_params(course, auto_enroll=True, course_key=ccx_id, display_name=ccx.display_name)
enroll_email(
course_id=ccx_id,
student_email=request.user.email,
auto_enroll=True,
email_students=True,
email_params=email_params,
)

# Grant the coach staff access to the course
allow_access(ccx_course, request.user, "staff")
return redirect(url)

@ensure_csrf_cookie
@cache_control(no_cache=True, no_store=True, must_revalidate=True)
Expand Down

0 comments on commit 66b9c91

Please sign in to comment.