diff --git a/cms/djangoapps/contentstore/tests/test_course_index.py b/cms/djangoapps/contentstore/tests/test_course_index.py index ec0c0b1f8e..42ca510c1f 100644 --- a/cms/djangoapps/contentstore/tests/test_course_index.py +++ b/cms/djangoapps/contentstore/tests/test_course_index.py @@ -61,7 +61,7 @@ class TestCourseIndex(CourseTestCase): Test the error conditions for the access """ locator = loc_mapper().translate_location(self.course.location.course_id, self.course.location, False, True) - outline_url = reverse('contentstore.views.course_handler', kwargs={'course_url': unicode(locator)}) + outline_url = locator.url_reverse('course/', '') # register a non-staff member and try to delete the course branch non_staff_client, _ = self.createNonStaffAuthedUserClient() response = non_staff_client.delete(outline_url, {}, HTTP_ACCEPT='application/json') diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index cf6ef7f626..8fd1c1a5dc 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -60,7 +60,7 @@ __all__ = ['create_new_course', 'course_info', 'course_handler', @login_required -def course_handler(request, course_url): +def course_handler(request, tag=None, course_id=None, branch=None, version_guid=None, block=None): """ The restful handler for course specific requests. It provides the course tree with the necessary information for identifying and labeling the parts. The root @@ -84,7 +84,10 @@ def course_handler(request, course_url): if 'application/json' in request.META.get('HTTP_ACCEPT', 'application/json'): if request.method == 'GET': raise NotImplementedError('coming soon') - elif not has_access(request.user, BlockUsageLocator(course_url)): + elif not has_access( + request.user, + BlockUsageLocator(course_id=course_id, branch=branch, version_guid=version_guid, usage_id=block) + ): raise PermissionDenied() elif request.method == 'POST': raise NotImplementedError() @@ -95,7 +98,7 @@ def course_handler(request, course_url): else: return HttpResponseBadRequest() elif request.method == 'GET': # assume html - return course_index(request, course_url) + return course_index(request, course_id, branch, version_guid, block) else: return HttpResponseNotFound() @@ -108,18 +111,18 @@ def old_course_index_shim(request, org, course, name): """ old_location = Location(['i4x', org, course, 'course', name]) locator = loc_mapper().translate_location(old_location.course_id, old_location, False, True) - return course_index(request, locator) + return course_index(request, locator.course_id, locator.branch, locator.version_guid, locator.usage_id) @login_required @ensure_csrf_cookie -def course_index(request, course_url): +def course_index(request, course_id, branch, version_guid, block): """ Display an editable course overview. org, course, name: Attributes of the Location for the item to edit """ - location = BlockUsageLocator(course_url) + location = BlockUsageLocator(course_id=course_id, branch=branch, version_guid=version_guid, usage_id=block) # TODO: when converting to split backend, if location does not have a usage_id, # we'll need to get the course's root block_id if not has_access(request.user, location): diff --git a/cms/djangoapps/contentstore/views/user.py b/cms/djangoapps/contentstore/views/user.py index d307e1295e..1d6804b564 100644 --- a/cms/djangoapps/contentstore/views/user.py +++ b/cms/djangoapps/contentstore/views/user.py @@ -47,12 +47,13 @@ def index(request): def format_course_for_view(course): # published = false b/c studio manipulates draft versions not b/c the course isn't pub'd - course_url = loc_mapper().translate_location( + course_loc = loc_mapper().translate_location( course.location.course_id, course.location, published=False, add_entry_if_missing=True ) return ( course.display_name, - reverse("contentstore.views.course_handler", kwargs={'course_url': course_url}), + # note, couldn't get django reverse to work; so, wrote workaround + course_loc.url_reverse('course/', ''), get_lms_link_for_item( course.location ), diff --git a/cms/templates/widgets/header.html b/cms/templates/widgets/header.html index 3be0b3723a..5ae7d0d659 100644 --- a/cms/templates/widgets/header.html +++ b/cms/templates/widgets/header.html @@ -15,10 +15,7 @@ % if context_course: <% ctx_loc = context_course.location - index_url = reverse( - 'contentstore.views.course_handler', - kwargs={'course_url': loc_mapper().translate_location(ctx_loc.course_id, ctx_loc, False, True)} - ) + index_url = loc_mapper().translate_location(ctx_loc.course_id, ctx_loc, False, True).url_reverse('course/', '') %>