Commit 53d9ef92 by Eric Fischer

Staff can view uploaded files

Emulating the approach used by peer_mixin to allow staff to actually
see uploaded files. Also updates oa_student_info to make use of
oa_uploaded_file.html instead of duplicating that logic. Test
updates also included.
parent e8525013
......@@ -36,12 +36,8 @@
{% trans "The learner's response to the question above:" as translated_label %}
{% include "openassessmentblock/oa_submission_answer.html" with answer=submission.answer answer_text_label=translated_label %}
{% if submission.file_url %}
<a href="{{ submission.file_url }}" class="submission--file">
{% trans "The file associated with this response." %}
</a>
<span>{% trans "Caution: This file was uploaded by another course learner and has not been verified, screened, approved, reviewed, or endorsed by edX. If you decide to access it, you do so at your own risk." %}</span>
{% endif %}
{% trans "Associated File" as translated_header %}
{% include "openassessmentblock/oa_uploaded_file.html" with file_upload_type=file_upload_type file_url=staff_file_url header=translated_header class_prefix="staff-assessment" show_warning="true" %}
</div>
{% endif %}
</div>
......
......@@ -323,26 +323,16 @@ class StaffAreaMixin(object):
Returns:
A context dict for rendering a student submission and associated rubric (for staff grading).
"""
if submission and 'file_key' in submission.get('answer', {}):
file_key = submission['answer']['file_key']
try:
submission['file_url'] = file_api.get_download_url(file_key)
except file_exceptions.FileUploadError:
# Log the error, but do not prevent the rest of the student info
# from being displayed.
msg = (
u"Could not retrieve image URL for staff debug page. "
u"The learner username is '{student_username}', and the file key is {file_key}"
).format(student_username=student_username, file_key=file_key)
logger.exception(msg)
context = {
'submission': create_submission_dict(submission, self.prompts) if submission else None,
'rubric_criteria': copy.deepcopy(self.rubric_criteria_with_labels),
'student_username': student_username,
}
if submission:
context["file_upload_type"] = self.file_upload_type
context["staff_file_url"] = self.get_download_url_from_submission(submission)
if self.rubric_feedback_prompt is not None:
context["rubric_feedback_prompt"] = self.rubric_feedback_prompt
......
......@@ -317,15 +317,19 @@ class TestCourseStaff(XBlockHandlerTestCase):
}, ['self'])
# Mock the file upload API to avoid hitting S3
with patch("openassessment.xblock.staff_area_mixin.file_api") as file_api:
with patch("openassessment.xblock.submission_mixin.file_upload_api") as file_api:
file_api.get_download_url.return_value = "http://www.example.com/image.jpeg"
# also fake a file_upload_type so our patched url gets rendered
xblock.file_upload_type_raw = 'image'
__, context = xblock.get_student_info_path_and_context("Bob")
# Check that the right file key was passed to generate the download url
file_api.get_download_url.assert_called_with("test_key")
# Check the context passed to the template
self.assertEquals('http://www.example.com/image.jpeg', context['submission']['file_url'])
self.assertEquals('http://www.example.com/image.jpeg', context['staff_file_url'])
self.assertEquals('image', context['file_upload_type'])
# Check the fully rendered template
payload = urllib.urlencode({"student_username": "Bob"})
......
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