From bf1c434f10db55a512ba62b09f1fa6736f353d2f Mon Sep 17 00:00:00 2001 From: alipov-dm Date: Mon, 15 May 2023 13:05:57 +0300 Subject: [PATCH 1/2] fix: share certificate in FB Fixed the Course Card Image is absent on FB post after sharing by user. Commit for Palm release. --- .../certificates/tests/test_webview_views.py | 63 +++++++++++++++++++ .../certificates/_accomplishment-banner.html | 2 +- .../certificates/accomplishment-base.html | 10 ++- 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/lms/djangoapps/certificates/tests/test_webview_views.py b/lms/djangoapps/certificates/tests/test_webview_views.py index 96832e3cb694..5489f28e0f7e 100644 --- a/lms/djangoapps/certificates/tests/test_webview_views.py +++ b/lms/djangoapps/certificates/tests/test_webview_views.py @@ -49,6 +49,7 @@ ) from openedx.core.djangolib.js_utils import js_escaped_string from openedx.core.djangolib.testing.utils import CacheIsolationTestCase +from openedx.core.lib.courses import course_image_url from openedx.core.lib.tests.assertions.events import assert_event_matches from openedx.features.name_affirmation_api.utils import get_name_affirmation_service from xmodule.data import CertificatesDisplayBehaviors # lint-amnesty, pylint: disable=wrong-import-order @@ -351,6 +352,68 @@ def test_linkedin_share_url_site(self): js_escaped_string(self.linkedin_url.format(params=urlencode(params))), ) + @patch.dict("django.conf.settings.SOCIAL_SHARING_SETTINGS", { + "CERTIFICATE_FACEBOOK": True, + "CERTIFICATE_FACEBOOK_TEXT": "test FB text" + }) + @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + def test_render_certificate_html_view_with_facebook_meta_tags(self): + """ + Test view html certificate if share to FB is enabled. + If 'facebook_share_enabled=True', tags with property="og:..." + must be enabled to pass parameters to FB. + """ + self._add_course_certificates(count=1, signatory_count=1, is_active=True) + self.course.cert_html_view_enabled = True + self.course.save() + self.update_course(self.course, self.user.id) + test_url = get_certificate_url( + user_id=self.user.id, + course_id=str(self.course.id), + uuid=self.cert.verify_uuid + ) + platform_name = settings.PLATFORM_NAME + share_url = f'http://testserver{test_url}' + full_course_image_url = f'http://testserver{course_image_url(self.course)}' + document_title = f'{self.course.org} {self.course.number} Certificate | {platform_name}' + response = self.client.get(test_url) + + assert response.status_code == 200 + self.assertContains(response, f'') + self.assertContains(response, f'') + self.assertContains(response, '') + self.assertContains(response, f'') + self.assertContains(response, '') + + @patch.dict("django.conf.settings.SOCIAL_SHARING_SETTINGS", { + "CERTIFICATE_FACEBOOK": False, + }) + @override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED) + def test_render_certificate_html_view_without_facebook_meta_tags(self): + """ + Test view html certificate if share to FB is disabled. + If 'facebook_share_enabled=False', html certificate view + should not contain tags with parameters property="og:..." + """ + self._add_course_certificates(count=1, signatory_count=1, is_active=True) + self.course.cert_html_view_enabled = True + self.course.save() + self.update_course(self.course, self.user.id) + + test_url = get_certificate_url( + user_id=self.user.id, + course_id=str(self.course.id), + uuid=self.cert.verify_uuid + ) + response = self.client.get(test_url) + + assert response.status_code == 200 + self.assertNotContains(response, '') + self.assertNotContains(response, '${_("Print or share your certificate:")} % if facebook_share_enabled: ${_("Post on Facebook")} diff --git a/lms/templates/certificates/accomplishment-base.html b/lms/templates/certificates/accomplishment-base.html index 158c7698e80a..92c58dc138ff 100644 --- a/lms/templates/certificates/accomplishment-base.html +++ b/lms/templates/certificates/accomplishment-base.html @@ -15,7 +15,15 @@ - + % if facebook_share_enabled: + ## OG (Open Graph) url, title, type, image and description added below to give social media info to display + ## (https://developers.facebook.com/docs/opengraph/howtos/maximizing-distribution-media-content#tags) + + + + + + %endif ${document_title} <%static:css group='style-certificates'/> From 9259411647587105425a895a703d8b05c824a11c Mon Sep 17 00:00:00 2001 From: alipov_d Date: Wed, 16 Aug 2023 15:24:13 +0100 Subject: [PATCH 2/2] fix: User retirement 404 for state RETIRING_FORUMS --- lms/djangoapps/discussion/rest_api/urls.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lms/djangoapps/discussion/rest_api/urls.py b/lms/djangoapps/discussion/rest_api/urls.py index b861bd7848d6..f54637dc3724 100644 --- a/lms/djangoapps/discussion/rest_api/urls.py +++ b/lms/djangoapps/discussion/rest_api/urls.py @@ -64,7 +64,11 @@ CourseView.as_view(), name="discussion_course" ), - path('v1/accounts/retire_forum', RetireUserView.as_view(), name="retire_discussion_user"), + re_path( + r"^v1/accounts/retire_forum/?$", + RetireUserView.as_view(), + name="retire_discussion_user" + ), path('v1/accounts/replace_username', ReplaceUsernamesView.as_view(), name="replace_discussion_username"), re_path( fr"^v1/course_topics/{settings.COURSE_ID_PATTERN}",