fix: Remove v1 course certificate code, as this was previously globally disabled (#28155)
MICROBA-1227
This commit is contained in:
@@ -24,9 +24,7 @@ from common.djangoapps.student.models import CourseEnrollment
|
||||
from lms.djangoapps.branding import api as branding_api
|
||||
from lms.djangoapps.certificates.generation_handler import (
|
||||
generate_certificate_task as _generate_certificate_task,
|
||||
generate_user_certificates as _generate_user_certificates,
|
||||
is_on_certificate_allowlist as _is_on_certificate_allowlist,
|
||||
regenerate_user_certificates as _regenerate_user_certificates
|
||||
is_on_certificate_allowlist as _is_on_certificate_allowlist
|
||||
)
|
||||
from lms.djangoapps.certificates.data import CertificateStatuses
|
||||
from lms.djangoapps.certificates.models import (
|
||||
@@ -200,14 +198,6 @@ def get_recently_modified_certificates(course_keys=None, start_date=None, end_da
|
||||
return GeneratedCertificate.objects.filter(**cert_filter_args).order_by('modified_date')
|
||||
|
||||
|
||||
def generate_user_certificates(student, course_key, insecure=False, generation_mode='batch', forced_grade=None):
|
||||
return _generate_user_certificates(student, course_key, insecure, generation_mode, forced_grade)
|
||||
|
||||
|
||||
def regenerate_user_certificates(student, course_key, forced_grade=None, template_file=None, insecure=False):
|
||||
return _regenerate_user_certificates(student, course_key, forced_grade, template_file, insecure)
|
||||
|
||||
|
||||
def generate_certificate_task(user, course_key, generation_mode=None):
|
||||
"""
|
||||
Create a task to generate a certificate for this user in this course run, if the user is eligible and a certificate
|
||||
|
||||
@@ -367,58 +367,3 @@ def _is_cert_downloadable(user, course_key):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def generate_user_certificates(student, course_key, insecure=False, generation_mode='batch', forced_grade=None): # pylint: disable=unused-argument
|
||||
"""
|
||||
It will add the add-cert request into the xqueue.
|
||||
|
||||
A new record will be created to track the certificate
|
||||
generation task. If an error occurs while adding the certificate
|
||||
to the queue, the task will have status 'error'. It also emits
|
||||
`edx.certificate.created` event for analytics.
|
||||
|
||||
This method has not yet been updated (it predates the certificates revamp). If modifying this method,
|
||||
see also generate_user_certificates() in generation.py (which is very similar but is called from a celery task).
|
||||
In the future these methods will be unified.
|
||||
|
||||
Args:
|
||||
student (User)
|
||||
course_key (CourseKey)
|
||||
|
||||
Keyword Arguments:
|
||||
insecure - (Boolean)
|
||||
generation_mode - who has requested certificate generation. Its value should `batch`
|
||||
in case of django command and `self` if student initiated the request.
|
||||
forced_grade - a string indicating to replace grade parameter. if present grading
|
||||
will be skipped.
|
||||
"""
|
||||
# Note that this will launch an asynchronous task, and so cannot return the certificate status. This is a
|
||||
# change from the older certificate code that tries to immediately create a cert.
|
||||
log.info(f'{course_key} is using V2 certificates. Attempt will be made to regenerate a V2 certificate for user '
|
||||
f'{student.id}.')
|
||||
return generate_certificate_task(student, course_key)
|
||||
|
||||
|
||||
def regenerate_user_certificates(student, course_key, forced_grade=None, template_file=None, insecure=False): # pylint: disable=unused-argument
|
||||
"""
|
||||
Add the regen-cert request into the xqueue.
|
||||
|
||||
A new record will be created to track the certificate
|
||||
generation task. If an error occurs while adding the certificate
|
||||
to the queue, the task will have status 'error'.
|
||||
|
||||
This method has not yet been updated (it predates the certificates revamp).
|
||||
|
||||
Args:
|
||||
student (User)
|
||||
course_key (CourseKey)
|
||||
|
||||
Keyword Arguments:
|
||||
grade_value - The grade string, such as "Distinction"
|
||||
template_file - The template file used to render this certificate
|
||||
insecure - (Boolean)
|
||||
"""
|
||||
log.info(f"{course_key} is using V2 certificates. Attempt will be made to regenerate a V2 certificate for "
|
||||
f"user {student.id}.")
|
||||
return generate_certificate_task(student, course_key)
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
import uuid
|
||||
from contextlib import contextmanager
|
||||
from datetime import datetime, timedelta
|
||||
from unittest import mock
|
||||
from unittest.mock import patch
|
||||
|
||||
import ddt
|
||||
@@ -39,7 +38,6 @@ from lms.djangoapps.certificates.api import (
|
||||
create_or_update_certificate_allowlist_entry,
|
||||
example_certificates_status,
|
||||
generate_example_certificates,
|
||||
generate_user_certificates,
|
||||
get_allowlist_entry,
|
||||
get_allowlisted_users,
|
||||
get_certificate_footer_context,
|
||||
@@ -68,7 +66,6 @@ from lms.djangoapps.certificates.tests.factories import (
|
||||
GeneratedCertificateFactory,
|
||||
CertificateInvalidationFactory
|
||||
)
|
||||
from lms.djangoapps.grades.tests.utils import mock_passing_grade
|
||||
from openedx.core.djangoapps.content.course_overviews.tests.factories import CourseOverviewFactory
|
||||
from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration
|
||||
|
||||
@@ -564,19 +561,6 @@ class GenerateUserCertificatesTest(EventTestMixin, WebCertificateTestMixin, Modu
|
||||
self.enrollment = CourseEnrollment.enroll(self.student, self.course.id, mode='honor')
|
||||
self.request_factory = RequestFactory()
|
||||
|
||||
@mock.patch(CAN_GENERATE_METHOD, mock.Mock(return_value=True))
|
||||
@patch.dict(settings.FEATURES, {'CERTIFICATES_HTML_VIEW': True})
|
||||
def test_new_cert_request_for_html_certificate(self):
|
||||
"""
|
||||
Test generate_user_certificates with HTML certificates
|
||||
"""
|
||||
self._setup_course_certificate()
|
||||
with mock_passing_grade():
|
||||
generate_user_certificates(self.student, self.course.id)
|
||||
|
||||
cert = GeneratedCertificate.eligible_certificates.get(user=self.student, course_id=self.course.id)
|
||||
assert cert.status == CertificateStatuses.downloadable
|
||||
|
||||
@patch.dict(settings.FEATURES, {'CERTIFICATES_HTML_VIEW': False})
|
||||
def test_cert_url_empty_with_invalid_certificate(self):
|
||||
"""
|
||||
|
||||
@@ -21,7 +21,7 @@ from opaque_keys.edx.keys import CourseKey
|
||||
|
||||
from common.djangoapps.student.models import CourseEnrollment, User
|
||||
from common.djangoapps.util.json_request import JsonResponse
|
||||
from lms.djangoapps.certificates.api import get_certificates_for_user, regenerate_user_certificates
|
||||
from lms.djangoapps.certificates.api import generate_certificate_task, get_certificates_for_user
|
||||
from lms.djangoapps.certificates.permissions import GENERATE_ALL_CERTIFICATES, VIEW_ALL_CERTIFICATES
|
||||
from lms.djangoapps.instructor_task.api import generate_certificates_for_students
|
||||
from openedx.core.djangoapps.content.course_overviews.api import get_course_overview
|
||||
@@ -203,7 +203,7 @@ def regenerate_certificate_for_user(request):
|
||||
|
||||
# Attempt to regenerate certificates
|
||||
try:
|
||||
regenerate_user_certificates(user, course_key)
|
||||
generate_certificate_task(user, course_key)
|
||||
except: # pylint: disable=bare-except
|
||||
# We are pessimistic about the kinds of errors that might get thrown by the
|
||||
# certificates API. This may be overkill, but we're logging everything so we can
|
||||
|
||||
Reference in New Issue
Block a user