Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
eab3d42
feat: publish full CMS schema paths and register path converters
Abdul-Muqadim-Arbisoft Oct 4, 2026
0ae573b
feat: add a v2 video usages endpoint to the authoring API
Abdul-Muqadim-Arbisoft Oct 4, 2026
f20db7b
feat: add a v2 video archives endpoint to the authoring API
Abdul-Muqadim-Arbisoft Oct 4, 2026
cd38a23
test: use the standard library UTC in the video archive tests
Abdul-Muqadim-Arbisoft Oct 4, 2026
df3842b
Merge branch 'master' into feat/api-adrs-video-management
Abdul-Muqadim-Arbisoft Oct 14, 2026
050c98e
test: follow master's schema hook and pin the viewset mount's actions
Abdul-Muqadim-Arbisoft Oct 14, 2026
ec62c3a
test: list the two video paths as superseded and read the new docs do…
Abdul-Muqadim-Arbisoft Oct 14, 2026
c13404a
fix: record that the two legacy video operations are now superseded
Abdul-Muqadim-Arbisoft Oct 14, 2026
1bfa8c6
Merge branch 'master' into feat/api-adrs-video-management
Abdul-Muqadim-Arbisoft Nov 2, 2026
10ed05c
refactor: move VideoDownloadThrottle out of the frozen v1 views
Abdul-Muqadim-Arbisoft Nov 2, 2026
a18bf7f
feat: refuse archive addresses outside the course in the request seri…
Abdul-Muqadim-Arbisoft Nov 2, 2026
5653d51
test: leave the legacy videos listing to its own successor
Abdul-Muqadim-Arbisoft Nov 2, 2026
653e1fc
refactor: drop the JSON fallback routes under the video collections
Abdul-Muqadim-Arbisoft Nov 2, 2026
e6d8c14
fix: align the video usage and archive views with their v2 neighbours
Abdul-Muqadim-Arbisoft Nov 2, 2026
0adc81f
test: cover the video usage and archive views under course-authoring …
Abdul-Muqadim-Arbisoft Nov 2, 2026
e6ee964
test: make the throttle wait assertion independent of run speed
Abdul-Muqadim-Arbisoft Nov 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cms/djangoapps/contentstore/rest_api/throttles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Throttles shared by more than one version of the contentstore REST API.
"""
from django.conf import settings
from rest_framework.throttling import UserRateThrottle


class VideoDownloadThrottle(UserRateThrottle):
"""
Per-user rate limit on the Studio video-download endpoint.

The download endpoint streams a multi-video zip into the response, which
keeps a uWSGI worker busy for the duration. Rate-limiting per user keeps
a single course author from initiating many overlapping streams.
"""
rate = settings.VIDEO_DOWNLOAD_RATE_LIMIT
14 changes: 1 addition & 13 deletions cms/djangoapps/contentstore/rest_api/v1/views/videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
"""
import logging

from django.conf import settings
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import OpenApiParameter, OpenApiResponse, extend_schema
from opaque_keys.edx.keys import CourseKey
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.throttling import UserRateThrottle
from rest_framework.views import APIView

import cms.djangoapps.contentstore.toggles as contentstore_toggles
from cms.djangoapps.contentstore.rest_api.throttles import VideoDownloadThrottle
from cms.djangoapps.contentstore.rest_api.v1.serializers import (
CourseVideosSerializer,
VideoDownloadSerializer,
Expand Down Expand Up @@ -183,17 +182,6 @@ def get(self, request: Request, course_id: str, edx_video_id: str):
return Response(serializer.data)


class VideoDownloadThrottle(UserRateThrottle):
"""
Per-user rate limit on the Studio video-download endpoint.

The download endpoint streams a multi-video zip into the response, which
keeps a uWSGI worker busy for the duration. Rate-limiting per user keeps
a single course author from initiating many overlapping streams.
"""
rate = settings.VIDEO_DOWNLOAD_RATE_LIMIT


@view_auth_classes(is_authenticated=True)
class VideoDownloadView(DeveloperErrorViewMixin, APIView):
"""
Expand Down
12 changes: 12 additions & 0 deletions cms/djangoapps/contentstore/rest_api/v2/authoring_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from django.urls import path

from cms.djangoapps.contentstore.rest_api.v2.views.textbooks import CourseTextbooksViewSet
from cms.djangoapps.contentstore.rest_api.v2.views.video_archives import CourseVideoArchiveView
from cms.djangoapps.contentstore.rest_api.v2.views.video_settings import CourseVideoSettingsViewSet
from cms.djangoapps.contentstore.rest_api.v2.views.video_usages import CourseVideoUsageViewSet

app_name = "authoring_v2"

Expand All @@ -18,4 +20,14 @@
CourseVideoSettingsViewSet.as_view({"get": "retrieve"}),
name="course_video_settings",
),
path(
"courses/<course_key:course_key>/video_usages/<str:edx_video_id>/",
CourseVideoUsageViewSet.as_view({"get": "retrieve"}),
name="course_video_usage_detail",
),
path(
"courses/<course_key:course_key>/video_archives/",
CourseVideoArchiveView.as_view(),
name="course_video_archive_list",
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Serializers for zip archives of a course's videos."""

from rest_framework import serializers

from cms.djangoapps.contentstore.video_storage_handlers import get_course_video_download_urls


class VideoArchiveFileSerializer(serializers.Serializer): # pylint: disable=abstract-method
"""One video to put in the archive."""

# Values are used exactly as sent: the URL is matched character for
# character against the course's video URLs, and the name becomes the entry
# name in the archive.
url = serializers.CharField(
trim_whitespace=False,
help_text=(
"Address of one of the course's encoded video files, exactly as the course's video "
"listing reports it. Any other address is refused."
),
)
name = serializers.CharField(
trim_whitespace=False,
allow_blank=True,
help_text=(
"File name of the video inside the archive. When it does not already end with the "
"extension of the video's content type, that extension is appended."
),
)


class VideoArchiveRequestSerializer(serializers.Serializer): # pylint: disable=abstract-method
"""
The videos to bundle into one archive.

Expects the parsed ``course_key`` of the course in its context.
"""

files = VideoArchiveFileSerializer(
many=True,
help_text="The videos to include, in archive order. An empty list gives an empty archive.",
)

def validate_files(self, files):
"""Refuse every address that is not one of the course's encoded-video URLs."""
if not files:
return files
allowed_urls = get_course_video_download_urls(str(self.context["course_key"]))
refused = [file["url"] for file in files if file["url"] not in allowed_urls]
if refused:
raise serializers.ValidationError([f"Invalid video download url: {url}" for url in refused])
return files
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Serializers for where a video is used in a course."""

from rest_framework import serializers


class VideoUsageLocationSerializer(serializers.Serializer): # pylint: disable=abstract-method
"""One video component of the course that plays the video."""

display_location = serializers.CharField(
help_text=(
"Where the component sits, as '<subsection> - <unit> / <component>' display names. "
"A subsection or unit with no display name set appears as 'None', and a component with "
"none as 'Video'. The subsection part is empty for a unit that is in no subsection."
),
)
url = serializers.CharField(
help_text=(
"Studio address of the unit holding the component, anchored at the component: "
"'/container/<unit usage key>#<component usage key>'."
),
)


class CourseVideoUsageSerializer(serializers.Serializer): # pylint: disable=abstract-method
"""The places in a course where one video is used."""

usage_locations = VideoUsageLocationSerializer(
many=True,
help_text=(
"One entry per video component that references the video, published or not. A "
"component with no parent in the course outline is left out. Empty when no component "
"is listed."
),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Service layer for the video usage and video archive resources of a course."""

from rest_framework.exceptions import NotFound

from cms.djangoapps.contentstore.video_storage_handlers import create_video_zip, get_video_usage_path
from cms.djangoapps.contentstore.views.permissions import COURSE_NOT_FOUND_MESSAGE
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview


def ensure_course_exists(course_key):
"""
Raise ``NotFound`` unless a course run exists under ``course_key``.

Only reads: the course overview table first, then the content store. The
overview row is never created here, so a read request writes nothing.
"""
if not CourseOverview.course_exists(course_key):
raise NotFound(COURSE_NOT_FOUND_MESSAGE)


def get_course_video_usages(course_key, edx_video_id):
"""
Return where the video ``edx_video_id`` is placed in the course.

The result is ``{"usage_locations": [{"display_location", "url"}, ...]}``,
one entry per video component that references the id, in content-store
order. Unpublished components are included; a component with no parent is
left out. An id that nothing references gives an empty list.
"""
ensure_course_exists(course_key)
return get_video_usage_path(course_key, edx_video_id)


def create_course_video_archive(course_key, files):
"""
Return a streaming zip response holding the requested videos of the course.

Every ``files[].url`` must be one of the course's own encoded-video URLs;
the request serializer refuses any other, and the helper checks again
before anything is fetched. The archive is assembled while it is sent and
is not stored.
"""
return create_video_zip(str(course_key), files)
Loading
Loading