Example #1
0
def can_generate_allowlist_certificate(user, course_key):
    """
    Check if an allowlist certificate can be generated (created if it doesn't already exist, or updated if it does
    exist) for this user, in this course run.
    """
    if not is_using_certificate_allowlist(course_key):
        # This course run is not using the allowlist feature
        log.info(
            '{course} is not using the certificate allowlist. Certificate cannot be generated.'.format(
                course=course_key
            ))
        return False

    if not auto_certificate_generation_enabled():
        # Automatic certificate generation is globally disabled
        log.info('Automatic certificate generation is globally disabled. Certificate cannot be generated.')
        return False

    if CertificateInvalidation.has_certificate_invalidation(user, course_key):
        # The invalidation list overrides the allowlist
        log.info(
            '{user} : {course} is on the certificate invalidation list. Certificate cannot be generated.'.format(
                user=user.id,
                course=course_key
            ))
        return False

    enrollment_mode, __ = CourseEnrollment.enrollment_mode_for_user(user, course_key)
    if enrollment_mode is None:
        log.info('{user} : {course} does not have an enrollment. Certificate cannot be generated.'.format(
            user=user.id,
            course=course_key
        ))
        return False

    if not IDVerificationService.user_has_ever_been_verified(user):
        log.info(f'{user.id} has not ever had a verified id. Certificate cannot be generated.')
        return False

    if not _is_on_certificate_allowlist(user, course_key):
        log.info('{user} : {course} is not on the certificate allowlist. Certificate cannot be generated.'.format(
            user=user.id,
            course=course_key
        ))
        return False

    log.info('{user} : {course} is on the certificate allowlist'.format(
        user=user.id,
        course=course_key
    ))
    cert = GeneratedCertificate.certificate_for_student(user, course_key)
    return _can_generate_allowlist_certificate_for_status(cert)
Example #2
0
    def test_user_has_ever_been_verified(self):
        """
        Test to make sure we correctly answer whether a user has ever been verified.
        """
        # Missing user
        assert not IDVerificationService.user_has_ever_been_verified(None)

        # User without any attempts
        photo_user = UserFactory.create()
        assert not IDVerificationService.user_has_ever_been_verified(
            photo_user)

        # User without an approved attempt
        attempt = SoftwareSecurePhotoVerification(user=photo_user,
                                                  status='submitted')
        attempt.save()
        assert not IDVerificationService.user_has_ever_been_verified(
            photo_user)

        # User with a submitted, then an approved attempt
        attempt = SoftwareSecurePhotoVerification(user=photo_user,
                                                  status='approved')
        attempt.save()
        assert IDVerificationService.user_has_ever_been_verified(photo_user)

        # User with a manual approved attempt
        manual_user = UserFactory.create()
        attempt = ManualVerification(user=manual_user, status='approved')
        attempt.save()
        assert IDVerificationService.user_has_ever_been_verified(manual_user)

        # User with 2 manual approved attempts
        attempt = ManualVerification(user=manual_user, status='approved')
        attempt.save()
        assert IDVerificationService.user_has_ever_been_verified(manual_user)

        # User with an SSO approved attempt, then a must_retry attempt
        sso_user = UserFactory.create()
        attempt = SSOVerification(user=sso_user, status='approved')
        attempt.save()
        attempt = SSOVerification(user=sso_user, status='must_retry')
        attempt.save()
        assert IDVerificationService.user_has_ever_been_verified(sso_user)