AA-226: Adding Authentication classes to endpoints for mobile use

The class BearerAuthenticationAllowInactiveUser is needed for the
mobile app to authenticate. The other Auth classes are to support
the standard work flows.
This commit is contained in:
Dillon Dumesnil
2020-07-08 10:06:58 -07:00
parent df3f8d4344
commit f0b4c75289
4 changed files with 24 additions and 4 deletions

View File

@@ -29,3 +29,8 @@ class ResetCourseDeadlinesViewTests(BaseCourseHomeTests):
reverse('course-experience-reset-course-deadlines'), {'course_key': self.course.id, 'invalid': 'value'}
)
self.assertEqual(response.status_code, 400)
def test_post_unauthenticated_user(self):
self.client.logout()
response = self.client.post(reverse('course-experience-reset-course-deadlines'), {'course_key': self.course.id})
self.assertEqual(response.status_code, 401)

View File

@@ -1,9 +1,13 @@
from rest_framework.decorators import api_view, permission_classes
from rest_framework.decorators import api_view, authentication_classes, permission_classes
from rest_framework.exceptions import APIException, ParseError
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser
from openedx.core.djangoapps.schedules.utils import reset_self_paced_schedule
from openedx.core.lib.api.authentication import BearerAuthenticationAllowInactiveUser
class UnableToResetDeadlines(APIException):
@@ -12,8 +16,11 @@ class UnableToResetDeadlines(APIException):
default_code = 'unable_to_reset_deadlines'
@permission_classes((IsAuthenticated,))
@api_view(['POST'])
@authentication_classes((
JwtAuthentication, BearerAuthenticationAllowInactiveUser, SessionAuthenticationAllowInactiveUser,
))
@permission_classes((IsAuthenticated,))
def reset_course_deadlines(request):
course_key = request.data.get('course_key', None)