Skip to content

Commit d361718

Browse files
committed
chore: move waffle flags, configs to video service
1 parent a50ab7d commit d361718

File tree

2 files changed

+41
-12
lines changed

2 files changed

+41
-12
lines changed

openedx/core/djangoapps/video_config/services.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88

99
import logging
1010

11-
from opaque_keys.edx.keys import CourseKey, UsageKey
12-
11+
from opaque_keys.edx.keys import (
12+
CourseKey,
13+
UsageKey,
14+
UsageKeyV2,
15+
)
1316
from openedx.core.djangoapps.video_config import sharing
1417
from organizations.api import get_course_organization
1518
from openedx.core.djangoapps.video_config.models import (
@@ -91,3 +94,30 @@ def is_hls_playback_enabled(self, course_id: CourseKey) -> bool:
9194
Check if HLS playback is enabled for the course.
9295
"""
9396
return HLSPlaybackEnabledFlag.feature_enabled(course_id)
97+
98+
def add_library_static_asset(self, usage_key: UsageKeyV2, filename: str, content: bytes) -> bool:
99+
"""
100+
This method provides access to the library API for adding static assets
101+
to Learning Core components.
102+
"""
103+
# Import here to avoid circular dependency
104+
from openedx.core.djangoapps.content_libraries.api import lib_api
105+
lib_api.add_library_block_static_asset_file(
106+
usage_key,
107+
filename,
108+
content,
109+
)
110+
return True
111+
112+
def delete_library_static_asset(self, usage_key: UsageKeyV2, filename: str) -> bool:
113+
"""
114+
This method provides access to the library API for deleting static assets
115+
from Learning Core components.
116+
"""
117+
# Import here to avoid circular dependency
118+
from openedx.core.djangoapps.content_libraries.api import lib_api
119+
lib_api.delete_library_block_static_asset_file(
120+
usage_key,
121+
filename,
122+
)
123+
return True

xmodule/video_block/video_handlers.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
from xmodule.exceptions import NotFoundError
2222
from xmodule.fields import RelativeTime
23-
from openedx.core.djangoapps.content_libraries import api as lib_api
2423

2524
from openedx.core.djangoapps.video_config.transcripts_utils import (
2625
Transcript,
@@ -563,11 +562,9 @@ def _studio_transcript_upload(self, request):
563562
if is_library:
564563
# Save transcript as static asset in Learning Core if is a library component
565564
filename = f"static/{filename}"
566-
lib_api.add_library_block_static_asset_file(
567-
self.usage_key,
568-
filename,
569-
content,
570-
)
565+
video_config_service = self.runtime.service(self, 'video_config')
566+
if video_config_service:
567+
video_config_service.add_library_static_asset(self.usage_key, filename, content)
571568
else:
572569
sjson_subs = Transcript.convert(
573570
content=content.decode('utf-8'),
@@ -625,10 +622,12 @@ def _studio_transcript_delete(self, request):
625622
# TODO: In the future, we need a proper XBlock API
626623
# like `self.static_assets.delete(...)` instead of coding
627624
# these runtime-specific/library-specific APIs.
628-
lib_api.delete_library_block_static_asset_file(
629-
self.usage_key,
630-
f"static/{transcript_name}",
631-
)
625+
video_config_service = self.runtime.service(self, 'video_config')
626+
if video_config_service:
627+
video_config_service.delete_library_static_asset(
628+
self.usage_key,
629+
f"static/{transcript_name}"
630+
)
632631
self._save_transcript_field()
633632
else:
634633
if language == 'en':

0 commit comments

Comments
 (0)