Deserialze values coming into course_groups views

This commit is contained in:
Diana Huang
2014-05-22 10:52:30 -04:00
parent 253ed3b855
commit ae95e07cce
2 changed files with 18 additions and 1 deletions

View File

@@ -67,7 +67,7 @@ class AddUsersToCohortTestCase(ModuleStoreTestCase):
expected_unknown = expected_unknown or [] expected_unknown = expected_unknown or []
request = RequestFactory().post("dummy_url", {"users": users_string}) request = RequestFactory().post("dummy_url", {"users": users_string})
request.user = self.staff_user request.user = self.staff_user
response = add_users_to_cohort(request, self.course.id, self.cohort1.id) response = add_users_to_cohort(request, self.course.id.to_deprecated_string(), self.cohort1.id)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
result = json.loads(response.content) result = json.loads(response.content)
self.assertEqual(result.get("success"), True) self.assertEqual(result.get("success"), True)

View File

@@ -8,6 +8,7 @@ import json
import logging import logging
import re import re
from xmodule.modulestore.locations import SlashSeparatedCourseKey
from courseware.courses import get_course_with_access from courseware.courses import get_course_with_access
from edxmako.shortcuts import render_to_response from edxmako.shortcuts import render_to_response
@@ -40,6 +41,10 @@ def list_cohorts(request, course_key):
{'success': True, {'success': True,
'cohorts': [{'name': name, 'id': id}, ...]} 'cohorts': [{'name': name, 'id': id}, ...]}
""" """
# this is a string when we get it here
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_key)
get_course_with_access(request.user, 'staff', course_key) get_course_with_access(request.user, 'staff', course_key)
all_cohorts = [{'name': c.name, 'id': c.id} all_cohorts = [{'name': c.name, 'id': c.id}
@@ -63,6 +68,9 @@ def add_cohort(request, course_key):
{'success': False, {'success': False,
'msg': error_msg} if there's an error 'msg': error_msg} if there's an error
""" """
# this is a string when we get it here
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_key)
get_course_with_access(request.user, 'staff', course_key) get_course_with_access(request.user, 'staff', course_key)
name = request.POST.get("name") name = request.POST.get("name")
@@ -97,6 +105,9 @@ def users_in_cohort(request, course_key, cohort_id):
'users': [{'username': ..., 'email': ..., 'name': ...}] 'users': [{'username': ..., 'email': ..., 'name': ...}]
} }
""" """
# this is a string when we get it here
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_key)
get_course_with_access(request.user, 'staff', course_key) get_course_with_access(request.user, 'staff', course_key)
# this will error if called with a non-int cohort_id. That's ok--it # this will error if called with a non-int cohort_id. That's ok--it
@@ -144,6 +155,8 @@ def add_users_to_cohort(request, course_key, cohort_id):
'present': [str1, str2, ...], # already there 'present': [str1, str2, ...], # already there
'unknown': [str1, str2, ...]} 'unknown': [str1, str2, ...]}
""" """
# this is a string when we get it here
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_key)
get_course_with_access(request.user, 'staff', course_key) get_course_with_access(request.user, 'staff', course_key)
cohort = cohorts.get_cohort_by_id(course_key, cohort_id) cohort = cohorts.get_cohort_by_id(course_key, cohort_id)
@@ -193,6 +206,8 @@ def remove_user_from_cohort(request, course_key, cohort_id):
{'success': False, {'success': False,
'msg': error_msg} 'msg': error_msg}
""" """
# this is a string when we get it here
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_key)
get_course_with_access(request.user, 'staff', course_key) get_course_with_access(request.user, 'staff', course_key)
username = request.POST.get('username') username = request.POST.get('username')
@@ -215,6 +230,8 @@ def debug_cohort_mgmt(request, course_key):
""" """
Debugging view for dev. Debugging view for dev.
""" """
# this is a string when we get it here
course_key = SlashSeparatedCourseKey.from_deprecated_string(course_key)
# add staff check to make sure it's safe if it's accidentally deployed. # add staff check to make sure it's safe if it's accidentally deployed.
get_course_with_access(request.user, 'staff', course_key) get_course_with_access(request.user, 'staff', course_key)