refactor!: Remove the request_certificate REST endpoint (#28346)
[MICROBA-1412] [DEPR-155] Remove the request_certificate REST endpoint from the LMS (certificates Django app)
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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 *
|
||||
|
||||
@@ -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
|
||||
@@ -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'),
|
||||
|
||||
Reference in New Issue
Block a user