From 9ad3f0ff60a5c9d538ad38dda71db2f8fa44edf4 Mon Sep 17 00:00:00 2001 From: Jansen Kantor Date: Fri, 10 Mar 2023 12:54:07 -0500 Subject: [PATCH] fix: share link should show even if video download is disabled (#31902) * fix: share link should show even if video download is disabled * fixup! fix: share link should show even if video download is disabled * chore: update test * chore: linting --------- Co-authored-by: Leangseu Kim --- .../courseware/tests/test_video_mongo.py | 18 +++++--- lms/templates/video.html | 42 ++++++++++--------- xmodule/video_block/video_block.py | 12 ++++-- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/lms/djangoapps/courseware/tests/test_video_mongo.py b/lms/djangoapps/courseware/tests/test_video_mongo.py index dd728597c9..9abdf022a1 100644 --- a/lms/djangoapps/courseware/tests/test_video_mongo.py +++ b/lms/djangoapps/courseware/tests/test_video_mongo.py @@ -48,6 +48,7 @@ from xmodule.x_module import PUBLIC_VIEW, STUDENT_VIEW from common.djangoapps.xblock_django.constants import ATTR_KEY_REQUEST_COUNTRY_CODE from lms.djangoapps.courseware.tests.helpers import get_context_dict_from_string +from lms.djangoapps.courseware.toggles import PUBLIC_VIDEO_SHARE from openedx.core.djangoapps.video_pipeline.config.waffle import DEPRECATE_YOUTUBE from openedx.core.djangoapps.waffle_utils.models import WaffleFlagCourseOverrideModel from openedx.core.djangolib.testing.utils import CacheIsolationTestCase @@ -237,14 +238,21 @@ class TestVideoPublicAccess(BaseTestVideoXBlock): } METADATA = {} - @ddt.data(True, False) - def test_public_video_url(self, is_lms_platform): + @ddt.data( + (True, False), + (False, False), + (True, True), + ) + @ddt.unpack + def test_public_video_url(self, is_lms_platform, enable_public_share): """Test public video url.""" assert self.item_descriptor.public_access is True - with patch.object(self.item_descriptor, '_is_lms_platform', return_value=is_lms_platform): + with patch.object(self.item_descriptor, '_is_lms_platform', return_value=is_lms_platform), \ + patch.object(PUBLIC_VIDEO_SHARE, 'is_enabled', return_value=enable_public_share): context = self.item_descriptor.render(STUDENT_VIEW).content - # public video url iif is_lms_platform and public_access are true - assert bool(get_context_dict_from_string(context)['public_video_url']) is is_lms_platform + # public video url iif PUBLIC_VIDEO_SHARE waffle and is_lms_platform, public_access are true + assert bool(get_context_dict_from_string(context)['public_video_url']) \ + is (is_lms_platform and enable_public_share) @ddt.ddt diff --git a/lms/templates/video.html b/lms/templates/video.html index 36f91b47c0..75de10acda 100644 --- a/lms/templates/video.html +++ b/lms/templates/video.html @@ -46,27 +46,31 @@ from openedx.core.djangolib.js_utils import (
- % if (download_video_link or track or handout or branding_info) and not hide_downloads: + % if (download_video_link or track or handout or branding_info or public_video_url) and not hide_downloads:

${_('Downloads and transcripts')}

- % if download_video_link: -
-

${_('Video')}

- - ${_('Download video file')} - - % if public_video_url: -
- - ${_('Share on Twitter')} - - % endif -
+ % if download_video_link or public_video_url: +
+

${_('Video')}

+ % if download_video_link: + + ${_('Download video file')} + + % endif + % if download_video_link and public_video_url: +
+ % endif + % if public_video_url: + + ${_('Share on Twitter')} + + % endif +
% endif % if track:
diff --git a/xmodule/video_block/video_block.py b/xmodule/video_block/video_block.py index 0609fe30ef..2d2a4300f9 100644 --- a/xmodule/video_block/video_block.py +++ b/xmodule/video_block/video_block.py @@ -494,10 +494,14 @@ class VideoBlock( """ Returns the public video url """ - return urljoin( - settings.LMS_ROOT_URL, - reverse('render_public_video_xblock', kwargs={'usage_key_string': str(self.location)}) - ) if self.public_access and self._is_lms_platform() else None + if self.public_access and self._is_lms_platform(): + from lms.djangoapps.courseware.toggles import PUBLIC_VIDEO_SHARE + if PUBLIC_VIDEO_SHARE.is_enabled(self.location.course_key): + return urljoin( + settings.LMS_ROOT_URL, + reverse('render_public_video_xblock', kwargs={'usage_key_string': str(self.location)}) + ) + return None def validate(self): """