From b7085c2cf9ec10abe29719cbfcf57f0bf91c5230 Mon Sep 17 00:00:00 2001 From: Justin Hynes Date: Wed, 18 Aug 2021 10:43:47 -0400 Subject: [PATCH] refactor!: Remove the `request_certificate` REST endpoint (#28346) [MICROBA-1412] [DEPR-155] Remove the request_certificate REST endpoint from the LMS (certificates Django app) --- .../certificates/tests/test_webview_views.py | 11 ----- lms/djangoapps/certificates/views/__init__.py | 1 - lms/djangoapps/certificates/views/xqueue.py | 44 ------------------- lms/urls.py | 4 -- 4 files changed, 60 deletions(-) delete mode 100644 lms/djangoapps/certificates/views/xqueue.py diff --git a/lms/djangoapps/certificates/tests/test_webview_views.py b/lms/djangoapps/certificates/tests/test_webview_views.py index 440b0c142f..bbf731194c 100644 --- a/lms/djangoapps/certificates/tests/test_webview_views.py +++ b/lms/djangoapps/certificates/tests/test_webview_views.py @@ -2,7 +2,6 @@ import datetime -import json from unittest.mock import patch from urllib.parse import urlencode from uuid import uuid4 @@ -1027,16 +1026,6 @@ class CertificatesViewsTests(CommonCertificatesTestCase, CacheIsolationTestCase) response = self.client.get(test_url) self.assertContains(response, "Invalid Certificate") - @override_settings(FEATURES=FEATURES_WITH_CERTS_DISABLED) - def test_request_certificate_without_html_certs(self): - self.cert.status = CertificateStatuses.unavailable - self.cert.save() - request_certificate_url = reverse('request_certificate') - response = self.client.post(request_certificate_url, {'course_id': str(self.course.id)}) - assert response.status_code == 200 - response_json = json.loads(response.content.decode('utf-8')) - assert CertificateStatuses.unavailable == response_json['add_status'] - # TEMPLATES WITHOUT LANGUAGE TESTS @override_settings(FEATURES=FEATURES_WITH_CUSTOM_CERTS_ENABLED) @override_settings(LANGUAGE_CODE='fr') diff --git a/lms/djangoapps/certificates/views/__init__.py b/lms/djangoapps/certificates/views/__init__.py index 15c02d9b1a..e3b9210927 100644 --- a/lms/djangoapps/certificates/views/__init__.py +++ b/lms/djangoapps/certificates/views/__init__.py @@ -3,4 +3,3 @@ Aggregate all views exposed by the certificates app. """ from lms.djangoapps.certificates.views.support import * from lms.djangoapps.certificates.views.webview import * -from lms.djangoapps.certificates.views.xqueue import * diff --git a/lms/djangoapps/certificates/views/xqueue.py b/lms/djangoapps/certificates/views/xqueue.py deleted file mode 100644 index ec66cf1658..0000000000 --- a/lms/djangoapps/certificates/views/xqueue.py +++ /dev/null @@ -1,44 +0,0 @@ -""" -Views used by XQueue certificate generation. -""" - - -import json -import logging - -from django.contrib.auth import get_user_model -from django.db import transaction -from django.http import HttpResponse -from django.views.decorators.csrf import csrf_exempt -from opaque_keys.edx.keys import CourseKey - -from lms.djangoapps.certificates.api import generate_certificate_task -from lms.djangoapps.certificates.utils import certificate_status_for_student - -log = logging.getLogger(__name__) -User = get_user_model() - - -# Grades can potentially be written - if so, let grading manage the transaction. -@transaction.non_atomic_requests -@csrf_exempt -def request_certificate(request): - """Request the on-demand creation of a certificate for some user, course. - - A request doesn't imply a guarantee that such a creation will take place. - We intentionally use the same machinery as is used for doing certification - at the end of a course run, so that we can be sure users get graded and - then if and only if they pass, do they get a certificate issued. - """ - if request.method == "POST": - if request.user.is_authenticated: - username = request.user.username - student = User.objects.get(username=username) - course_key = CourseKey.from_string(request.POST.get('course_id')) - status = certificate_status_for_student(student, course_key)['status'] - - log.info(f'{course_key} is using V2 course certificates. Attempt will be made to generate a V2 certificate ' - f'for user {student.id}.') - generate_certificate_task(student, course_key) - return HttpResponse(json.dumps({'add_status': status}), content_type='application/json') # pylint: disable=http-response-with-content-type-json, http-response-with-json-dumps - return HttpResponse(json.dumps({'add_status': 'ERRORANONYMOUSUSER'}), content_type='application/json') # pylint: disable=http-response-with-content-type-json, http-response-with-json-dumps diff --git a/lms/urls.py b/lms/urls.py index 243b1be33a..c7e03d45a3 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -16,7 +16,6 @@ from ratelimitbackend import admin from lms.djangoapps.branding import views as branding_views from lms.djangoapps.debug import views as debug_views -from lms.djangoapps.certificates import views as certificates_views from lms.djangoapps.courseware.masquerade import MasqueradeView from lms.djangoapps.courseware.module_render import ( handle_xblock_callback, @@ -889,9 +888,6 @@ if settings.FEATURES.get('ENABLE_OAUTH2_PROVIDER'): urlpatterns += [ url(r'^certificates/', include('lms.djangoapps.certificates.urls')), - url(r'^request_certificate$', certificates_views.request_certificate, - name='request_certificate'), - # REST APIs url(r'^api/certificates/', include(('lms.djangoapps.certificates.apis.urls', 'lms.djangoapps.certificates'),