Skip to content

Commit

Permalink
feat: TNL-11173 Authoring API is v0 for now (#33644)
Browse files Browse the repository at this point in the history
* feat: TNL-11173 authoring API offered as v0, not v1

* docs: correct swaggerfile for authoring api

---------

Co-authored-by: Bernard Szabo <[email protected]>
Co-authored-by: Jesper Hodge <[email protected]>
  • Loading branch information
3 people authored Nov 3, 2023
1 parent ddabba4 commit 5d6e925
Show file tree
Hide file tree
Showing 25 changed files with 277 additions and 237 deletions.
4 changes: 4 additions & 0 deletions cms/djangoapps/contentstore/rest_api/serializers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"""
Serializers for all contentstore API versions
"""
from .common import StrictSerializer
12 changes: 12 additions & 0 deletions cms/djangoapps/contentstore/rest_api/v0/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""
Views for v0 contentstore API.
"""

from cms.djangoapps.contentstore.rest_api.v0.views.assets import (
AssetsCreateRetrieveView,
AssetsUpdateDestroyView
)
from cms.djangoapps.contentstore.rest_api.v0.views.xblock import (
XblockView,
XblockCreateView
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
Serializers for v0 contentstore API.
"""
from .advanced_settings import AdvancedSettingsFieldSerializer, CourseAdvancedSettingsSerializer
from .assets import AssetSerializer
from .tabs import CourseTabSerializer, CourseTabUpdateSerializer, TabIDLocatorSerializer
from .transcripts import TranscriptSerializer
from .xblock import XblockSerializer
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
API Serializers for assets
"""
from rest_framework import serializers
from .common import StrictSerializer
from cms.djangoapps.contentstore.rest_api.serializers.common import StrictSerializer


class AssetSerializer(StrictSerializer):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
API Serializers for transcripts
"""
from rest_framework import serializers
from .common import StrictSerializer
from cms.djangoapps.contentstore.rest_api.serializers.common import StrictSerializer


class TranscriptSerializer(StrictSerializer):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
API Serializers for xblocks
"""
from rest_framework import serializers
from .common import StrictSerializer
from cms.djangoapps.contentstore.rest_api.serializers.common import StrictSerializer

# The XblockSerializer is designed to be scalable and generic. As such, its structure
# should remain as general as possible. Avoid indiscriminately adding fields to it,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
ASSET_KEY_STRING = "asset-v1:dede+aba+weagi+type@asset+block@_0e37192a-42c4-441e-a3e1-8e40ec304e2e.jpg"
mock_image = MagicMock(file=File)
mock_image.name = "test.jpg"
VERSION = "v0"


class AssetsViewTestCase(AuthorizeStaffTestCase):
Expand All @@ -44,15 +45,15 @@ def get_url_params(self):

def get_url(self, _course_id=None):
return reverse(
"cms.djangoapps.contentstore:v1:cms_api_update_destroy_assets",
f"cms.djangoapps.contentstore:{VERSION}:cms_api_update_destroy_assets",
kwargs=self.get_url_params(),
)

def send_request(self, _url, _data):
raise NotImplementedError("send_request must be implemented by subclasses")

@patch(
"cms.djangoapps.contentstore.rest_api.v1.views.assets.handle_assets",
f"cms.djangoapps.contentstore.rest_api.{VERSION}.views.assets.handle_assets",
return_value=JsonResponse(
{
"locator": ASSET_KEY_STRING,
Expand All @@ -61,7 +62,7 @@ def send_request(self, _url, _data):
),
)
@patch(
"cms.djangoapps.contentstore.rest_api.v1.views.xblock.toggles.use_studio_content_api",
f"cms.djangoapps.contentstore.rest_api.{VERSION}.views.xblock.toggles.use_studio_content_api",
return_value=True,
)
def make_request(
Expand Down Expand Up @@ -104,7 +105,7 @@ def get_url_params(self):

def get_url(self, _course_id=None):
return reverse(
"cms.djangoapps.contentstore:v1:cms_api_create_retrieve_assets",
f"cms.djangoapps.contentstore:{VERSION}:cms_api_create_retrieve_assets",
kwargs=self.get_url_params(),
)

Expand Down Expand Up @@ -156,7 +157,7 @@ def get_url_params(self):

def get_url(self, _course_id=None):
return reverse(
"cms.djangoapps.contentstore:v1:cms_api_create_retrieve_assets",
f"cms.djangoapps.contentstore:{VERSION}:cms_api_create_retrieve_assets",
kwargs=self.get_url_params(),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@


TEST_LOCATOR = "block-v1:dede+aba+weagi+type@problem+block@ba6327f840da49289fb27a9243913478"
VERSION = "v0"


class XBlockViewTestCase(AuthorizeStaffTestCase):
Expand All @@ -38,15 +39,15 @@ def get_url_params(self):

def get_url(self, _course_id=None):
return reverse(
"cms.djangoapps.contentstore:v1:cms_api_xblock",
f"cms.djangoapps.contentstore:{VERSION}:cms_api_xblock",
kwargs=self.get_url_params(),
)

def send_request(self, _url, _data):
raise NotImplementedError("send_request must be implemented by subclasses")

@patch(
"cms.djangoapps.contentstore.rest_api.v1.views.xblock.handle_xblock",
f"cms.djangoapps.contentstore.rest_api.{VERSION}.views.xblock.handle_xblock",
return_value=JsonResponse(
{
"locator": TEST_LOCATOR,
Expand All @@ -55,7 +56,7 @@ def send_request(self, _url, _data):
),
)
@patch(
"cms.djangoapps.contentstore.rest_api.v1.views.xblock.toggles.use_studio_content_api",
f"cms.djangoapps.contentstore.rest_api.{VERSION}.views.xblock.toggles.use_studio_content_api",
return_value=True,
)
def make_request(
Expand Down Expand Up @@ -134,13 +135,14 @@ class XBlockViewPostTest(XBlockViewTestCase, ModuleStoreTestCase, APITestCase):
"""
Test POST operation on xblocks - Create a new xblock for a parent xblock
"""
VERSION = "v0"

def get_url_params(self):
return {"course_id": self.get_course_key_string()}

def get_url(self, _course_id=None):
return reverse(
"cms.djangoapps.contentstore:v1:cms_api_create_xblock",
f"cms.djangoapps.contentstore:{VERSION}:cms_api_create_xblock",
kwargs=self.get_url_params(),
)

Expand Down
52 changes: 51 additions & 1 deletion cms/djangoapps/contentstore/rest_api/v0/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
""" Contenstore API v0 URLs. """

from django.urls import re_path
from django.conf import settings
from django.urls import re_path, path

from openedx.core.constants import COURSE_ID_PATTERN

from .views import AdvancedCourseSettingsView, CourseTabSettingsView, CourseTabListView, CourseTabReorderView
from .views import assets
from .views import transcripts
from .views import authoring_videos
from .views import xblock

app_name = "v0"

VIDEO_ID_PATTERN = r'(?P<edx_video_id>[-\w]+)'

urlpatterns = [
re_path(
fr"^advanced_settings/{COURSE_ID_PATTERN}$",
Expand All @@ -28,4 +36,46 @@
CourseTabReorderView.as_view(),
name="course_tab_reorder",
),

# Authoring API
re_path(
fr'^file_assets/{settings.COURSE_ID_PATTERN}/$',
assets.AssetsCreateRetrieveView.as_view(), name='cms_api_create_retrieve_assets'
),
re_path(
fr'^file_assets/{settings.COURSE_ID_PATTERN}/{settings.ASSET_KEY_PATTERN}$',
assets.AssetsUpdateDestroyView.as_view(), name='cms_api_update_destroy_assets'
),
re_path(
fr'^videos/encodings/{settings.COURSE_ID_PATTERN}$',
authoring_videos.VideoEncodingsDownloadView.as_view(), name='cms_api_videos_encodings'
),
path(
'videos/features/',
authoring_videos.VideoFeaturesView.as_view(), name='cms_api_videos_features'
),
re_path(
fr'^videos/images/{settings.COURSE_ID_PATTERN}/{VIDEO_ID_PATTERN}$',
authoring_videos.VideoImagesView.as_view(), name='cms_api_videos_images'
),
re_path(
fr'^videos/uploads/{settings.COURSE_ID_PATTERN}/$',
authoring_videos.VideosCreateUploadView.as_view(), name='cms_api_create_videos_upload'
),
re_path(
fr'^videos/uploads/{settings.COURSE_ID_PATTERN}/{VIDEO_ID_PATTERN}$',
authoring_videos.VideosUploadsView.as_view(), name='cms_api_videos_uploads'
),
re_path(
fr'^video_transcripts/{settings.COURSE_ID_PATTERN}$',
transcripts.TranscriptView.as_view(), name='cms_api_video_transcripts'
),
re_path(
fr'^xblock/{settings.COURSE_ID_PATTERN}/$',
xblock.XblockCreateView.as_view(), name='cms_api_create_xblock'
),
re_path(
fr'^xblock/{settings.COURSE_ID_PATTERN}/{settings.USAGE_KEY_PATTERN}$',
xblock.XblockView.as_view(), name='cms_api_xblock'
),
]
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes
from common.djangoapps.util.json_request import expect_json_in_class_view

from ....api import course_author_access_required
from cms.djangoapps.contentstore.api import course_author_access_required

from cms.djangoapps.contentstore.asset_storage_handlers import handle_assets
import cms.djangoapps.contentstore.toggles as contentstore_toggles

from cms.djangoapps.contentstore.rest_api.v1.serializers import AssetSerializer
from ..serializers.assets import AssetSerializer
from .utils import validate_request_with_serializer
from rest_framework.parsers import (MultiPartParser, FormParser, JSONParser)
from openedx.core.lib.api.parsers import TypedFileUploadParser
Expand Down
Loading

0 comments on commit 5d6e925

Please sign in to comment.