Commit f77b6670 by Eric Fischer

Merge pull request #835 from edx/efischer/staff-upload-fix

Staff can view uploaded files
parents e8525013 53d9ef92
...@@ -36,12 +36,8 @@ ...@@ -36,12 +36,8 @@
{% trans "The learner's response to the question above:" as translated_label %} {% 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 %} {% include "openassessmentblock/oa_submission_answer.html" with answer=submission.answer answer_text_label=translated_label %}
{% if submission.file_url %} {% trans "Associated File" as translated_header %}
<a href="{{ submission.file_url }}" class="submission--file"> {% 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" %}
{% 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 %}
</div> </div>
{% endif %} {% endif %}
</div> </div>
......
...@@ -323,26 +323,16 @@ class StaffAreaMixin(object): ...@@ -323,26 +323,16 @@ class StaffAreaMixin(object):
Returns: Returns:
A context dict for rendering a student submission and associated rubric (for staff grading). 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 = { context = {
'submission': create_submission_dict(submission, self.prompts) if submission else None, 'submission': create_submission_dict(submission, self.prompts) if submission else None,
'rubric_criteria': copy.deepcopy(self.rubric_criteria_with_labels), 'rubric_criteria': copy.deepcopy(self.rubric_criteria_with_labels),
'student_username': student_username, '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: if self.rubric_feedback_prompt is not None:
context["rubric_feedback_prompt"] = self.rubric_feedback_prompt context["rubric_feedback_prompt"] = self.rubric_feedback_prompt
......
...@@ -317,15 +317,19 @@ class TestCourseStaff(XBlockHandlerTestCase): ...@@ -317,15 +317,19 @@ class TestCourseStaff(XBlockHandlerTestCase):
}, ['self']) }, ['self'])
# Mock the file upload API to avoid hitting S3 # 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" 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") __, context = xblock.get_student_info_path_and_context("Bob")
# Check that the right file key was passed to generate the download url # Check that the right file key was passed to generate the download url
file_api.get_download_url.assert_called_with("test_key") file_api.get_download_url.assert_called_with("test_key")
# Check the context passed to the template # 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 # Check the fully rendered template
payload = urllib.urlencode({"student_username": "Bob"}) 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