From 7f4bd900d1e647fe017ce4c01e279dd41a71a349 Mon Sep 17 00:00:00 2001 From: Peter Fogg Date: Mon, 5 Oct 2015 16:02:56 -0400 Subject: [PATCH] Add management command to set SoftwareSecure verification status. --- .../commands/set_software_secure_status.py | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 lms/djangoapps/verify_student/management/commands/set_software_secure_status.py diff --git a/lms/djangoapps/verify_student/management/commands/set_software_secure_status.py b/lms/djangoapps/verify_student/management/commands/set_software_secure_status.py new file mode 100644 index 0000000000..9437b9da40 --- /dev/null +++ b/lms/djangoapps/verify_student/management/commands/set_software_secure_status.py @@ -0,0 +1,60 @@ +""" +Manually set Software Secure verification status. +""" + +import sys + +from django.core.management.base import BaseCommand +from verify_student.models import ( + SoftwareSecurePhotoVerification, VerificationCheckpoint, VerificationStatus +) + + +class Command(BaseCommand): + """ + Command to trigger the actions that would normally follow Software Secure + returning with the results of a photo verification. + """ + + args = "<{approved, denied}, SoftwareSecurePhotoVerification id, [reason_for_denial]>" + + def handle(self, *args, **kwargs): # pylint: disable=unused-argument + from verify_student.views import _set_user_requirement_status + + status_to_set = args[0] + receipt_id = args[1] + + try: + attempt = SoftwareSecurePhotoVerification.objects.get(receipt_id=receipt_id) + except SoftwareSecurePhotoVerification.DoesNotExist: + self.stderr.write( + 'SoftwareSecurePhotoVerification with id {id} could not be found.\n'.format(id=receipt_id) + ) + sys.exit(1) + + if status_to_set == 'approved': + self.stdout.write('Approving verification for {id}.\n'.format(id=receipt_id)) + attempt.approve() + _set_user_requirement_status(attempt, 'reverification', 'satisfied') + + elif status_to_set == 'denied': + self.stdout.write('Denying verification for {id}.\n'.format(id=receipt_id)) + if len(args) >= 3: + reason_for_denial = args[2] + else: + reason_for_denial = 'Denied via management command.' + attempt.deny(reason_for_denial) + _set_user_requirement_status(attempt, 'reverification', 'failed', reason_for_denial) + + else: + self.stdout.write('Cannot set id {id} to unrecognized status {status}'.format( + id=receipt_id, status=status_to_set + )) + sys.exit(1) + + checkpoints = VerificationCheckpoint.objects.filter(photo_verification=attempt).all() + VerificationStatus.add_status_from_checkpoints( + checkpoints=checkpoints, + user=attempt.user, + status=status_to_set + )