MA-635 Block Mobile Content for unfulfilled milestones
Previously, the mobile api did not check for pre-requisite courses or entrance exams. This change checks for these milestones and then returns course content accordingly.
This commit is contained in:
@@ -3,16 +3,21 @@ Common utility methods and decorators for Mobile APIs.
|
||||
"""
|
||||
|
||||
import functools
|
||||
from rest_framework import permissions
|
||||
|
||||
from django.http import Http404
|
||||
|
||||
from rest_framework import permissions, status, response
|
||||
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from xmodule.modulestore.django import modulestore
|
||||
|
||||
from courseware.courses import get_course_with_access
|
||||
from openedx.core.lib.api.permissions import IsUserInUrl
|
||||
from openedx.core.lib.api.authentication import (
|
||||
SessionAuthenticationAllowInactiveUser,
|
||||
OAuth2AuthenticationAllowInactiveUser,
|
||||
)
|
||||
from openedx.core.lib.api.permissions import IsUserInUrl
|
||||
from util.milestones_helpers import any_unfulfilled_milestones
|
||||
from xmodule.modulestore.django import modulestore
|
||||
|
||||
|
||||
def mobile_course_access(depth=0, verify_enrolled=True):
|
||||
@@ -30,12 +35,25 @@ def mobile_course_access(depth=0, verify_enrolled=True):
|
||||
"""
|
||||
course_id = CourseKey.from_string(kwargs.pop('course_id'))
|
||||
with modulestore().bulk_operations(course_id):
|
||||
course = get_course_with_access(
|
||||
request.user,
|
||||
'load_mobile' if verify_enrolled else 'load_mobile_no_enrollment_check',
|
||||
course_id,
|
||||
depth=depth
|
||||
)
|
||||
try:
|
||||
course = get_course_with_access(
|
||||
request.user,
|
||||
'load_mobile' if verify_enrolled else 'load_mobile_no_enrollment_check',
|
||||
course_id,
|
||||
depth=depth
|
||||
)
|
||||
except Http404:
|
||||
# any_unfulfilled_milestones called a second time since get_course_with_access returns a bool
|
||||
if any_unfulfilled_milestones(course_id, request.user.id):
|
||||
message = {
|
||||
"developer_message": "Cannot access content with unfulfilled pre-requisites or unpassed entrance exam." # pylint: disable=line-too-long
|
||||
}
|
||||
return response.Response(
|
||||
data=message,
|
||||
status=status.HTTP_204_NO_CONTENT
|
||||
)
|
||||
else:
|
||||
raise
|
||||
return func(self, request, course=course, *args, **kwargs)
|
||||
return _wrapper
|
||||
return _decorator
|
||||
|
||||
Reference in New Issue
Block a user