Commit af976a0e by Matthew Piatetsky

Add JWT auth and hidden flag to course_api

parent 0016d1af
......@@ -72,10 +72,19 @@ class CourseSerializer(serializers.Serializer): # pylint: disable=abstract-meth
start_type = serializers.CharField()
pacing = serializers.CharField()
mobile_available = serializers.BooleanField()
hidden = serializers.SerializerMethodField()
# 'course_id' is a deprecated field, please use 'id' instead.
course_id = serializers.CharField(source='id', read_only=True)
def get_hidden(self, course_overview):
"""
Get the representation for SerializerMethodField `hidden`
Represents whether course is hidden in LMS
"""
catalog_visibility = course_overview.catalog_visibility
return catalog_visibility in ['about', 'none']
def get_blocks_url(self, course_overview):
"""
Get the representation for SerializerMethodField `blocks_url`
......
......@@ -68,6 +68,7 @@ class TestCourseSerializer(CourseApiFactoryMixin, ModuleStoreTestCase):
'effort': u'6 hours',
'pacing': 'instructor',
'mobile_available': False,
'hidden': False,
# 'course_id' is a deprecated field, please use 'id' instead.
'course_id': u'edX/toy/2012_Fall',
......@@ -97,6 +98,15 @@ class TestCourseSerializer(CourseApiFactoryMixin, ModuleStoreTestCase):
result = self._get_result(course)
self.assertDictEqual(result, self.expected_data)
def test_hidden(self):
course = self.create_course(
course=u'custom',
start=datetime(2015, 3, 15),
catalog_visibility=u'none'
)
result = self._get_result(course)
self.assertEqual(result['hidden'], True)
def test_advertised_start(self):
course = self.create_course(
course=u'custom',
......
......@@ -13,6 +13,7 @@ from rest_framework.response import Response
from rest_framework.mixins import RetrieveModelMixin, UpdateModelMixin
from rest_framework.generics import GenericAPIView
from edx_rest_framework_extensions.authentication import JwtAuthentication
from openedx.core.lib.api.authentication import (
SessionAuthenticationAllowInactiveUser,
OAuth2AuthenticationAllowInactiveUser,
......@@ -93,6 +94,7 @@ def view_auth_classes(is_user=False, is_authenticated=True):
If is_user is True, also requires username in URL matches the request user.
"""
func_or_class.authentication_classes = (
JwtAuthentication,
OAuth2AuthenticationAllowInactiveUser,
SessionAuthenticationAllowInactiveUser
)
......
......@@ -41,7 +41,7 @@ django==1.8.16
djangorestframework-jwt==1.8.0
djangorestframework-oauth==1.1.0
edx-ccx-keys==0.2.1
edx-drf-extensions==0.5.1
edx-drf-extensions==1.2.1
edx-lint==0.4.3
edx-django-oauth2-provider==1.1.4
edx-django-sites-extensions==2.1.1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment