Skip to content

Commit 0eef233

Browse files
authored
Merge pull request #600 from open-craft/sync-open-release/palm.master-20231106-1699229227
Sync opencraft-release/palm.1 with Upstream 20231106-1699229227
2 parents dff3647 + 96ec8d0 commit 0eef233

File tree

4 files changed

+78
-3
lines changed

4 files changed

+78
-3
lines changed

lms/djangoapps/certificates/tests/test_webview_views.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
)
5050
from openedx.core.djangolib.js_utils import js_escaped_string
5151
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase
52+
from openedx.core.lib.courses import course_image_url
5253
from openedx.core.lib.tests.assertions.events import assert_event_matches
5354
from openedx.features.name_affirmation_api.utils import get_name_affirmation_service
5455
from xmodule.data import CertificatesDisplayBehaviors # lint-amnesty, pylint: disable=wrong-import-order
@@ -352,6 +353,68 @@ def test_linkedin_share_url_site(self):
352353
js_escaped_string(self.linkedin_url.format(params=urlencode(params))),
353354
)
354355

356+
@patch.dict("django.conf.settings.SOCIAL_SHARING_SETTINGS", {
357+
"CERTIFICATE_FACEBOOK": True,
358+
"CERTIFICATE_FACEBOOK_TEXT": "test FB text"
359+
})
360+
@override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED)
361+
def test_render_certificate_html_view_with_facebook_meta_tags(self):
362+
"""
363+
Test view html certificate if share to FB is enabled.
364+
If 'facebook_share_enabled=True', <meta> tags with property="og:..."
365+
must be enabled to pass parameters to FB.
366+
"""
367+
self._add_course_certificates(count=1, signatory_count=1, is_active=True)
368+
self.course.cert_html_view_enabled = True
369+
self.course.save()
370+
self.update_course(self.course, self.user.id)
371+
test_url = get_certificate_url(
372+
user_id=self.user.id,
373+
course_id=str(self.course.id),
374+
uuid=self.cert.verify_uuid
375+
)
376+
platform_name = settings.PLATFORM_NAME
377+
share_url = f'http://testserver{test_url}'
378+
full_course_image_url = f'http://testserver{course_image_url(self.course)}'
379+
document_title = f'{self.course.org} {self.course.number} Certificate | {platform_name}'
380+
response = self.client.get(test_url)
381+
382+
assert response.status_code == 200
383+
self.assertContains(response, f'<meta property="og:url" content="{share_url}" />')
384+
self.assertContains(response, f'<meta property="og:title" content="{document_title}" />')
385+
self.assertContains(response, '<meta property="og:type" content="image/png" />')
386+
self.assertContains(response, f'<meta property="og:image" content="{full_course_image_url}" />')
387+
self.assertContains(response, '<meta property="og:description" content="test FB text" />')
388+
389+
@patch.dict("django.conf.settings.SOCIAL_SHARING_SETTINGS", {
390+
"CERTIFICATE_FACEBOOK": False,
391+
})
392+
@override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED)
393+
def test_render_certificate_html_view_without_facebook_meta_tags(self):
394+
"""
395+
Test view html certificate if share to FB is disabled.
396+
If 'facebook_share_enabled=False', html certificate view
397+
should not contain <meta> tags with parameters property="og:..."
398+
"""
399+
self._add_course_certificates(count=1, signatory_count=1, is_active=True)
400+
self.course.cert_html_view_enabled = True
401+
self.course.save()
402+
self.update_course(self.course, self.user.id)
403+
404+
test_url = get_certificate_url(
405+
user_id=self.user.id,
406+
course_id=str(self.course.id),
407+
uuid=self.cert.verify_uuid
408+
)
409+
response = self.client.get(test_url)
410+
411+
assert response.status_code == 200
412+
self.assertNotContains(response, '<meta property="og:url" ')
413+
self.assertNotContains(response, '<meta property="og:title" ')
414+
self.assertNotContains(response, '<meta property="og:type" content="image/png" />')
415+
self.assertNotContains(response, '<meta property="og:image" ')
416+
self.assertNotContains(response, '<meta property="og:description" ')
417+
355418
@override_settings(FEATURES=FEATURES_WITH_CERTS_ENABLED)
356419
@patch.dict("django.conf.settings.SOCIAL_SHARING_SETTINGS", {"CERTIFICATE_FACEBOOK": True})
357420
@with_site_configuration(

lms/djangoapps/discussion/rest_api/urls.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@
6464
CourseView.as_view(),
6565
name="discussion_course"
6666
),
67-
path('v1/accounts/retire_forum', RetireUserView.as_view(), name="retire_discussion_user"),
67+
re_path(
68+
r"^v1/accounts/retire_forum/?$",
69+
RetireUserView.as_view(),
70+
name="retire_discussion_user"
71+
),
6872
path('v1/accounts/replace_username', ReplaceUsernamesView.as_view(), name="replace_discussion_username"),
6973
re_path(
7074
fr"^v1/course_topics/{settings.COURSE_ID_PATTERN}",

lms/templates/certificates/_accomplishment-banner.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ <h3 class="sr-only">${_("Print or share your certificate:")}</h3>
5151
% if facebook_share_enabled:
5252
<button class="action action-share-facebook btn-inverse btn-small icon-only" id="action-share-facebook"
5353
## xss-lint: disable=mako-invalid-html-filter
54-
onclick="FaceBook.share({share_text: '${facebook_share_text | n, js_escaped_string}', share_link: '${share_url | n, js_escaped_string}', picture_link: '${full_course_image_url | n, js_escaped_string}', description: '${_('Click the link to see my certificate.') | n, js_escaped_string}'});">
54+
onclick="FaceBook.share({share_link: '${share_url | n, js_escaped_string}'});"></button>
5555
<span class="icon fa fa-facebook-official" aria-hidden="true"></span>
5656
<span class="action-label">${_("Post on Facebook")}</span>
5757
</button>

lms/templates/certificates/accomplishment-base.html

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,15 @@
1515
<meta http-equiv="X-UA-Compatible" content="IE=edge">
1616
<meta charset="utf-8">
1717
<meta name="viewport" content="width=device-width, initial-scale=1">
18-
18+
% if facebook_share_enabled:
19+
## OG (Open Graph) url, title, type, image and description added below to give social media info to display
20+
## (https://developers.facebook.com/docs/opengraph/howtos/maximizing-distribution-media-content#tags)
21+
<meta property="og:url" content="${share_url}" />
22+
<meta property="og:title" content="${document_title}" />
23+
<meta property="og:type" content="image/png" />
24+
<meta property="og:image" content="${full_course_image_url}" />
25+
<meta property="og:description" content="${facebook_share_text}" />
26+
%endif
1927
<title>${document_title}</title>
2028

2129
<%static:css group='style-certificates'/>

0 commit comments

Comments
 (0)