|
101 | 101 | from lms.djangoapps.instructor.views.serializer import (
|
102 | 102 | AccessSerializer,
|
103 | 103 | BlockDueDateSerializer,
|
| 104 | + CertificateGenerationSerializer, |
104 | 105 | CertificateSerializer,
|
105 | 106 | CertificateStatusesSerializer,
|
106 | 107 | ForumRoleNameSerializer,
|
@@ -3402,22 +3403,35 @@ def _instructor_dash_url(course_key, section=None):
|
3402 | 3403 | return url
|
3403 | 3404 |
|
3404 | 3405 |
|
3405 |
| -@require_course_permission(permissions.ENABLE_CERTIFICATE_GENERATION) |
3406 |
| -@require_POST |
3407 |
| -def enable_certificate_generation(request, course_id=None): |
3408 |
| - """Enable/disable self-generated certificates for a course. |
| 3406 | +class EnableCertificateGenerationAPIView(APIView): |
| 3407 | + """Enable/disable self-generated certificates for a course.""" |
| 3408 | + permission_classes = (IsAuthenticated, permissions.InstructorPermission) |
| 3409 | + permission_name = permissions.ENABLE_CERTIFICATE_GENERATION |
| 3410 | + serializer_class = CertificateGenerationSerializer |
3409 | 3411 |
|
3410 |
| - Once self-generated certificates have been enabled, students |
3411 |
| - who have passed the course will be able to generate certificates. |
| 3412 | + @method_decorator(ensure_csrf_cookie) |
| 3413 | + def post(self, request, course_id=None): |
| 3414 | + """ |
| 3415 | + Once self-generated certificates have been enabled, students |
| 3416 | + who have passed the course will be able to generate certificates. |
3412 | 3417 |
|
3413 |
| - Redirects back to the instructor dashboard once the |
3414 |
| - setting has been updated. |
| 3418 | + Parameters: |
| 3419 | + - `certificates-enabled`: The true/false value based on user action. |
| 3420 | + - `course_id`: The ID of the course for which the extensions are being queried. |
3415 | 3421 |
|
3416 |
| - """ |
3417 |
| - course_key = CourseKey.from_string(course_id) |
3418 |
| - is_enabled = (request.POST.get('certificates-enabled', 'false') == 'true') |
3419 |
| - certs_api.set_cert_generation_enabled(course_key, is_enabled) |
3420 |
| - return redirect(_instructor_dash_url(course_key, section='certificates')) |
| 3422 | + Redirects back to the instructor dashboard once the |
| 3423 | + setting has been updated. |
| 3424 | + """ |
| 3425 | + |
| 3426 | + serializer = self.serializer_class(data=request.data) |
| 3427 | + serializer.is_valid(raise_exception=True) |
| 3428 | + |
| 3429 | + course_key = CourseKey.from_string(course_id) |
| 3430 | + is_enabled = serializer.validated_data["certificates-enabled"] |
| 3431 | + |
| 3432 | + certs_api.set_cert_generation_enabled(course_key, is_enabled) |
| 3433 | + |
| 3434 | + return redirect(_instructor_dash_url(course_key, section='certificates')) |
3421 | 3435 |
|
3422 | 3436 |
|
3423 | 3437 | @method_decorator(cache_control(no_cache=True, no_store=True, must_revalidate=True), name='dispatch')
|
|
0 commit comments