From 00d1cf5e0b44515c9b728215f4c0eda236ac6e92 Mon Sep 17 00:00:00 2001 From: hajorg Date: Mon, 4 Dec 2023 15:01:41 +0100 Subject: [PATCH 1/4] feat: add is_ai_translations_enabled to get_course_videos_context util --- cms/djangoapps/contentstore/rest_api/v1/serializers/videos.py | 1 + cms/djangoapps/contentstore/utils.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/cms/djangoapps/contentstore/rest_api/v1/serializers/videos.py b/cms/djangoapps/contentstore/rest_api/v1/serializers/videos.py index 04f508eedf..c5e730d127 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/serializers/videos.py +++ b/cms/djangoapps/contentstore/rest_api/v1/serializers/videos.py @@ -89,6 +89,7 @@ class CourseVideosSerializer(serializers.Serializer): video_upload_max_file_size = serializers.CharField() video_image_settings = VideoImageSettingsSerializer(required=True, allow_null=False) is_video_transcript_enabled = serializers.BooleanField() + is_ai_translations_enabled = serializers.BooleanField() active_transcript_preferences = VideoActiveTranscriptPreferencesSerializer(required=False, allow_null=True) transcript_credentials = serializers.DictField( child=serializers.BooleanField() diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index 8e3f97eee9..cb9f77b3bd 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -1595,6 +1595,7 @@ def get_course_videos_context(course_block, pagination_conf, course_key=None): get_transcript_preferences, ) from openedx.core.djangoapps.video_config.models import VideoTranscriptEnabledFlag + from openedx.core.djangoapps.video_config.toggles import XPERT_TRANSLATIONS_UI from xmodule.video_block.transcripts_utils import Transcript # lint-amnesty, pylint: disable=wrong-import-order from .video_storage_handlers import ( @@ -1619,6 +1620,7 @@ def get_course_videos_context(course_block, pagination_conf, course_key=None): course = modulestore().get_course(course_key) is_video_transcript_enabled = VideoTranscriptEnabledFlag.feature_enabled(course.id) + is_ai_translations_enabled = XPERT_TRANSLATIONS_UI.is_enabled(course.id) previous_uploads, pagination_context = _get_index_videos(course, pagination_conf) course_video_context = { 'context_course': course, @@ -1639,6 +1641,7 @@ def get_course_videos_context(course_block, pagination_conf, course_key=None): 'supported_file_formats': settings.VIDEO_IMAGE_SUPPORTED_FILE_FORMATS }, 'is_video_transcript_enabled': is_video_transcript_enabled, + 'is_ai_translations_enabled': is_ai_translations_enabled, 'active_transcript_preferences': None, 'transcript_credentials': None, 'transcript_available_languages': get_all_transcript_languages(), From b70e29a0ab47928fa6916d0bd22cdcb41f3cd185 Mon Sep 17 00:00:00 2001 From: hajorg Date: Mon, 4 Dec 2023 16:43:59 +0100 Subject: [PATCH 2/4] feat: add test for is_ai_translations_enabled --- .../contentstore/rest_api/v1/views/tests/test_videos.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_videos.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_videos.py index d5d277c498..753ddcfb28 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_videos.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_videos.py @@ -56,6 +56,7 @@ class CourseVideosViewTest(CourseTestCase, PermissionAccessMixin): "supported_file_formats": settings.VIDEO_IMAGE_SUPPORTED_FILE_FORMATS }, "is_video_transcript_enabled": False, + "is_ai_translations_enabled": False, "active_transcript_preferences": None, "transcript_credentials": None, "transcript_available_languages": get_all_transcript_languages(), @@ -126,3 +127,9 @@ class CourseVideosViewTest(CourseTestCase, PermissionAccessMixin): ) self.assertIn("transcript_credentials_handler_url", transcript_settings) self.assertEqual(expected_credentials_handler, transcript_settings["transcript_credentials_handler_url"]) + from openedx.core.djangoapps.video_config.toggles import XPERT_TRANSLATIONS_UI + with patch('openedx.core.djangoapps.video_config.toggles.XPERT_TRANSLATIONS_UI.is_enabled') as xpertTranslationfeature: + xpertTranslationfeature.return_value = True + response = self.client.get(self.url) + self.assertIn("is_ai_translations_enabled", response.data) + self.assertTrue(response.data["is_ai_translations_enabled"]) From 4bc2e74a40cd53a2045e8efcc72ce10d66379d1f Mon Sep 17 00:00:00 2001 From: hajorg Date: Mon, 4 Dec 2023 17:13:30 +0100 Subject: [PATCH 3/4] fix: resolve lint issue --- .../contentstore/rest_api/v1/views/tests/test_videos.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_videos.py b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_videos.py index 753ddcfb28..993072e071 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_videos.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/tests/test_videos.py @@ -127,8 +127,9 @@ class CourseVideosViewTest(CourseTestCase, PermissionAccessMixin): ) self.assertIn("transcript_credentials_handler_url", transcript_settings) self.assertEqual(expected_credentials_handler, transcript_settings["transcript_credentials_handler_url"]) - from openedx.core.djangoapps.video_config.toggles import XPERT_TRANSLATIONS_UI - with patch('openedx.core.djangoapps.video_config.toggles.XPERT_TRANSLATIONS_UI.is_enabled') as xpertTranslationfeature: + with patch( + 'openedx.core.djangoapps.video_config.toggles.XPERT_TRANSLATIONS_UI.is_enabled' + ) as xpertTranslationfeature: xpertTranslationfeature.return_value = True response = self.client.get(self.url) self.assertIn("is_ai_translations_enabled", response.data) From 0190a0cc9ed4e58c4255f24c986225e461c7996c Mon Sep 17 00:00:00 2001 From: hajorg Date: Tue, 5 Dec 2023 17:36:13 +0100 Subject: [PATCH 4/4] feat: use function to access xpert translations ui waffle flag --- cms/djangoapps/contentstore/utils.py | 5 +++-- openedx/core/djangoapps/video_config/toggles.py | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index cb9f77b3bd..112431b612 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -77,6 +77,7 @@ from cms.djangoapps.contentstore.toggles import ( use_new_video_uploads_page, use_new_custom_pages, use_tagging_taxonomy_list_page, + # use_xpert_translations_component, ) from cms.djangoapps.models.settings.course_grading import CourseGradingModel from xmodule.library_tools import LibraryToolsService @@ -1595,7 +1596,7 @@ def get_course_videos_context(course_block, pagination_conf, course_key=None): get_transcript_preferences, ) from openedx.core.djangoapps.video_config.models import VideoTranscriptEnabledFlag - from openedx.core.djangoapps.video_config.toggles import XPERT_TRANSLATIONS_UI + from openedx.core.djangoapps.video_config.toggles import use_xpert_translations_component from xmodule.video_block.transcripts_utils import Transcript # lint-amnesty, pylint: disable=wrong-import-order from .video_storage_handlers import ( @@ -1620,7 +1621,7 @@ def get_course_videos_context(course_block, pagination_conf, course_key=None): course = modulestore().get_course(course_key) is_video_transcript_enabled = VideoTranscriptEnabledFlag.feature_enabled(course.id) - is_ai_translations_enabled = XPERT_TRANSLATIONS_UI.is_enabled(course.id) + is_ai_translations_enabled = use_xpert_translations_component(course.id) previous_uploads, pagination_context = _get_index_videos(course, pagination_conf) course_video_context = { 'context_course': course, diff --git a/openedx/core/djangoapps/video_config/toggles.py b/openedx/core/djangoapps/video_config/toggles.py index f417537b54..9569a00edd 100644 --- a/openedx/core/djangoapps/video_config/toggles.py +++ b/openedx/core/djangoapps/video_config/toggles.py @@ -37,3 +37,10 @@ TRANSCRIPT_FEEDBACK = CourseWaffleFlag( XPERT_TRANSLATIONS_UI = CourseWaffleFlag( f'{WAFFLE_FLAG_NAMESPACE}.xpert_translations_ui', __name__ ) + + +def use_xpert_translations_component(course_key): + """ + Returns a boolean if xpert translations ui component is enabled + """ + return XPERT_TRANSLATIONS_UI.is_enabled(course_key)