feat: fix authentication classes for recommendation view (#30699)

- Updated classes to allow inactive users to access the view
- In case of any error show general recommendations
This commit is contained in:
Zainab Amir
2022-07-06 17:32:20 +05:00
committed by GitHub
parent 7a1d263477
commit 9a21d1448a
2 changed files with 11 additions and 7 deletions

View File

@@ -1,6 +1,7 @@
""" API v0 views. """
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser
from enterprise.models import EnterpriseCourseEnrollment
from rest_framework.authentication import SessionAuthentication
from rest_framework.permissions import IsAuthenticated
@@ -347,7 +348,7 @@ class CourseRecommendationApiView(APIView):
GET api/dashboard/v0/recommendation/courses/
"""
authentication_classes = (JwtAuthentication, SessionAuthentication,)
authentication_classes = (JwtAuthentication, SessionAuthenticationAllowInactiveUser,)
permission_classes = (IsAuthenticated,)
def get(self, request):
@@ -379,4 +380,5 @@ class CourseRecommendationApiView(APIView):
})
else:
return Response(status=400)
return Response({'courses': recommended_courses, 'is_personalized_recommendation': not is_control}, status=200)

View File

@@ -37,13 +37,15 @@ class RecommendationsPanel extends React.Component {
getCourseList = async () => {
const coursesRecommendationData = await fetch(`${this.props.lmsRootUrl}/api/dashboard/v0/recommendation/courses/`)
.then(response => {
if (response.status === 400) {
return this.props.generalRecommendations;
} else {
return response.json();
}
if (response.status === 400) {
return this.props.generalRecommendations;
} else {
return response.json();
}
);
}).catch(() => {
return this.props.generalRecommendations;
});
this.setState({
coursesList: coursesRecommendationData['courses'],
isPersonalizedRecommendation: coursesRecommendationData['is_personalized_recommendation']