Skip to content

Commit

Permalink
Merge pull request #511 from edx/matthugs/add-reviewed_by
Browse files Browse the repository at this point in the history
Add reviewed_by field to API
  • Loading branch information
davestgermain authored Jan 14, 2019
2 parents f8f0ab4 + 27d0e85 commit 8211f87
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 12 deletions.
5 changes: 3 additions & 2 deletions docs/backends.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,11 @@ The following fields are optional::

{
"start": 123,
"stop": 144
"stop": 144,
"reviewed_by": "[email protected]"
}

(Start and stop are seconds relative to the start of the recorded proctoring session.)
Start and stop are seconds relative to the start of the recorded proctoring session. ``reviewed_by`` must be included whenever a specific edX user (e.g. a member of a course team) initiated the review.


Instructor Dashboard
Expand Down
2 changes: 1 addition & 1 deletion edx_proctoring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
from __future__ import absolute_import

# Be sure to update the version number in edx_proctoring/package.json
__version__ = '1.5.4'
__version__ = '1.5.5'

default_app_config = 'edx_proctoring.apps.EdxProctoringConfig' # pylint: disable=invalid-name
7 changes: 7 additions & 0 deletions edx_proctoring/backends/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from webpack_loader.utils import get_files
from webpack_loader.exceptions import BaseWebpackLoaderException, WebpackBundleLookupError

from django.contrib.auth.models import User

from edx_proctoring.backends.backend import ProctoringBackendProvider
from edx_proctoring.exceptions import BackendProviderCannotRegisterAttempt
from edx_proctoring.statuses import ProctoredExamStudentAttemptStatus, SoftwareSecureReviewStatus
Expand Down Expand Up @@ -199,6 +201,11 @@ def on_review_callback(self, attempt, payload):
Called when the reviewing 3rd party service posts back the results
"""
# REST backends should convert the payload into the expected data structure
if payload.get('reviewed_by', False):
try:
payload['reviewed_by'] = User.objects.get(email=payload['reviewed_by'])
except User.DoesNotExist:
payload['reviewed_by'] = None
return payload

def on_exam_saved(self, exam):
Expand Down
3 changes: 2 additions & 1 deletion edx_proctoring/backends/software_secure.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ def on_review_callback(self, attempt, payload):
converted = {
'status': review_status,
'comments': comments,
'payload': payload
'payload': payload,
'reviewed_by': None,
}
return converted

Expand Down
44 changes: 41 additions & 3 deletions edx_proctoring/backends/tests/test_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from django.test import TestCase
from django.utils import translation
from django.contrib.auth.models import User

from edx_proctoring.backends.rest import BaseRestProctoringProvider
from edx_proctoring.exceptions import BackendProviderCannotRegisterAttempt
Expand Down Expand Up @@ -218,9 +219,10 @@ def test_stop_exam_attempt(self):
status = self.provider.stop_exam_attempt(self.backend_exam['external_id'], attempt_id)
self.assertEqual(status, 'stop')

@responses.activate
def test_on_review_callback(self):
# on_review_callback should just return the payload
"""
on_review_callback should just return the payload when called without review author
"""
attempt = {
'id': 1,
'external_id': 'abcd',
Expand All @@ -229,12 +231,48 @@ def test_on_review_callback(self):
payload = {
'status': 'verified',
'comments': [
{'comment': 'something happend', 'status': 'ok'}
{'comment': 'something happened', 'status': 'ok'}
]
}
new_payload = self.provider.on_review_callback(attempt, payload)
self.assertEqual(payload, new_payload)

def test_on_review_callback_with_reviewer(self):
"""
on_review_callback should find a user if an email is provided
"""
person = User(
username='tester',
email='[email protected]'
)
person.save()
attempt = {
'id': 1,
'external_id': 'abcd',
'user': 1
}

def payload_with_email(email):
"""
generic payload with variable email
"""
return {
'status': 'verified',
'comments': [
{'comment': 'something happened', 'status': 'ok'},
],
'reviewed_by': email,
}

payload = payload_with_email('[email protected]')
new_payload = self.provider.on_review_callback(attempt, payload)
self.assertEqual(new_payload['reviewed_by'], person)

payload = payload_with_email('[email protected]')
new_payload = self.provider.on_review_callback(attempt, payload)

self.assertEqual(new_payload['reviewed_by'], None)

def test_get_javascript(self):
self.assertEqual(self.provider.get_javascript(), '')

Expand Down
6 changes: 2 additions & 4 deletions edx_proctoring/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,12 +840,10 @@ def make_review(self, attempt, data, backend=None):
review.review_status = SoftwareSecureReviewStatus.from_standard_status.get(backend_review['status'])

review.attempt_code = attempt_code
review.raw_data = json.dumps(backend_review)
review.raw_data = json.dumps(data)
review.student_id = attempt['user']['id']
review.exam_id = attempt['proctored_exam']['id']
# set reviewed_by to None because it was reviewed by our 3rd party
# service provider, not a user in our database
review.reviewed_by = None
review.reviewed_by = backend_review.get('reviewed_by', None)

review.save()

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@edx/edx-proctoring",
"//": "Be sure to update the version number in edx_proctoring/__init__.py",
"//": "Note that the version format is slightly different than that of the Python version when using prereleases.",
"version": "1.5.4",
"version": "1.5.5",
"main": "edx_proctoring/static/index.js",
"repository": {
"type": "git",
Expand Down

0 comments on commit 8211f87

Please sign in to comment.