feat: add api for help tokens (#33073)
This commit is contained in:
@@ -17,6 +17,7 @@ from .views import (
|
||||
assets,
|
||||
videos,
|
||||
transcripts,
|
||||
HelpUrlsView,
|
||||
)
|
||||
|
||||
app_name = 'v1'
|
||||
@@ -86,4 +87,9 @@ urlpatterns = [
|
||||
fr'^video_transcripts/{settings.COURSE_ID_PATTERN}$',
|
||||
transcripts.TranscriptView.as_view(), name='studio_content_video_transcripts'
|
||||
),
|
||||
path(
|
||||
'help_urls',
|
||||
HelpUrlsView.as_view(),
|
||||
name="help_urls"
|
||||
),
|
||||
]
|
||||
|
||||
@@ -9,3 +9,4 @@ from .settings import CourseSettingsView
|
||||
from .xblock import XblockView
|
||||
from .assets import AssetsView
|
||||
from .videos import VideosView
|
||||
from .help_urls import HelpUrlsView
|
||||
|
||||
44
cms/djangoapps/contentstore/rest_api/v1/views/help_urls.py
Normal file
44
cms/djangoapps/contentstore/rest_api/v1/views/help_urls.py
Normal file
@@ -0,0 +1,44 @@
|
||||
""" API Views for help tokens """
|
||||
|
||||
from rest_framework.request import Request
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
from openedx.core.lib.api.view_utils import view_auth_classes
|
||||
|
||||
from ....utils import get_help_urls
|
||||
|
||||
|
||||
@view_auth_classes(is_authenticated=True)
|
||||
class HelpUrlsView(APIView):
|
||||
"""
|
||||
View for getting all help urls.
|
||||
"""
|
||||
def get(self, request: Request):
|
||||
"""
|
||||
Get an help url.
|
||||
|
||||
**Example Request**
|
||||
|
||||
GET /api/contentstore/v1/help_urls
|
||||
|
||||
**Response Values**
|
||||
|
||||
If the request is successful, an HTTP 200 "OK" response is returned.
|
||||
|
||||
The HTTP 200 response contains a single dict that contains keys for
|
||||
pages and locales
|
||||
|
||||
**Example Response**
|
||||
|
||||
```json
|
||||
{
|
||||
"default": "http://edx.readthedocs.io/projects/.../index.html",
|
||||
"home": "http://edx.readthedocs.io/projects/.../CA_get_started_Studio.html",
|
||||
"develop_course": "http://edx.readthedocs.io/projects/.../developing_course/index.html",
|
||||
...
|
||||
}
|
||||
```
|
||||
"""
|
||||
|
||||
data = get_help_urls()
|
||||
return Response(data)
|
||||
@@ -1,9 +1,9 @@
|
||||
"""
|
||||
Common utility functions useful throughout the contentstore
|
||||
"""
|
||||
|
||||
from collections import defaultdict
|
||||
import configparser
|
||||
import logging
|
||||
from collections import defaultdict
|
||||
from contextlib import contextmanager
|
||||
from datetime import datetime, timezone
|
||||
from uuid import uuid4
|
||||
@@ -13,6 +13,7 @@ from django.core.exceptions import ValidationError
|
||||
from django.urls import reverse
|
||||
from django.utils import translation
|
||||
from django.utils.translation import gettext as _
|
||||
from help_tokens.core import HelpUrlExpert
|
||||
from lti_consumer.models import CourseAllowPIISharingInLTIFlag
|
||||
from opaque_keys.edx.keys import CourseKey, UsageKey
|
||||
from opaque_keys.edx.locator import LibraryLocator
|
||||
@@ -1374,6 +1375,18 @@ def get_course_grading(course_key):
|
||||
return grading_context
|
||||
|
||||
|
||||
def get_help_urls():
|
||||
"""
|
||||
Utils is used to get help tokens urls.
|
||||
"""
|
||||
ini = HelpUrlExpert.the_one()
|
||||
ini.config = configparser.ConfigParser()
|
||||
ini.config.read(ini.ini_file_name)
|
||||
tokens = list(ini.config['pages'].keys())
|
||||
help_tokens = {token: HelpUrlExpert.the_one().url_for_token(token) for token in tokens}
|
||||
return help_tokens
|
||||
|
||||
|
||||
class StudioPermissionsService:
|
||||
"""
|
||||
Service that can provide information about a user's permissions.
|
||||
|
||||
Reference in New Issue
Block a user