Unverified Commit 34d8b1fb by Tasawer Nawaz Committed by GitHub

Merge pull request #16515 from edx/tasawer/learner-3097/fix-certificates-visibility-on-profile-page

Fix certificates visibility to students on the profile page before the available date
parents 947b8723 d2827b3d
......@@ -201,3 +201,19 @@ class LearnerProfileViewTest(UrlResetMixin, ModuleStoreTestCase):
self.assertContains(response, 'Explore New Courses')
else:
self.assertNotContains(response, 'Explore New Courses')
def test_certificate_for_visibility_for_not_viewable_course(self):
"""
Verify that a certificate is not shown if certificate are not viewable to users.
"""
# add new course with certificate_available_date is future date.
course = CourseFactory.create(
certificate_available_date=datetime.datetime.now() + datetime.timedelta(days=5)
)
cert = self._create_certificate(course_key=course.id)
cert.save()
response = self.client.get('/u/{username}'.format(username=self.user.username))
self.assertNotContains(response, 'card certificate-card mode-{cert_mode}'.format(cert_mode=cert.mode))
......@@ -4,6 +4,7 @@ Views to render a learner's achievements.
from django.template.loader import render_to_string
from lms.djangoapps.certificates import api as certificate_api
from openedx.core.djangoapps.certificates.api import certificates_viewable_for_course
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
from openedx.core.djangoapps.plugin_api.views import EdxFragmentView
from web_fragments.fragment import Fragment
......@@ -41,7 +42,8 @@ class LearnerAchievementsFragmentView(EdxFragmentView):
try:
course_overview = CourseOverview.get_from_id(course_key)
course_certificate['course'] = course_overview
passing_certificates.append(course_certificate)
if certificates_viewable_for_course(course_overview):
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment