Commit 955dc947 by David Ormsbee

Merge pull request #554 from MITx/feature/victor/fix-staff-profile-view

Set request.user = student when impersonating a student
parents d042578a 7a6fa1dd
...@@ -143,8 +143,9 @@ def get_module(user, request, location, student_module_cache, course_id, positio ...@@ -143,8 +143,9 @@ def get_module(user, request, location, student_module_cache, course_id, positio
exists. exists.
Arguments: Arguments:
- user : current django User - user : User for whom we're getting the module
- request : current django HTTPrequest - request : current django HTTPrequest -- used in particular for auth
(This is important e.g. for prof impersonation of students in progress view)
- location : A Location-like object identifying the module to load - location : A Location-like object identifying the module to load
- student_module_cache : a StudentModuleCache - student_module_cache : a StudentModuleCache
- course_id : the course_id in the context of which to load module - course_id : the course_id in the context of which to load module
...@@ -170,7 +171,9 @@ def _get_module(user, request, location, student_module_cache, course_id, positi ...@@ -170,7 +171,9 @@ def _get_module(user, request, location, student_module_cache, course_id, positi
descriptor = modulestore().get_instance(course_id, location) descriptor = modulestore().get_instance(course_id, location)
# Short circuit--if the user shouldn't have access, bail without doing any work # Short circuit--if the user shouldn't have access, bail without doing any work
if not has_access(user, descriptor, 'load'): # NOTE: Do access check on request.user -- that's who actually needs access (e.g. could be prof
# impersonating a user)
if not has_access(request.user, descriptor, 'load'):
return None return None
#TODO Only check the cache if this module can possibly have state #TODO Only check the cache if this module can possibly have state
......
...@@ -325,14 +325,17 @@ def progress(request, course_id, student_id=None): ...@@ -325,14 +325,17 @@ def progress(request, course_id, student_id=None):
raise Http404 raise Http404
student = User.objects.get(id=int(student_id)) student = User.objects.get(id=int(student_id))
# NOTE: To make sure impersonation by instructor works, use
# student instead of request.user in the rest of the function.
student_module_cache = StudentModuleCache.cache_for_descriptor_descendents( student_module_cache = StudentModuleCache.cache_for_descriptor_descendents(
course_id, request.user, course) course_id, student, course)
course_module = get_module(request.user, request, course.location, course_module = get_module(student, request, course.location,
student_module_cache, course_id) student_module_cache, course_id)
courseware_summary = grades.progress_summary(student, course_module, courseware_summary = grades.progress_summary(student, course_module,
course.grader, student_module_cache) course.grader, student_module_cache)
grade_summary = grades.grade(request.user, request, course, student_module_cache) grade_summary = grades.grade(student, request, course, student_module_cache)
context = {'course': course, context = {'course': course,
'courseware_summary': courseware_summary, 'courseware_summary': courseware_summary,
......
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