diff --git a/cms/djangoapps/contentstore/rest_api/v1/urls.py b/cms/djangoapps/contentstore/rest_api/v1/urls.py index ed1e4d63e1..13fec10ddc 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/urls.py +++ b/cms/djangoapps/contentstore/rest_api/v1/urls.py @@ -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" + ), ] diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/__init__.py b/cms/djangoapps/contentstore/rest_api/v1/views/__init__.py index 0e584debaa..044e4653e0 100644 --- a/cms/djangoapps/contentstore/rest_api/v1/views/__init__.py +++ b/cms/djangoapps/contentstore/rest_api/v1/views/__init__.py @@ -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 diff --git a/cms/djangoapps/contentstore/rest_api/v1/views/help_urls.py b/cms/djangoapps/contentstore/rest_api/v1/views/help_urls.py new file mode 100644 index 0000000000..09798485a3 --- /dev/null +++ b/cms/djangoapps/contentstore/rest_api/v1/views/help_urls.py @@ -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) diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index 198a48b488..321b97be6f 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -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.