-
Notifications
You must be signed in to change notification settings - Fork 4.3k
refactor: Introduce VideoConfig service, move video sharing methods in it #37459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| """ | ||
| Video Configuration Service for XBlock runtime. | ||
|
|
||
| This service provides video-related configuration and feature flags | ||
| that are specific to the edx-platform implementation | ||
| for the extracted video block in xblocks-contrib repository. | ||
| """ | ||
|
|
||
| import logging | ||
|
|
||
| from opaque_keys.edx.keys import CourseKey, UsageKey | ||
|
|
||
| from openedx.core.djangoapps.video_config import sharing | ||
| from organizations.api import get_course_organization | ||
|
|
||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class VideoConfigService: | ||
| """ | ||
| Service for providing video-related configuration and feature flags. | ||
|
|
||
| This service abstracts away edx-platform specific functionality | ||
| that the Video XBlock needs, allowing the Video XBlock to be | ||
| extracted to a separate repository. | ||
| """ | ||
|
|
||
| def get_public_video_url(self, usage_id: UsageKey) -> str: | ||
| """ | ||
| Returns the public video url | ||
| """ | ||
| return sharing.get_public_video_url(usage_id) | ||
|
|
||
| def get_public_sharing_context(self, video_block, course_key: CourseKey) -> dict: | ||
| """ | ||
| Get the complete public sharing context for a video. | ||
|
|
||
| Args: | ||
| video_block: The video XBlock instance | ||
| course_key: The course identifier | ||
|
|
||
| Returns: | ||
| dict: Context dictionary with sharing information, empty if sharing is disabled | ||
| """ | ||
| context = {} | ||
|
|
||
| if not sharing.is_public_sharing_enabled(video_block.location, video_block.public_access): | ||
| return context | ||
|
|
||
| public_video_url = sharing.get_public_video_url(video_block.location) | ||
| context['public_sharing_enabled'] = True | ||
| context['public_video_url'] = public_video_url | ||
|
|
||
| organization = get_course_organization(course_key) | ||
|
|
||
| from openedx.core.djangoapps.video_config.sharing_sites import sharing_sites_info_for_video | ||
| sharing_sites_info = sharing_sites_info_for_video( | ||
| public_video_url, | ||
| organization=organization | ||
| ) | ||
| context['sharing_sites_info'] = sharing_sites_info | ||
|
|
||
| return context |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| """ | ||
| Provides utility methods for video sharing functionality. | ||
| """ | ||
|
|
||
| import logging | ||
|
|
||
| from django.conf import settings | ||
| from opaque_keys.edx.keys import UsageKey | ||
|
|
||
| from openedx.core.djangoapps.video_config.toggles import PUBLIC_VIDEO_SHARE | ||
| from openedx.core.lib.courses import get_course_by_id | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
||
| # Video sharing constants | ||
| COURSE_VIDEO_SHARING_PER_VIDEO = 'per-video' | ||
| COURSE_VIDEO_SHARING_ALL_VIDEOS = 'all-on' | ||
| COURSE_VIDEO_SHARING_NONE = 'all-off' | ||
|
|
||
|
|
||
| @staticmethod | ||
| def get_public_video_url(usage_id: UsageKey) -> str: | ||
| """ | ||
| Returns the public video url | ||
| """ | ||
| return fr'{settings.LMS_ROOT_URL}/videos/{str(usage_id)}' | ||
|
|
||
|
|
||
| @staticmethod | ||
| def is_public_sharing_enabled(usage_key: UsageKey, public_access: bool) -> bool: | ||
| """ | ||
| Check if public sharing is enabled for a video. | ||
|
|
||
| Args: | ||
| usage_key: The usage key of the video block | ||
| public_access: Whether the video block has public access enabled | ||
| """ | ||
| if not usage_key.context_key.is_course: | ||
| return False # Only courses support this feature (not libraries) | ||
|
|
||
| try: | ||
| # Video share feature must be enabled for sharing settings to take effect | ||
| feature_enabled = PUBLIC_VIDEO_SHARE.is_enabled(usage_key.context_key) | ||
| except Exception as err: # pylint: disable=broad-except | ||
| log.exception(f"Error retrieving course for course ID: {usage_key.context_key}") | ||
| return False | ||
|
|
||
| if not feature_enabled: | ||
| return False | ||
|
|
||
| # Check if the course specifies a general setting | ||
| course_video_sharing_option = get_course_video_sharing_override(usage_key) | ||
|
|
||
| # Course can override all videos to be shared | ||
| if course_video_sharing_option == COURSE_VIDEO_SHARING_ALL_VIDEOS: | ||
| return True | ||
|
|
||
| # ... or no videos to be shared | ||
| elif course_video_sharing_option == COURSE_VIDEO_SHARING_NONE: | ||
| return False | ||
|
|
||
| # ... or can fall back to per-video setting | ||
| # Equivalent to COURSE_VIDEO_SHARING_PER_VIDEO or None / unset | ||
| else: | ||
| return public_access | ||
|
|
||
|
|
||
| @staticmethod | ||
| def get_course_video_sharing_override(usage_key: UsageKey) -> str | None: | ||
| """ | ||
| Return course video sharing options override | ||
| """ | ||
| if not usage_key.context_key.is_course: | ||
| return False # Only courses support this feature (not libraries) | ||
|
|
||
| try: | ||
| course = get_course_by_id(usage_key.context_key) | ||
| return getattr(course, 'video_sharing_options', None) | ||
| except Exception as err: # pylint: disable=broad-except | ||
| log.exception(f"Error retrieving course for course ID: {usage_key.context_key}") | ||
| return None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this addition is necessary in order to get tests to pass, then this is fine.
But, if tests pass without the service, then please remove it. It's best to keep the test runtime as simple as possible. For example, there's not even a
userservice in this runtime.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, without this injection tests are failing.
FAILED lms/djangoapps/courseware/tests/test_video_mongo.py::VideoBlockTest::test_get_context - xblock.exceptions.NoSuchServiceError: Service 'video_config' is not available.Detailed logs