Add "visible_to_staff_only" field to support staff locking in Studio.
STUD-1875
This commit is contained in:
@@ -200,33 +200,27 @@ class XBlockVisibilityTestCase(TestCase):
|
||||
|
||||
def test_private_unreleased_xblock(self):
|
||||
"""Verifies that a private unreleased xblock is not visible"""
|
||||
vertical = self._create_xblock_with_start_date('private_unreleased', self.future)
|
||||
self.assertFalse(utils.is_xblock_visible_to_students(vertical))
|
||||
self._test_visible_to_students(False, 'private_unreleased', self.future)
|
||||
|
||||
def test_private_released_xblock(self):
|
||||
"""Verifies that a private released xblock is not visible"""
|
||||
vertical = self._create_xblock_with_start_date('private_released', self.past)
|
||||
self.assertFalse(utils.is_xblock_visible_to_students(vertical))
|
||||
self._test_visible_to_students(False, 'private_released', self.past)
|
||||
|
||||
def test_public_unreleased_xblock(self):
|
||||
"""Verifies that a public (published) unreleased xblock is not visible"""
|
||||
vertical = self._create_xblock_with_start_date('public_unreleased', self.future, publish=True)
|
||||
self.assertFalse(utils.is_xblock_visible_to_students(vertical))
|
||||
self._test_visible_to_students(False, 'public_unreleased', self.future, publish=True)
|
||||
|
||||
def test_public_released_xblock(self):
|
||||
"""Verifies that public (published) released xblock is visible"""
|
||||
vertical = self._create_xblock_with_start_date('public_released', self.past, publish=True)
|
||||
self.assertTrue(utils.is_xblock_visible_to_students(vertical))
|
||||
"""Verifies that public (published) released xblock is visible if staff lock is not enabled."""
|
||||
self._test_visible_to_students(True, 'public_released', self.past, publish=True)
|
||||
|
||||
def test_private_no_start_xblock(self):
|
||||
"""Verifies that a private xblock with no start date is not visible"""
|
||||
vertical = self._create_xblock_with_start_date('private_no_start', None)
|
||||
self.assertFalse(utils.is_xblock_visible_to_students(vertical))
|
||||
self._test_visible_to_students(False, 'private_no_start', None)
|
||||
|
||||
def test_public_no_start_xblock(self):
|
||||
"""Verifies that a public (published) xblock with no start date is visible"""
|
||||
vertical = self._create_xblock_with_start_date('public_no_start', None, publish=True)
|
||||
self.assertTrue(utils.is_xblock_visible_to_students(vertical))
|
||||
"""Verifies that a public (published) xblock with no start date is visible unless staff lock is enabled"""
|
||||
self._test_visible_to_students(True, 'public_no_start', None, publish=True)
|
||||
|
||||
def test_draft_released_xblock(self):
|
||||
"""Verifies that a xblock with an unreleased draft and a released published version is visible"""
|
||||
@@ -238,12 +232,28 @@ class XBlockVisibilityTestCase(TestCase):
|
||||
|
||||
self.assertTrue(utils.is_xblock_visible_to_students(vertical))
|
||||
|
||||
def _create_xblock_with_start_date(self, name, start_date, publish=False):
|
||||
def _test_visible_to_students(self, expected_visible_without_lock, name, start_date, publish=False):
|
||||
"""
|
||||
Helper method that checks that is_xblock_visible_to_students returns the correct value both
|
||||
with and without visible_to_staff_only set.
|
||||
"""
|
||||
no_staff_lock = self._create_xblock_with_start_date(name, start_date, publish, visible_to_staff_only=False)
|
||||
self.assertEqual(expected_visible_without_lock, utils.is_xblock_visible_to_students(no_staff_lock))
|
||||
|
||||
# any xblock with visible_to_staff_only set to True should not be visible to students.
|
||||
staff_lock = self._create_xblock_with_start_date(
|
||||
name + "_locked", start_date, publish, visible_to_staff_only=True
|
||||
)
|
||||
self.assertFalse(utils.is_xblock_visible_to_students(staff_lock))
|
||||
|
||||
def _create_xblock_with_start_date(self, name, start_date, publish=False, visible_to_staff_only=False):
|
||||
"""Helper to create an xblock with a start date, optionally publishing it"""
|
||||
location = Location('edX', 'visibility', '2012_Fall', 'vertical', name)
|
||||
|
||||
vertical = modulestore().create_xmodule(location)
|
||||
vertical.start = start_date
|
||||
if visible_to_staff_only:
|
||||
vertical.visible_to_staff_only = visible_to_staff_only
|
||||
modulestore().update_item(vertical, self.dummy_user, allow_not_found=True)
|
||||
|
||||
if publish:
|
||||
|
||||
@@ -139,6 +139,10 @@ def is_xblock_visible_to_students(xblock):
|
||||
except ItemNotFoundError:
|
||||
return False
|
||||
|
||||
# If visible_to_staff_only is True, this xblock is not visible to students regardless of start date.
|
||||
if published.visible_to_staff_only:
|
||||
return False
|
||||
|
||||
# Check start date
|
||||
if 'detached' not in published._class_tags and published.start is not None:
|
||||
return datetime.now(UTC) > published.start
|
||||
|
||||
@@ -26,6 +26,7 @@ class CourseMetadata(object):
|
||||
'name', # from xblock
|
||||
'tags', # from xblock
|
||||
'video_speed_optimizations',
|
||||
'visible_to_staff_only'
|
||||
]
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user