diff --git a/lms/djangoapps/verify_student/management/commands/manual_verifications.py b/lms/djangoapps/verify_student/management/commands/manual_verifications.py index 5cc3a78ea76e35e73f3c9f3a89b6424ee80c8ba8..603d654a24de19253c8f4c2ff16c59c4a85c1cc0 100644 --- a/lms/djangoapps/verify_student/management/commands/manual_verifications.py +++ b/lms/djangoapps/verify_student/management/commands/manual_verifications.py @@ -32,11 +32,24 @@ class Command(BaseCommand): default=None, help='Path of the file to read email id from.', type=str, - required=True + ) + parser.add_argument( + '--email', + default=None, + help='Single email to verify one user', + type=str, ) def handle(self, *args, **options): + single_email = options['email'] + + if single_email: + successfully_verified = self._add_user_to_manual_verification(single_email) + if successfully_verified is False: + log.error(f'Manual verification of {single_email} failed') + return + email_ids_file = options['email_ids_file'] if email_ids_file: @@ -72,17 +85,31 @@ class Command(BaseCommand): total_emails = len(email_ids) log.info(f'Creating manual verification for {total_emails} emails.') for email_id in email_ids: - try: - email_id = email_id.strip() - user = User.objects.get(email=email_id) - ManualVerification.objects.get_or_create( - user=user, - status='approved', - created_at__gte=earliest_allowed_verification_date(), - defaults={'name': user.profile.name}, - ) - except User.DoesNotExist: + successfully_verified = self._add_user_to_manual_verification(email_id) + if successfully_verified is False: failed_emails.append(email_id) - err_msg = 'Tried to verify email {}, but user not found' - log.error(err_msg.format(email_id)) return total_emails, failed_emails + + def _add_user_to_manual_verification(self, email_id): + """ + Generates a single verification for a user. + + Arguments: + email_id (str): email of the user to be verified + + Returns: + (success): boolean to show if the user has been successfully verified. + """ + try: + email_id = email_id.strip() + user = User.objects.get(email=email_id) + ManualVerification.objects.get_or_create( + user=user, + status='approved', + created_at__gte=earliest_allowed_verification_date(), + defaults={'name': user.profile.name}, + ) + return True + except User.DoesNotExist: + log.error(f'Tried to verify email {email_id}, but user not found') + return False