Added ability to disable xblock types in LMS.
TNL-2305
This commit is contained in:
@@ -3,6 +3,9 @@ from xmodule.raw_module import RawDescriptor
|
||||
|
||||
|
||||
class HiddenModule(XModule):
|
||||
|
||||
HIDDEN = True
|
||||
|
||||
def get_html(self):
|
||||
if self.system.user_is_staff:
|
||||
return u"ERROR: This module is unknown--students will not see it at all"
|
||||
|
||||
@@ -1122,7 +1122,7 @@ class ModuleStoreReadBase(BulkOperationsMixin, ModuleStoreRead):
|
||||
contentstore=None,
|
||||
doc_store_config=None, # ignore if passed up
|
||||
metadata_inheritance_cache_subsystem=None, request_cache=None,
|
||||
xblock_mixins=(), xblock_select=None,
|
||||
xblock_mixins=(), xblock_select=None, disabled_xblock_types=(), # pylint: disable=bad-continuation
|
||||
# temporary parms to enable backward compatibility. remove once all envs migrated
|
||||
db=None, collection=None, host=None, port=None, tz_aware=True, user=None, password=None,
|
||||
# allow lower level init args to pass harmlessly
|
||||
@@ -1139,6 +1139,7 @@ class ModuleStoreReadBase(BulkOperationsMixin, ModuleStoreRead):
|
||||
self.request_cache = request_cache
|
||||
self.xblock_mixins = xblock_mixins
|
||||
self.xblock_select = xblock_select
|
||||
self.disabled_xblock_types = disabled_xblock_types
|
||||
self.contentstore = contentstore
|
||||
|
||||
def get_course_errors(self, course_key):
|
||||
|
||||
@@ -46,6 +46,11 @@ try:
|
||||
except ImportError:
|
||||
HAS_USER_SERVICE = False
|
||||
|
||||
try:
|
||||
from xblock_django.models import XBlockDisableConfig
|
||||
except ImportError:
|
||||
XBlockDisableConfig = None
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
ASSET_IGNORE_REGEX = getattr(settings, "ASSET_IGNORE_REGEX", r"(^\._.*$)|(^\.DS_Store$)|(^.*~$)")
|
||||
|
||||
@@ -161,12 +166,18 @@ def create_modulestore_instance(
|
||||
if 'read_preference' in doc_store_config:
|
||||
doc_store_config['read_preference'] = getattr(ReadPreference, doc_store_config['read_preference'])
|
||||
|
||||
if XBlockDisableConfig and settings.FEATURES.get('ENABLE_DISABLING_XBLOCK_TYPES', False):
|
||||
disabled_xblock_types = XBlockDisableConfig.disabled_block_types()
|
||||
else:
|
||||
disabled_xblock_types = ()
|
||||
|
||||
return class_(
|
||||
contentstore=content_store,
|
||||
metadata_inheritance_cache_subsystem=metadata_inheritance_cache,
|
||||
request_cache=request_cache,
|
||||
xblock_mixins=getattr(settings, 'XBLOCK_MIXINS', ()),
|
||||
xblock_select=getattr(settings, 'XBLOCK_SELECT_FUNCTION', None),
|
||||
disabled_xblock_types=disabled_xblock_types,
|
||||
doc_store_config=doc_store_config,
|
||||
i18n_service=i18n_service or ModuleI18nService(),
|
||||
fs_service=fs_service or xblock.reference.plugins.FSService(),
|
||||
|
||||
@@ -937,6 +937,7 @@ class MongoModuleStore(ModuleStoreDraftAndPublished, ModuleStoreWriteBase, Mongo
|
||||
cached_metadata=cached_metadata,
|
||||
mixins=self.xblock_mixins,
|
||||
select=self.xblock_select,
|
||||
disabled_xblock_types=self.disabled_xblock_types,
|
||||
services=services,
|
||||
)
|
||||
else:
|
||||
|
||||
@@ -3099,6 +3099,7 @@ class SplitMongoModuleStore(SplitBulkWriteMixin, ModuleStoreWriteBase):
|
||||
render_template=self.render_template,
|
||||
mixins=self.xblock_mixins,
|
||||
select=self.xblock_select,
|
||||
disabled_xblock_types=self.disabled_xblock_types,
|
||||
services=self.services,
|
||||
)
|
||||
|
||||
|
||||
@@ -1298,9 +1298,9 @@ class DescriptorSystem(MetricsMixin, ConfigurableFragmentWrapper, Runtime): # p
|
||||
"""
|
||||
Base class for :class:`Runtime`s to be used with :class:`XModuleDescriptor`s
|
||||
"""
|
||||
|
||||
# pylint: disable=bad-continuation
|
||||
def __init__(
|
||||
self, load_item, resources_fs, error_tracker, get_policy=None, **kwargs
|
||||
self, load_item, resources_fs, error_tracker, get_policy=None, disabled_xblock_types=(), **kwargs
|
||||
):
|
||||
"""
|
||||
load_item: Takes a Location and returns an XModuleDescriptor
|
||||
@@ -1358,10 +1358,20 @@ class DescriptorSystem(MetricsMixin, ConfigurableFragmentWrapper, Runtime): # p
|
||||
else:
|
||||
self.get_policy = lambda u: {}
|
||||
|
||||
self.disabled_xblock_types = disabled_xblock_types
|
||||
|
||||
def get_block(self, usage_id, for_parent=None):
|
||||
"""See documentation for `xblock.runtime:Runtime.get_block`"""
|
||||
return self.load_item(usage_id, for_parent=for_parent)
|
||||
|
||||
def load_block_type(self, block_type):
|
||||
"""
|
||||
Returns a subclass of :class:`.XBlock` that corresponds to the specified `block_type`.
|
||||
"""
|
||||
if block_type in self.disabled_xblock_types:
|
||||
return self.default_class
|
||||
return super(DescriptorSystem, self).load_block_type(block_type)
|
||||
|
||||
def get_field_provenance(self, xblock, field):
|
||||
"""
|
||||
For the given xblock, return a dict for the field's current state:
|
||||
|
||||
Reference in New Issue
Block a user