Commit 6b3b7fe2 by cahrens

Some cleanup.

parent 0a063342
...@@ -18,4 +18,5 @@ Feature: Course checklists ...@@ -18,4 +18,5 @@ Feature: Course checklists
Scenario: A task can link to a location outside Studio Scenario: A task can link to a location outside Studio
Given I have opened Checklists Given I have opened Checklists
When I select a link to help page When I select a link to help page
Then I am brought to the help page in a new window Then I am brought to the help page in a new window
\ No newline at end of file
...@@ -791,9 +791,7 @@ def upload_asset(request, org, course, coursename): ...@@ -791,9 +791,7 @@ def upload_asset(request, org, course, coursename):
return HttpResponseBadRequest() return HttpResponseBadRequest()
# construct a location from the passed in path # construct a location from the passed in path
location = ['i4x', org, course, 'course', coursename] location = get_location_and_verify_access(request, org, course, coursename)
if not has_access(request.user, location):
return HttpResponseForbidden()
# Does the course actually exist?!? Get anything from it to prove its existance # Does the course actually exist?!? Get anything from it to prove its existance
...@@ -945,11 +943,7 @@ def landing(request, org, course, coursename): ...@@ -945,11 +943,7 @@ def landing(request, org, course, coursename):
@ensure_csrf_cookie @ensure_csrf_cookie
def static_pages(request, org, course, coursename): def static_pages(request, org, course, coursename):
location = ['i4x', org, course, 'course', coursename] location = get_location_and_verify_access(request, org, course, coursename)
# check that logged in user has permissions to this item
if not has_access(request.user, location):
raise PermissionDenied()
course = modulestore().get_item(location) course = modulestore().get_item(location)
...@@ -1221,11 +1215,7 @@ def course_settings_updates(request, org, course, name, section): ...@@ -1221,11 +1215,7 @@ def course_settings_updates(request, org, course, name, section):
org, course: Attributes of the Location for the item to edit org, course: Attributes of the Location for the item to edit
section: one of details, faculty, grading, problems, discussions section: one of details, faculty, grading, problems, discussions
""" """
location = ['i4x', org, course, 'course', name] get_location_and_verify_access(request, org, course, name)
# check that logged in user has permissions to this item
if not has_access(request.user, location):
raise PermissionDenied()
if section == 'details': if section == 'details':
manager = CourseDetails manager = CourseDetails
...@@ -1293,7 +1283,7 @@ def course_advanced_updates(request, org, course, name): ...@@ -1293,7 +1283,7 @@ def course_advanced_updates(request, org, course, name):
return HttpResponse(json.dumps(CourseMetadata.update_from_json(location, json.loads(request.body))), mimetype="application/json") return HttpResponse(json.dumps(CourseMetadata.update_from_json(location, json.loads(request.body))), mimetype="application/json")
#@ensure_csrf_cookie what is this cookie? @ensure_csrf_cookie
@login_required @login_required
def get_checklists(request, org, course, name): def get_checklists(request, org, course, name):
""" """
...@@ -1313,8 +1303,7 @@ def get_checklists(request, org, course, name): ...@@ -1313,8 +1303,7 @@ def get_checklists(request, org, course, name):
course_module.checklists = template_module.checklists course_module.checklists = template_module.checklists
modulestore.update_metadata(location, own_metadata(course_module)) modulestore.update_metadata(location, own_metadata(course_module))
checklists = course_module.checklists checklists = get_checklists_with_action_urls(course_module)
create_checklist_action_urls(checklists, course_module)
return render_to_response('checklists.html', return render_to_response('checklists.html',
{ {
'context_course': course_module, 'context_course': course_module,
...@@ -1322,6 +1311,7 @@ def get_checklists(request, org, course, name): ...@@ -1322,6 +1311,7 @@ def get_checklists(request, org, course, name):
}) })
@ensure_csrf_cookie
@login_required @login_required
def update_checklist(request, org, course, name, checklist_index=None): def update_checklist(request, org, course, name, checklist_index=None):
""" """
...@@ -1343,24 +1333,31 @@ def update_checklist(request, org, course, name, checklist_index=None): ...@@ -1343,24 +1333,31 @@ def update_checklist(request, org, course, name, checklist_index=None):
modified_checklist = json.loads(request.body) modified_checklist = json.loads(request.body)
course_module.checklists[int(checklist_index)] = modified_checklist course_module.checklists[int(checklist_index)] = modified_checklist
modulestore.update_metadata(location, own_metadata(course_module)) modulestore.update_metadata(location, own_metadata(course_module))
create_checklist_action_urls([modified_checklist], course_module) checklists = get_checklists_with_action_urls(course_module)
return HttpResponse(json.dumps(modified_checklist), mimetype="application/json") return HttpResponse(json.dumps(checklists), mimetype="application/json")
else: else:
return HttpResponseBadRequest("Could not save checklist state because the checklist index was out of range or unspecified.", return HttpResponseBadRequest("Could not save checklist state because the checklist index was out of range or unspecified.",
content_type="text/plain") content_type="text/plain")
elif request.method == 'GET': elif request.method == 'GET':
# In the JavaScript view initialize method, we do a fetch to get all the checklists. # In the JavaScript view initialize method, we do a fetch to get all the checklists.
checklists = course_module.checklists checklists = get_checklists_with_action_urls(course_module)
create_checklist_action_urls(checklists, course_module)
return HttpResponse(json.dumps(checklists), mimetype="application/json") return HttpResponse(json.dumps(checklists), mimetype="application/json")
def create_checklist_action_urls(checklists, course_module): def get_checklists_with_action_urls(course_module):
"""
Gets the checklists out of the course module and expands their action urls.
Returns the checklists with modified urls (different from what is stored in the course moduule).
"""
checklists = course_module.checklists
# Expand action names to their URLs. # Expand action names to their URLs.
for checklist in checklists: for checklist in checklists:
for item in checklist.get('items'): for item in checklist.get('items'):
item['action_url'] = get_url_reverse(item.get('action_url'), course_module) item['action_url'] = get_url_reverse(item.get('action_url'), course_module)
return checklists
@login_required @login_required
@ensure_csrf_cookie @ensure_csrf_cookie
def asset_index(request, org, course, name): def asset_index(request, org, course, name):
...@@ -1597,9 +1594,6 @@ def export_course(request, org, course, name): ...@@ -1597,9 +1594,6 @@ def export_course(request, org, course, name):
location = get_location_and_verify_access(request, org, course, name) location = get_location_and_verify_access(request, org, course, name)
course_module = modulestore().get_item(location) course_module = modulestore().get_item(location)
# check that logged in user has permissions to this item
if not has_access(request.user, location):
raise PermissionDenied()
return render_to_response('export.html', { return render_to_response('export.html', {
'context_course': course_module, 'context_course': course_module,
...@@ -1627,7 +1621,7 @@ def render_500(request): ...@@ -1627,7 +1621,7 @@ def render_500(request):
def get_location_and_verify_access(request, org, course, name): def get_location_and_verify_access(request, org, course, name):
""" """
Create the location tuple verify that the user has permissions Create the location tuple verify that the user has permissions
to view the location. to view the location. Returns the location.
""" """
location = ['i4x', org, course, 'course', name] location = ['i4x', org, course, 'course', name]
...@@ -1641,7 +1635,7 @@ def get_location_and_verify_access(request, org, course, name): ...@@ -1641,7 +1635,7 @@ def get_location_and_verify_access(request, org, course, name):
def get_request_method(request): def get_request_method(request):
""" """
Using HTTP_X_HTTP_METHOD_OVERRIDE, in the request metadata, determine Using HTTP_X_HTTP_METHOD_OVERRIDE, in the request metadata, determine
what type of request came from the client. what type of request came from the client, and return it.
""" """
# NB: we're setting Backbone.emulateHTTP to true on the client so everything comes as a post!!! # NB: we're setting Backbone.emulateHTTP to true on the client so everything comes as a post!!!
if request.method == 'POST' and 'HTTP_X_HTTP_METHOD_OVERRIDE' in request.META: if request.method == 'POST' and 'HTTP_X_HTTP_METHOD_OVERRIDE' in request.META:
......
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