Beispiel #1
0
    def invalidate(self):
        """
        Invalidate Generated Certificate by  marking it 'unavailable'.

        Following is the list of fields with their defaults
            1 - verify_uuid = '',
            2 - download_uuid = '',
            3 - download_url = '',
            4 - grade = ''
            5 - status = 'unavailable'
        """
        log.info(
            'Marking certificate as unavailable for {user} : {course}'.format(
                user=self.user.id, course=self.course_id))

        self.verify_uuid = ''
        self.download_uuid = ''
        self.download_url = ''
        self.grade = ''
        self.status = CertificateStatuses.unavailable
        self.save()
        COURSE_CERT_REVOKED.send_robust(
            sender=self.__class__,
            user=self.user,
            course_key=self.course_id,
            mode=self.mode,
            status=self.status,
        )
Beispiel #2
0
    def invalidate(self):
        """
        Invalidate Generated Certificate by marking it 'unavailable'. This will prevent the learner from being able to
        access their certiticate in the associated Course. In addition, we remove any errors and grade information
        associated with the certificate record.

        We remove the `download_uuid` and the `download_url` as well, but this is only important to PDF certificates.

        Invalidating a certificate fires the `COURSE_CERT_REVOKED` signal. This kicks off a task to determine if there
        are any program certificates that need to be revoked from the learner.
        """
        log.info(
            f'Marking certificate as unavailable for {self.user.id} : {self.course_id}'
        )

        self.error_reason = ''
        self.download_uuid = ''
        self.download_url = ''
        self.grade = ''
        self.status = CertificateStatuses.unavailable
        self.save()

        COURSE_CERT_REVOKED.send_robust(
            sender=self.__class__,
            user=self.user,
            course_key=self.course_id,
            mode=self.mode,
            status=self.status,
        )
Beispiel #3
0
    def test_signal_received(self, mock_is_learner_issuance_enabled, mock_task):  # pylint: disable=unused-argument
        """
        Ensures the receiver function is invoked when COURSE_CERT_REVOKED is
        sent.

        Suboptimal: because we cannot mock the receiver function itself (due
        to the way django signals work), we mock a configuration call that is
        known to take place inside the function.
        """
        COURSE_CERT_REVOKED.send(**self.signal_kwargs)
        self.assertEqual(mock_is_learner_issuance_enabled.call_count, 1)
Beispiel #4
0
    def _revoke_certificate(self, status, grade=None, source=None):
        """
        Revokes a course certificate from a learner, updating the certificate's status as specified by the value of the
        `status` argument. This will prevent the learner from being able to access their certificate in the associated
        course run.

        We remove the `download_uuid` and the `download_url` as well, but this is only important to PDF certificates.

        Invalidating a certificate fires the `COURSE_CERT_REVOKED` signal. This kicks off a task to determine if there
        are any program certificates that also need to be revoked from the learner.

        If the certificate had a status of `downloadable` before being revoked then we will also emit an
        `edx.certificate.revoked` event for tracking purposes.

        Args:
            status (CertificateStatus) - certificate status to set for the `GeneratedCertificate` record
            grade (float) - snapshot of the learner's current grade as a decimal
            source (String) - source requesting invalidation of the certificate for tracking purposes
        """
        previous_certificate_status = self.status

        self.error_reason = ''
        self.download_uuid = ''
        self.download_url = ''
        self.grade = grade or ''
        self.status = status
        self.save()

        COURSE_CERT_REVOKED.send_robust(
            sender=self.__class__,
            user=self.user,
            course_key=self.course_id,
            mode=self.mode,
            status=self.status,
        )

        if previous_certificate_status == CertificateStatuses.downloadable:
            # imported here to avoid a circular import issue
            from lms.djangoapps.certificates.utils import emit_certificate_event

            event_data = {
                'user_id': self.user.id,
                'course_id': str(self.course_id),
                'certificate_id': self.verify_uuid,
                'enrollment_mode': self.mode,
                'source': source or '',
            }
            emit_certificate_event('revoked', self.user, str(self.course_id), event_data=event_data)
Beispiel #5
0
    def mark_notpassing(self, grade):
        """
        Invalidates a Generated Certificate by marking it as not passing
        """
        log.info(
            'Marking certificate as notpassing for {user} : {course}'.format(
                user=self.user.id, course=self.course_id))

        self.verify_uuid = ''
        self.download_uuid = ''
        self.download_url = ''
        self.grade = grade
        self.status = CertificateStatuses.notpassing
        self.save()
        COURSE_CERT_REVOKED.send_robust(
            sender=self.__class__,
            user=self.user,
            course_key=self.course_id,
            mode=self.mode,
            status=self.status,
        )
Beispiel #6
0
    def invalidate(self):
        """
        Invalidate Generated Certificate by  marking it 'unavailable'.
        """
        log.info(f'Marking certificate as unavailable for {self.user.id} : {self.course_id}')

        self.error_reason = ''
        self.verify_uuid = ''
        self.download_uuid = ''
        self.download_url = ''
        self.grade = ''
        self.status = CertificateStatuses.unavailable
        self.save()

        COURSE_CERT_REVOKED.send_robust(
            sender=self.__class__,
            user=self.user,
            course_key=self.course_id,
            mode=self.mode,
            status=self.status,
        )
Beispiel #7
0
    def mark_unverified(self):
        """
        Invalidates a Generated Certificate by marking it as 'unverified'. For additional information, please see the
        comments of the `invalidate` function above as they also apply here.
        """
        log.info(
            f'Marking certificate as unverified for {self.user.id} : {self.course_id}'
        )

        self.error_reason = ''
        self.download_uuid = ''
        self.download_url = ''
        self.grade = ''
        self.status = CertificateStatuses.unverified
        self.save()

        COURSE_CERT_REVOKED.send_robust(
            sender=self.__class__,
            user=self.user,
            course_key=self.course_id,
            mode=self.mode,
            status=self.status,
        )