Skip to content

Commit 2fdb8d4

Browse files
committed
chore: Implement TODOs
1 parent ae47f1d commit 2fdb8d4

2 files changed

Lines changed: 68 additions & 35 deletions

File tree

xblocks_contrib/video/toggles.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,35 @@ def get_course_organization(video_block, course_id):
4040
if video_config_service:
4141
return video_config_service.get_course_organization(course_id)
4242
return None
43+
44+
45+
def is_youtube_deprecated(video_block, course_id):
46+
"""Check if YouTube is deprecated."""
47+
video_config_service = video_block.runtime.service(video_block, 'video_config')
48+
if video_config_service:
49+
return video_config_service.is_youtube_deprecated(course_id)
50+
return False # Default from edx-platform: DEPRECATE_YOUTUBE toggle_default: False
51+
52+
53+
def is_youtube_blocked_for_course(video_block, course_id):
54+
"""Check if YouTube is blocked for course."""
55+
video_config_service = video_block.runtime.service(video_block, 'video_config')
56+
if video_config_service:
57+
return video_config_service.is_youtube_blocked_for_course(course_id)
58+
return False # Default from edx-platform: CourseYoutubeBlockedFlag default: False
59+
60+
61+
def is_public_video_share_enabled(video_block, course_id):
62+
"""Check if public video share is enabled."""
63+
video_config_service = video_block.runtime.service(video_block, 'video_config')
64+
if video_config_service:
65+
return video_config_service.is_public_video_share_enabled(course_id)
66+
return False # Default from edx-platform: PUBLIC_VIDEO_SHARE toggle_default: False
67+
68+
69+
def is_transcript_feedback_enabled(video_block, course_id):
70+
"""Check if transcript feedback is enabled."""
71+
video_config_service = video_block.runtime.service(video_block, 'video_config')
72+
if video_config_service:
73+
return video_config_service.is_transcript_feedback_enabled(course_id)
74+
return False # Default from edx-platform: TRANSCRIPT_FEEDBACK toggle_default: False

xblocks_contrib/video/video.py

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,23 @@
4747
is_hls_playback_enabled,
4848
get_branding_info,
4949
get_course_by_id,
50-
get_course_organization
50+
get_course_organization,
51+
is_youtube_deprecated,
52+
is_youtube_blocked_for_course,
53+
is_public_video_share_enabled,
54+
is_transcript_feedback_enabled
5155
)
5256
from xblocks_contrib.video.utils import deserialize_field, own_metadata
5357
from xblocks_contrib.video.validation import StudioValidation, StudioValidationMessage
54-
# TODO: reimport following wild card import
55-
from xblocks_contrib.video.constants import *
58+
from xblocks_contrib.video.constants import (
59+
STUDENT_VIEW,
60+
PUBLIC_VIEW,
61+
ATTR_KEY_USER_ID,
62+
ATTR_KEY_REQUEST_COUNTRY_CODE,
63+
COURSE_VIDEO_SHARING_PER_VIDEO,
64+
COURSE_VIDEO_SHARING_ALL_VIDEOS,
65+
COURSE_VIDEO_SHARING_NONE,
66+
)
5667
from xblocks_contrib.video.transcripts_utils import (
5768
Transcript,
5869
VideoTranscriptsMixin,
@@ -111,6 +122,7 @@
111122
LMS_ROOT_URL = "https://localhost:18000"
112123

113124

125+
# TODO: Add request_cache to the wants list
114126
@XBlock.wants('settings', 'completion', 'i18n')
115127
@XBlock.needs("i18n", 'user', 'video_config')
116128
class VideoBlock(
@@ -211,31 +223,25 @@ def youtube_deprecated(self):
211223
"""
212224
Return True if youtube is deprecated and hls as primary playback is enabled else False
213225
"""
214-
# # Return False if `hls` playback feature is disabled.
215-
# if not HLSPlaybackEnabledFlag.feature_enabled(self.location.course_key):
216-
# return False
217-
#
218-
# # check if youtube has been deprecated and hls as primary playback
219-
# # is enabled for this course
220-
# return DEPRECATE_YOUTUBE.is_enabled(self.location.course_key)
221-
# TODO: Implement this method
222-
return True
226+
# Return False if `hls` playback feature is disabled.
227+
if not is_hls_playback_enabled(self, self.location.course_key):
228+
return False
229+
230+
# check if youtube has been deprecated and hls as primary playback
231+
# is enabled for this course
232+
return is_youtube_deprecated(self, self.location.course_key)
223233

224234
def youtube_disabled_for_course(self): # lint-amnesty, pylint: disable=missing-function-docstring
225-
# TODO: Un comment following code
226-
# if not self.location.context_key.is_course:
227-
# return False # Only courses have this flag
228-
# request_cache = RequestCache('youtube_disabled_for_course')
229-
# cache_response = request_cache.get_cached_response(self.location.context_key)
230-
# if cache_response.is_found:
231-
# return cache_response.value
232-
233-
# # TODO: Un comment following as its linked to model
234-
# # youtube_is_disabled = CourseYoutubeBlockedFlag.feature_enabled(self.location.course_key)
235-
# youtube_is_disabled = True
236-
# request_cache.set(self.location.context_key, youtube_is_disabled)
237-
# return youtube_is_disabled
238-
return False
235+
if not self.location.context_key.is_course:
236+
return False # Only courses have this flag
237+
request_cache = RequestCache('youtube_disabled_for_course')
238+
cache_response = request_cache.get_cached_response(self.location.context_key)
239+
if cache_response.is_found:
240+
return cache_response.value
241+
242+
youtube_is_disabled = is_youtube_blocked_for_course(self, self.location.course_key)
243+
request_cache.set(self.location.context_key, youtube_is_disabled)
244+
return youtube_is_disabled
239245

240246
def prioritize_hls(self, youtube_streams, html5_sources):
241247
"""
@@ -326,7 +332,6 @@ def get_html(self, view=STUDENT_VIEW,
326332
try:
327333
val_profiles = ["youtube", "desktop_webm", "desktop_mp4"]
328334

329-
# Use VideoConfigService to check HLS playback enabled
330335
if is_hls_playback_enabled(self, self.course_id):
331336
val_profiles.append('hls')
332337

@@ -557,9 +562,7 @@ def is_public_sharing_enabled(self):
557562
return False # Only courses support this feature at all (not libraries)
558563
try:
559564
# Video share feature must be enabled for sharing settings to take effect
560-
# TODO: How to access waffle flag
561-
# feature_enabled = PUBLIC_VIDEO_SHARE.is_enabled(self.context_key)
562-
feature_enabled = False
565+
feature_enabled = is_public_video_share_enabled(self, self.context_key)
563566
except Exception as err: # pylint: disable=broad-except
564567
log.exception(f"Error retrieving course for course ID: {self.context_key}")
565568
return False
@@ -590,9 +593,7 @@ def is_transcript_feedback_enabled(self):
590593
return False # Only courses support this feature at all (not libraries)
591594
try:
592595
# Video transcript feedback must be enabled in order to show the widget
593-
# TODO: How to access waffle flags
594-
# feature_enabled = TRANSCRIPT_FEEDBACK.is_enabled(self.context_key)
595-
feature_enabled = False
596+
feature_enabled = is_transcript_feedback_enabled(self, self.context_key)
596597
except Exception as err: # pylint: disable=broad-except
597598
log.exception(f"Error retrieving course for course ID: {self.context_key}")
598599
return False
@@ -1048,7 +1049,7 @@ def get_youtube_link(video_id):
10481049
if self.edx_video_id and edxval_api:
10491050

10501051
val_profiles = ['youtube', 'desktop_webm', 'desktop_mp4']
1051-
if True: # TODO: HLSPlaybackEnabledFlag.feature_enabled(self.scope_ids.usage_id.context_key.for_branch(None)):
1052+
if is_hls_playback_enabled(self.scope_ids.usage_id.context_key.for_branch(None)):
10521053
val_profiles.append('hls')
10531054

10541055
# Get video encodings for val profiles.
@@ -1306,7 +1307,7 @@ def student_view_data(self, context=None):
13061307
# Check in VAL data first if edx_video_id exists
13071308
if self.edx_video_id:
13081309
video_profile_names = context.get("profiles", ["mobile_low", 'desktop_mp4', 'desktop_webm', 'mobile_high'])
1309-
if True: # TODO: HLSPlaybackEnabledFlag.feature_enabled(self.location.course_key) and 'hls' not in video_profile_names:
1310+
if is_hls_playback_enabled(self.location.course_key) and 'hls' not in video_profile_names:
13101311
video_profile_names.append('hls')
13111312

13121313
# get and cache bulk VAL data for course

0 commit comments

Comments
 (0)