Add gated content banner for staff in lms

This commit is contained in:
Kevin Kim
2016-07-11 20:32:48 +00:00
parent 1809f88dd8
commit a39d6c2e94
9 changed files with 135 additions and 28 deletions

View File

@@ -4,6 +4,7 @@ API for the gating djangoapp
import logging
from django.utils.translation import ugettext as _
from lms.djangoapps.courseware.access import _has_access_to_course
from milestones import api as milestones_api
from opaque_keys.edx.keys import UsageKey
from xmodule.modulestore.django import modulestore
@@ -285,12 +286,15 @@ def get_gated_content(course, user):
Returns:
list: The list of gated content usage keys for the given course
"""
# Get the unfulfilled gating milestones for this course, for this user
return [
m['content_id'] for m in find_gating_milestones(
course.id,
None,
'requires',
{'id': user.id}
)
]
if _has_access_to_course(user, 'staff', course.id):
return []
else:
# Get the unfulfilled gating milestones for this course, for this user
return [
m['content_id'] for m in find_gating_milestones(
course.id,
None,
'requires',
{'id': user.id}
)
]

View File

@@ -10,6 +10,7 @@ from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase, TEST_DAT
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
from openedx.core.lib.gating import api as gating_api
from openedx.core.lib.gating.exceptions import GatingValidationError
from student.tests.factories import UserFactory
@attr('shard_2')
@@ -154,19 +155,23 @@ class TestGatingApi(ModuleStoreTestCase, MilestonesTestCaseMixin):
self.assertIsNone(min_score)
def test_get_gated_content(self):
""" Test test_get_gated_content """
"""
Verify staff bypasses gated content and student gets list of unfulfilled prerequisites.
"""
mock_user = MagicMock()
mock_user.id.return_value = 1
staff = UserFactory(is_staff=True)
student = UserFactory(is_staff=False)
self.assertEqual(gating_api.get_gated_content(self.course, mock_user), [])
self.assertEqual(gating_api.get_gated_content(self.course, staff), [])
self.assertEqual(gating_api.get_gated_content(self.course, student), [])
gating_api.add_prerequisite(self.course.id, self.seq1.location)
gating_api.set_required_content(self.course.id, self.seq2.location, self.seq1.location, 100)
milestone = milestones_api.get_course_content_milestones(self.course.id, self.seq2.location, 'requires')[0]
self.assertEqual(gating_api.get_gated_content(self.course, mock_user), [unicode(self.seq2.location)])
self.assertEqual(gating_api.get_gated_content(self.course, staff), [])
self.assertEqual(gating_api.get_gated_content(self.course, student), [unicode(self.seq2.location)])
milestones_api.add_user_milestone({'id': mock_user.id}, milestone)
milestones_api.add_user_milestone({'id': student.id}, milestone) # pylint: disable=no-member
self.assertEqual(gating_api.get_gated_content(self.course, mock_user), [])
self.assertEqual(gating_api.get_gated_content(self.course, student), [])