diff --git a/lms/djangoapps/certificates/api.py b/lms/djangoapps/certificates/api.py index 36e8e216618ede2c1f75a04e815039f88a5803f6..efb5a866a6cd070f10635dff199ee40dc9ade0ab 100644 --- a/lms/djangoapps/certificates/api.py +++ b/lms/djangoapps/certificates/api.py @@ -290,6 +290,7 @@ def certificate_downloadable_status(student, course_key): if current_status['status'] == CertificateStatuses.downloadable and may_view_certificate: response_data['is_downloadable'] = True response_data['download_url'] = current_status['download_url'] or get_certificate_url(student.id, course_key) + response_data['is_pdf_certificate'] = bool(current_status['download_url']) response_data['uuid'] = current_status['uuid'] return response_data diff --git a/lms/djangoapps/certificates/tests/test_api.py b/lms/djangoapps/certificates/tests/test_api.py index ac447fb9faa814147c9c307e9541bce9933d5841..c8d00114d632eb309b84d0218a62fe23b7ee3429 100644 --- a/lms/djangoapps/certificates/tests/test_api.py +++ b/lms/djangoapps/certificates/tests/test_api.py @@ -173,6 +173,7 @@ class CertificateDownloadableStatusTests(WebCertificateTestMixin, ModuleStoreTes 'is_generating': False, 'is_unverified': False, 'download_url': 'www.google.com', + 'is_pdf_certificate': True, 'uuid': cert.verify_uuid } ) @@ -202,6 +203,7 @@ class CertificateDownloadableStatusTests(WebCertificateTestMixin, ModuleStoreTes user_id=self.student.id, course_id=self.course.id, ), + 'is_pdf_certificate': False, 'uuid': cert_status['uuid'] } ) diff --git a/lms/djangoapps/courseware/views/views.py b/lms/djangoapps/courseware/views/views.py index 53915d69bd019aea31692a461692e04708e32a9a..29232168649599e4df4446fd1b412814ee887463 100644 --- a/lms/djangoapps/courseware/views/views.py +++ b/lms/djangoapps/courseware/views/views.py @@ -1136,7 +1136,7 @@ def _downloadable_certificate_message(course, cert_downloadable_status): course_id=course.id, uuid=cert_downloadable_status['uuid'] ) ) - elif not cert_downloadable_status['download_url']: + elif not cert_downloadable_status['is_pdf_certificate']: return GENERATING_CERT_DATA return _downloadable_cert_data(download_url=cert_downloadable_status['download_url']) diff --git a/openedx/features/learner_profile/tests/views/test_learner_profile.py b/openedx/features/learner_profile/tests/views/test_learner_profile.py index e2eb0517de2f885757a372dc50b498dbe4044092..cb52924aadd506a6f427de3f610b98553574fa4b 100644 --- a/openedx/features/learner_profile/tests/views/test_learner_profile.py +++ b/openedx/features/learner_profile/tests/views/test_learner_profile.py @@ -18,6 +18,7 @@ from django.test.client import RequestFactory from opaque_keys.edx.locator import CourseLocator from openedx.features.learner_profile.toggles import REDIRECT_TO_PROFILE_MICROFRONTEND from openedx.features.learner_profile.views.learner_profile import learner_profile_context +from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.site_configuration.tests.mixins import SiteMixin from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag from student.tests.factories import CourseEnrollmentFactory, UserFactory @@ -269,3 +270,28 @@ class LearnerProfileViewTest(SiteMixin, UrlResetMixin, ModuleStoreTestCase): profile_username = self.user.username context = learner_profile_context(request, profile_username, user_is_staff) self.assertIn('achievements_fragment', context) + + @mock.patch.dict(settings.FEATURES, {'CERTIFICATES_HTML_VIEW': True}) + def test_certificate_visibility_with_no_cert_config(self): + """ + Verify that certificates are not displayed until there is no active + certificate configuration. + """ + # Add new certificate + cert = self._create_certificate(enrollment_mode=CourseMode.VERIFIED) + cert.download_url = '' + cert.save() + + response = self.client.get('/u/{username}'.format(username=self.user.username)) + self.assertNotContains( + response, u'card certificate-card mode-{cert_mode}'.format(cert_mode=CourseMode.VERIFIED) + ) + + course_overview = CourseOverview.get_from_id(self.course.id) + course_overview.has_any_active_web_certificate = True + course_overview.save() + + response = self.client.get('/u/{username}'.format(username=self.user.username)) + self.assertContains( + response, u'card certificate-card mode-{cert_mode}'.format(cert_mode=CourseMode.VERIFIED) + ) diff --git a/openedx/features/learner_profile/views/learner_achievements.py b/openedx/features/learner_profile/views/learner_achievements.py index d53947a29484fc73283fc086f24050ce21c51115..0b618fcfae0b8f58babad9e12d4e3dec4d3efab9 100644 --- a/openedx/features/learner_profile/views/learner_achievements.py +++ b/openedx/features/learner_profile/views/learner_achievements.py @@ -44,7 +44,10 @@ class LearnerAchievementsFragmentView(EdxFragmentView): course_overview = CourseOverview.get_from_id(course_key) course_certificate['course'] = course_overview if certificates_viewable_for_course(course_overview): - passing_certificates.append(course_certificate) + # add certificate into passing certificate list only if it's a PDF certificate + # or there is an active certificate configuration. + if course_certificate['is_pdf_certificate'] or course_overview.has_any_active_web_certificate: + passing_certificates.append(course_certificate) except CourseOverview.DoesNotExist: # This is unlikely to fail as the course should exist. # Ideally the cert should have all the information that