Merge pull request #37004 from djoseph-apphelix/djoseph-2u/TNL-12056-Add-swagger-details-for-new-endpoints-from-several-in-progress-tickets

feature: Added disable/enable discussion endpoint to swagger
This commit is contained in:
Devasia Joseph
2025-07-11 14:12:07 +05:30
committed by GitHub
2 changed files with 44 additions and 11 deletions

View File

@@ -22,6 +22,7 @@ from django.urls import reverse
from django.utils.translation import gettext as _
from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.decorators.http import require_GET, require_http_methods
from drf_spectacular.utils import extend_schema, OpenApiParameter, OpenApiRequest, OpenApiResponse
from edx_django_utils.monitoring import function_trace
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey
@@ -1712,6 +1713,37 @@ def group_configurations_detail_handler(request, course_key_string, group_config
)
@extend_schema(
summary="Bulk enable/disable discussions for all units in a course.",
description="Enable or disable discussions for all verticals in the specified course.",
request=OpenApiRequest(
request={
"type": "object",
"properties": {"discussion_enabled": {"type": "boolean"}},
"required": ["discussion_enabled"],
}
),
responses={
200: OpenApiResponse(
response={
"type": "object",
"properties": {"units_updated_and_republished": {"type": "integer"}},
}
),
400: OpenApiResponse(description="Bad request"),
403: OpenApiResponse(description="Permission denied"),
},
methods=["PUT"],
parameters=[
OpenApiParameter(
name="course_key_string",
description="Course key string",
required=True,
type=str,
location=OpenApiParameter.PATH,
)
],
)
@api_view(['PUT'])
@view_auth_classes()
@expect_json

View File

@@ -1,4 +1,6 @@
""" Helper functions for drf-spectacular """
"""Helper functions for drf-spectacular"""
import re
def cms_api_filter(endpoints):
@@ -7,16 +9,15 @@ def cms_api_filter(endpoints):
Filter out endpoints that are not part of the CMS API.
"""
filtered = []
for (path, path_regex, method, callback) in endpoints:
# Add only paths to the list that are part of the CMS API
if (
# Don't just replace this with /v1 when switching to a later version of the CMS API.
# That would include some unintended endpoints.
path.startswith("/api/contentstore/v0/xblock") or
path.startswith("/api/contentstore/v0/videos") or
path.startswith("/api/contentstore/v0/video_transcripts") or
path.startswith("/api/contentstore/v0/file_assets") or
path.startswith("/api/contentstore/v0/youtube_transcripts")
CMS_PATH_PATTERN = re.compile(
r"^/api/contentstore/v0/(xblock|videos|video_transcripts|file_assets|youtube_transcripts)"
)
for path, path_regex, method, callback in endpoints:
if CMS_PATH_PATTERN.match(path) or (
path.startswith("/api/courses/")
and "bulk_enable_disable_discussions" in path
):
filtered.append((path, path_regex, method, callback))
return filtered