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:
@@ -7,7 +7,8 @@ from django.conf import settings
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from opaque_keys import InvalidKeyError
|
||||
from opaque_keys.edx.keys import CourseKey, UsageKey
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
|
||||
from xmodule.modulestore.django import modulestore
|
||||
|
||||
NAMESPACE_CHOICES = {
|
||||
@@ -26,7 +27,7 @@ def add_prerequisite_course(course_key, prerequisite_course_key):
|
||||
"""
|
||||
It would create a milestone, then it would set newly created
|
||||
milestones as requirement for course referred by `course_key`
|
||||
and it would set newly created milestone as fulfilment
|
||||
and it would set newly created milestone as fulfillment
|
||||
milestone for course referred by `prerequisite_course_key`.
|
||||
"""
|
||||
if not settings.FEATURES.get('ENABLE_PREREQUISITE_COURSES', False):
|
||||
@@ -313,6 +314,15 @@ def remove_content_references(content_id):
|
||||
return milestones_api.remove_content_references(content_id)
|
||||
|
||||
|
||||
def any_unfulfilled_milestones(course_id, user_id):
|
||||
""" Returns a boolean if user has any unfulfilled milestones """
|
||||
if not settings.FEATURES.get('MILESTONES_APP', False):
|
||||
return False
|
||||
return bool(
|
||||
get_course_milestones_fulfillment_paths(course_id, {"id": user_id})
|
||||
)
|
||||
|
||||
|
||||
def get_course_milestones_fulfillment_paths(course_id, user_id):
|
||||
"""
|
||||
Client API operation adapter/wrapper
|
||||
|
||||
@@ -3,6 +3,8 @@ Tests for the milestones helpers library, which is the integration point for the
|
||||
"""
|
||||
|
||||
from mock import patch
|
||||
|
||||
from milestones.exceptions import InvalidCourseKeyException, InvalidUserException
|
||||
from util import milestones_helpers
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
@@ -85,3 +87,11 @@ class MilestonesHelpersTestCase(ModuleStoreTestCase):
|
||||
def test_add_user_milestone_returns_none_when_app_disabled(self):
|
||||
response = milestones_helpers.add_user_milestone(self.user, self.milestone)
|
||||
self.assertIsNone(response)
|
||||
|
||||
@patch.dict('django.conf.settings.FEATURES', {'MILESTONES_APP': True})
|
||||
def test_any_unfulfilled_milestones(self):
|
||||
""" Tests any_unfulfilled_milestones for invalid arguments """
|
||||
with self.assertRaises(InvalidCourseKeyException):
|
||||
milestones_helpers.any_unfulfilled_milestones(None, self.user)
|
||||
with self.assertRaises(InvalidUserException):
|
||||
milestones_helpers.any_unfulfilled_milestones(self.course.id, None)
|
||||
|
||||
Reference in New Issue
Block a user