Merge pull request #14863 from edx/christina/tnl-6746
Show messages about component visibility.
This commit is contained in:
@@ -391,8 +391,8 @@ class GroupVisibilityTest(CourseTestCase):
|
||||
def verify_all_components_visible_to_all(): # pylint: disable=invalid-name
|
||||
""" Verifies when group_access has not been set on anything. """
|
||||
for item in (self.sequential, self.vertical, self.html, self.problem):
|
||||
self.assertFalse(utils.has_children_visible_to_specific_content_groups(item))
|
||||
self.assertFalse(utils.is_visible_to_specific_content_groups(item))
|
||||
self.assertFalse(utils.has_children_visible_to_specific_partition_groups(item))
|
||||
self.assertFalse(utils.is_visible_to_specific_partition_groups(item))
|
||||
|
||||
verify_all_components_visible_to_all()
|
||||
|
||||
@@ -409,16 +409,16 @@ class GroupVisibilityTest(CourseTestCase):
|
||||
self.set_group_access(self.vertical, {1: []})
|
||||
self.set_group_access(self.problem, {2: [3, 4]})
|
||||
|
||||
# Note that "has_children_visible_to_specific_content_groups" only checks immediate children.
|
||||
self.assertFalse(utils.has_children_visible_to_specific_content_groups(self.sequential))
|
||||
self.assertTrue(utils.has_children_visible_to_specific_content_groups(self.vertical))
|
||||
self.assertFalse(utils.has_children_visible_to_specific_content_groups(self.html))
|
||||
self.assertFalse(utils.has_children_visible_to_specific_content_groups(self.problem))
|
||||
# Note that "has_children_visible_to_specific_partition_groups" only checks immediate children.
|
||||
self.assertFalse(utils.has_children_visible_to_specific_partition_groups(self.sequential))
|
||||
self.assertTrue(utils.has_children_visible_to_specific_partition_groups(self.vertical))
|
||||
self.assertFalse(utils.has_children_visible_to_specific_partition_groups(self.html))
|
||||
self.assertFalse(utils.has_children_visible_to_specific_partition_groups(self.problem))
|
||||
|
||||
self.assertTrue(utils.is_visible_to_specific_content_groups(self.sequential))
|
||||
self.assertFalse(utils.is_visible_to_specific_content_groups(self.vertical))
|
||||
self.assertFalse(utils.is_visible_to_specific_content_groups(self.html))
|
||||
self.assertTrue(utils.is_visible_to_specific_content_groups(self.problem))
|
||||
self.assertTrue(utils.is_visible_to_specific_partition_groups(self.sequential))
|
||||
self.assertFalse(utils.is_visible_to_specific_partition_groups(self.vertical))
|
||||
self.assertFalse(utils.is_visible_to_specific_partition_groups(self.html))
|
||||
self.assertTrue(utils.is_visible_to_specific_partition_groups(self.problem))
|
||||
|
||||
|
||||
class GetUserPartitionInfoTest(ModuleStoreTestCase):
|
||||
|
||||
@@ -163,24 +163,24 @@ def is_currently_visible_to_students(xblock):
|
||||
return True
|
||||
|
||||
|
||||
def has_children_visible_to_specific_content_groups(xblock):
|
||||
def has_children_visible_to_specific_partition_groups(xblock):
|
||||
"""
|
||||
Returns True if this xblock has children that are limited to specific content groups.
|
||||
Returns True if this xblock has children that are limited to specific user partition groups.
|
||||
Note that this method is not recursive (it does not check grandchildren).
|
||||
"""
|
||||
if not xblock.has_children:
|
||||
return False
|
||||
|
||||
for child in xblock.get_children():
|
||||
if is_visible_to_specific_content_groups(child):
|
||||
if is_visible_to_specific_partition_groups(child):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def is_visible_to_specific_content_groups(xblock):
|
||||
def is_visible_to_specific_partition_groups(xblock):
|
||||
"""
|
||||
Returns True if this xblock has visibility limited to specific content groups.
|
||||
Returns True if this xblock has visibility limited to specific user partition groups.
|
||||
"""
|
||||
if not xblock.group_access:
|
||||
return False
|
||||
|
||||
@@ -28,7 +28,7 @@ from xblock_django.user_service import DjangoXBlockUserService
|
||||
from cms.lib.xblock.authoring_mixin import VISIBILITY_VIEW
|
||||
from contentstore.utils import (
|
||||
find_release_date_source, find_staff_lock_source, is_currently_visible_to_students,
|
||||
ancestor_has_staff_lock, has_children_visible_to_specific_content_groups,
|
||||
ancestor_has_staff_lock, has_children_visible_to_specific_partition_groups,
|
||||
get_user_partition_info, get_split_group_display_name,
|
||||
)
|
||||
from contentstore.views.helpers import is_unit, xblock_studio_url, xblock_primary_child_category, \
|
||||
@@ -1005,6 +1005,7 @@ def _get_module_info(xblock, rewrite_static_links=True, include_ancestor_info=Fa
|
||||
)
|
||||
if include_publishing_info:
|
||||
add_container_page_publishing_info(xblock, xblock_info)
|
||||
|
||||
return xblock_info
|
||||
|
||||
|
||||
@@ -1217,6 +1218,10 @@ def create_xblock_info(xblock, data=None, metadata=None, include_ancestor_info=F
|
||||
)
|
||||
else:
|
||||
xblock_info['staff_only_message'] = False
|
||||
|
||||
xblock_info["has_partition_group_components"] = has_children_visible_to_specific_partition_groups(
|
||||
xblock
|
||||
)
|
||||
return xblock_info
|
||||
|
||||
|
||||
@@ -1245,7 +1250,7 @@ def add_container_page_publishing_info(xblock, xblock_info): # pylint: disable=
|
||||
xblock_info["edited_by"] = safe_get_username(xblock.subtree_edited_by)
|
||||
xblock_info["published_by"] = safe_get_username(xblock.published_by)
|
||||
xblock_info["currently_visible_to_students"] = is_currently_visible_to_students(xblock)
|
||||
xblock_info["has_content_group_components"] = has_children_visible_to_specific_content_groups(xblock)
|
||||
xblock_info["has_partition_group_components"] = has_children_visible_to_specific_partition_groups(xblock)
|
||||
if xblock_info["release_date"]:
|
||||
xblock_info["release_date_from"] = _get_release_date_from(xblock)
|
||||
if xblock_info["visibility_state"] == VisibilityState.staff_only:
|
||||
|
||||
@@ -7,6 +7,7 @@ from django.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http import Http404, HttpResponseBadRequest
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.utils.translation import ugettext as _
|
||||
from edxmako.shortcuts import render_to_string
|
||||
|
||||
from openedx.core.lib.xblock_utils import (
|
||||
@@ -38,6 +39,7 @@ import static_replace
|
||||
from .session_kv_store import SessionKeyValueStore
|
||||
from .helpers import render_from_lms
|
||||
|
||||
from contentstore.utils import get_visibility_partition_info
|
||||
from contentstore.views.access import get_user_role
|
||||
from xblock_config.models import StudioConfig
|
||||
|
||||
@@ -279,6 +281,9 @@ def _studio_wrap_xblock(xblock, view, frag, context, display_name_only=False):
|
||||
root_xblock = context.get('root_xblock')
|
||||
is_root = root_xblock and xblock.location == root_xblock.location
|
||||
is_reorderable = _is_xblock_reorderable(xblock, context)
|
||||
selected_groups_label = get_visibility_partition_info(xblock)['selected_groups_label']
|
||||
if selected_groups_label:
|
||||
selected_groups_label = _('Visible to: {list_of_groups}').format(list_of_groups=selected_groups_label)
|
||||
template_context = {
|
||||
'xblock_context': context,
|
||||
'xblock': xblock,
|
||||
@@ -288,6 +293,7 @@ def _studio_wrap_xblock(xblock, view, frag, context, display_name_only=False):
|
||||
'is_reorderable': is_reorderable,
|
||||
'can_edit': context.get('can_edit', True),
|
||||
'can_edit_visibility': context.get('can_edit_visibility', True),
|
||||
'selected_groups_label': selected_groups_label,
|
||||
'can_add': context.get('can_add', True),
|
||||
'can_move': context.get('can_move', True)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user