Merge pull request #19385 from open-craft/pooja/implement-public-cohort
Implement public cohort for anonymous and unenrolled users
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Tests for the wrapping layer that provides the XBlock API using XModule/Descriptor
|
||||
functionality
|
||||
@@ -27,7 +28,7 @@ from xblock.core import XBlock
|
||||
|
||||
from opaque_keys.edx.locator import BlockUsageLocator, CourseLocator
|
||||
|
||||
from xmodule.x_module import ModuleSystem, XModule, XModuleDescriptor, DescriptorSystem, STUDENT_VIEW, STUDIO_VIEW
|
||||
from xmodule.x_module import ModuleSystem, XModule, XModuleDescriptor, DescriptorSystem, STUDENT_VIEW, STUDIO_VIEW, PUBLIC_VIEW
|
||||
from xmodule.annotatable_module import AnnotatableDescriptor
|
||||
from xmodule.capa_module import CapaDescriptor
|
||||
from xmodule.course_module import CourseDescriptor
|
||||
@@ -63,8 +64,8 @@ LEAF_XMODULES = {
|
||||
CONTAINER_XMODULES = {
|
||||
ConditionalDescriptor: [{}],
|
||||
CourseDescriptor: [{}],
|
||||
RandomizeDescriptor: [{}],
|
||||
SequenceDescriptor: [{}],
|
||||
RandomizeDescriptor: [{'display_name': 'Test String Display'}],
|
||||
SequenceDescriptor: [{'display_name': u'Test Unicode हिंदी Display'}],
|
||||
VerticalBlock: [{}],
|
||||
WrapperBlock: [{}],
|
||||
}
|
||||
@@ -433,3 +434,34 @@ class TestXmlExport(XBlockWrapperTestMixin, TestCase):
|
||||
|
||||
self.assertEquals(list(xmodule_api_fs.walk()), list(xblock_api_fs.walk()))
|
||||
self.assertEquals(etree.tostring(xmodule_node), etree.tostring(xblock_node))
|
||||
|
||||
|
||||
class TestPublicView(XBlockWrapperTestMixin, TestCase):
|
||||
"""
|
||||
This tests that default public_view shows the correct message.
|
||||
"""
|
||||
shard = 1
|
||||
|
||||
def skip_if_invalid(self, descriptor_cls):
|
||||
pure_xblock_class = issubclass(descriptor_cls, XBlock) and not issubclass(descriptor_cls, XModuleDescriptor)
|
||||
if pure_xblock_class:
|
||||
public_view = descriptor_cls.public_view
|
||||
else:
|
||||
public_view = descriptor_cls.module_class.public_view
|
||||
if public_view != XModule.public_view:
|
||||
raise SkipTest(descriptor_cls.__name__ + " implements public_view")
|
||||
|
||||
def check_property(self, descriptor):
|
||||
"""
|
||||
Assert that public_view contains correct message.
|
||||
"""
|
||||
if descriptor.display_name:
|
||||
self.assertIn(
|
||||
descriptor.display_name,
|
||||
descriptor.render(PUBLIC_VIEW).content
|
||||
)
|
||||
else:
|
||||
self.assertIn(
|
||||
"This content is only accessible",
|
||||
descriptor.render(PUBLIC_VIEW).content
|
||||
)
|
||||
|
||||
@@ -72,7 +72,10 @@ STUDIO_VIEW = 'studio_view'
|
||||
# Views that present a "preview" view of an xblock (as opposed to an editing view).
|
||||
PREVIEW_VIEWS = [STUDENT_VIEW, PUBLIC_VIEW, AUTHOR_VIEW]
|
||||
|
||||
DEFAULT_PUBLIC_VIEW_MESSAGE = u'Please enroll to view this content.'
|
||||
DEFAULT_PUBLIC_VIEW_MESSAGE = (
|
||||
u'This content is only accessible to enrolled learners. '
|
||||
u'Sign in or register, and enroll in this course to view it.'
|
||||
)
|
||||
|
||||
# Make '_' a no-op so we can scrape strings. Using lambda instead of
|
||||
# `django.utils.translation.ugettext_noop` because Django cannot be imported in this file
|
||||
@@ -766,7 +769,18 @@ class XModuleMixin(XModuleFields, XBlock):
|
||||
u'<span class="icon icon-alert fa fa fa-warning" aria-hidden="true"></span>'
|
||||
u'<div class="message-content">{}</div></div></div>'
|
||||
)
|
||||
return Fragment(alert_html.format(DEFAULT_PUBLIC_VIEW_MESSAGE))
|
||||
|
||||
if self.display_name:
|
||||
display_text = _(
|
||||
u'{display_name} is only accessible to enrolled learners. '
|
||||
'Sign in or register, and enroll in this course to view it.'
|
||||
).format(
|
||||
display_name=self.display_name
|
||||
)
|
||||
else:
|
||||
display_text = _(DEFAULT_PUBLIC_VIEW_MESSAGE)
|
||||
|
||||
return Fragment(alert_html.format(display_text))
|
||||
|
||||
|
||||
class ProxyAttribute(object):
|
||||
|
||||
Reference in New Issue
Block a user