Merge pull request #36794 from dwong2708/dw/certificates-enabled-fix
fix: certificates_enabled flag now correctly returns its boolean value
This commit is contained in:
@@ -103,7 +103,7 @@ class CourseValidationViewTest(SharedModuleStoreTestCase, APITestCase):
|
||||
'has_update': True,
|
||||
},
|
||||
'certificates': {
|
||||
'is_enabled': True,
|
||||
'is_enabled': False,
|
||||
'is_activated': False,
|
||||
'has_certificate': False,
|
||||
},
|
||||
|
||||
@@ -217,7 +217,7 @@ class CourseValidationView(DeveloperErrorViewMixin, GenericAPIView):
|
||||
|
||||
def _certificates_validation(self, course):
|
||||
is_activated, certificates = CertificateManager.is_activated(course)
|
||||
certificates_enabled = certificates is not None
|
||||
certificates_enabled = CertificateManager.is_enabled(course)
|
||||
return dict(
|
||||
is_activated=is_activated,
|
||||
has_certificate=certificates_enabled and len(certificates) > 0,
|
||||
|
||||
@@ -2124,11 +2124,7 @@ def get_certificates_context(course, user):
|
||||
handler_name='certificate_activation_handler',
|
||||
course_key=course_key
|
||||
)
|
||||
course_modes = [
|
||||
mode.slug for mode in CourseMode.modes_for_course(
|
||||
course_id=course_key, include_expired=True
|
||||
) if mode.slug != 'audit'
|
||||
]
|
||||
course_modes = CertificateManager.get_course_modes(course)
|
||||
|
||||
has_certificate_modes = len(course_modes) > 0
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ from django.shortcuts import redirect
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.decorators.csrf import ensure_csrf_cookie
|
||||
from django.views.decorators.http import require_http_methods
|
||||
from common.djangoapps.course_modes.models import CourseMode
|
||||
from eventtracking import tracker
|
||||
from opaque_keys import InvalidKeyError
|
||||
from opaque_keys.edx.keys import AssetKey, CourseKey
|
||||
@@ -271,6 +272,28 @@ class CertificateManager:
|
||||
certificates = [certificate for certificate in certificates if certificate.get('is_active', False)]
|
||||
return certificates
|
||||
|
||||
@staticmethod
|
||||
def get_course_modes(course):
|
||||
"""
|
||||
Retrieve certificate modes for the given course,
|
||||
including expired modes but excluding audit mode.
|
||||
"""
|
||||
course_modes = [
|
||||
mode.slug for mode in CourseMode.modes_for_course(
|
||||
course=course, include_expired=True
|
||||
) if mode.slug != CourseMode.AUDIT
|
||||
]
|
||||
return course_modes
|
||||
|
||||
@staticmethod
|
||||
def is_enabled(course):
|
||||
"""
|
||||
Is enabled when there is at least one course mode for the given course,
|
||||
including expired modes but excluding audit mode
|
||||
"""
|
||||
course_modes = CertificateManager.get_course_modes(course)
|
||||
return len(course_modes) > 0
|
||||
|
||||
@staticmethod
|
||||
def remove_certificate(request, store, course, certificate_id):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user