Skip to content

Commit

Permalink
feat: add api for help tokens (openedx#33073)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruzniaievdm authored Aug 23, 2023
1 parent 6eba79a commit b84d454
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
6 changes: 6 additions & 0 deletions cms/djangoapps/contentstore/rest_api/v1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
assets,
videos,
transcripts,
HelpUrlsView,
)

app_name = 'v1'
Expand Down Expand Up @@ -86,4 +87,9 @@
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"
),
]
1 change: 1 addition & 0 deletions cms/djangoapps/contentstore/rest_api/v1/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
from .xblock import XblockView
from .assets import AssetsView
from .videos import VideosView
from .help_urls import HelpUrlsView
44 changes: 44 additions & 0 deletions cms/djangoapps/contentstore/rest_api/v1/views/help_urls.py
Original file line number Diff line number Diff line change
@@ -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)
17 changes: 15 additions & 2 deletions cms/djangoapps/contentstore/utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -13,6 +13,7 @@
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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit b84d454

Please sign in to comment.