def _advanced_component_types(show_unsupported): """ Return advanced component types which can be created. Args: show_unsupported: if True, unsupported XBlocks may be included in the return value Returns: A dict of authorable XBlock types and their support levels (see XBlockStudioConfiguration). For example: { "done": "us", # unsupported "discussion: "fs" # fully supported } Note that the support level will be "True" for all XBlocks if XBlockStudioConfigurationFlag is not enabled. """ enabled_block_types = _filter_disabled_blocks(ADVANCED_COMPONENT_TYPES) if XBlockStudioConfigurationFlag.is_enabled(): authorable_blocks = authorable_xblocks( allow_unsupported=show_unsupported) filtered_blocks = {} for block in authorable_blocks: if block.name in enabled_block_types: filtered_blocks[block.name] = block.support_level return filtered_blocks else: all_blocks = {} for block_name in enabled_block_types: all_blocks[block_name] = True return all_blocks
def authorable_xblocks(allow_unsupported=False, name=None): """ If Studio XBlock support state is enabled (via `XBlockStudioConfigurationFlag`), this method returns the QuerySet of XBlocks that can be created in Studio (by default, only fully supported and provisionally supported). If `XBlockStudioConfigurationFlag` is not enabled, this method returns None. Note that this method does not take into account fully disabled xblocks (as returned by `disabled_xblocks`) or deprecated xblocks (as returned by `deprecated_xblocks`). Arguments: allow_unsupported (bool): If `True`, enabled but unsupported XBlocks will also be returned. Note that unsupported XBlocks are not recommended for use in courses due to non-compliance with one or more of the base requirements, such as testing, accessibility, internationalization, and documentation. Default value is `False`. name (str): If provided, filters the returned XBlocks to those with the provided name. This is useful for XBlocks with lots of template types. Returns: QuerySet: If `XBlockStudioConfigurationFlag` is enabled, returns authorable XBlocks, taking into account `support_level`, `enabled` and `name` (if specified). If `XBlockStudioConfigurationFlag` is disabled, returns None. """ if not XBlockStudioConfigurationFlag.is_enabled(): return None blocks = XBlockStudioConfiguration.objects.current_set().filter( enabled=True) if not allow_unsupported: blocks = blocks.exclude( support_level=XBlockStudioConfiguration.UNSUPPORTED) if name: blocks = blocks.filter(name=name) return blocks
def _advanced_component_types(show_unsupported): """ Return advanced component types which can be created. Args: show_unsupported: if True, unsupported XBlocks may be included in the return value Returns: A dict of authorable XBlock types and their support levels (see XBlockStudioConfiguration). For example: { "done": "us", # unsupported "discussion: "fs" # fully supported } Note that the support level will be "True" for all XBlocks if XBlockStudioConfigurationFlag is not enabled. """ enabled_block_types = _filter_disabled_blocks(ADVANCED_COMPONENT_TYPES) if XBlockStudioConfigurationFlag.is_enabled(): authorable_blocks = authorable_xblocks(allow_unsupported=show_unsupported) filtered_blocks = {} for block in authorable_blocks: if block.name in enabled_block_types: filtered_blocks[block.name] = block.support_level return filtered_blocks else: all_blocks = {} for block_name in enabled_block_types: all_blocks[block_name] = True return all_blocks
def component_support_level(editable_types, name, template=None): """ Returns the support level for the given xblock name/template combination. Args: editable_types: a QuerySet of xblocks with their support levels name: the name of the xblock template: optional template for the xblock Returns: If XBlockStudioConfigurationFlag is enabled, returns the support level (see XBlockStudioConfiguration) or False if this xblock name/template combination has no Studio support at all. If XBlockStudioConfigurationFlag is disabled, simply returns True. """ # If the Studio support feature is disabled, return True for all. if not XBlockStudioConfigurationFlag.is_enabled(): return True if template is None: template = "" extension_index = template.rfind(".yaml") if extension_index >= 0: template = template[0:extension_index] for block in editable_types: if block.name == name and block.template == template: return block.support_level return False
def authorable_xblocks(allow_unsupported=False, name=None): """ If Studio XBlock support state is enabled (via `XBlockStudioConfigurationFlag`), this method returns the QuerySet of XBlocks that can be created in Studio (by default, only fully supported and provisionally supported). If `XBlockStudioConfigurationFlag` is not enabled, this method returns None. Note that this method does not take into account fully disabled xblocks (as returned by `disabled_xblocks`) or deprecated xblocks (as returned by `deprecated_xblocks`). Arguments: allow_unsupported (bool): If `True`, enabled but unsupported XBlocks will also be returned. Note that unsupported XBlocks are not recommended for use in courses due to non-compliance with one or more of the base requirements, such as testing, accessibility, internationalization, and documentation. Default value is `False`. name (str): If provided, filters the returned XBlocks to those with the provided name. This is useful for XBlocks with lots of template types. Returns: QuerySet: If `XBlockStudioConfigurationFlag` is enabled, returns authorable XBlocks, taking into account `support_level`, `enabled` and `name` (if specified). If `XBlockStudioConfigurationFlag` is disabled, returns None. """ if not XBlockStudioConfigurationFlag.is_enabled(): return None blocks = XBlockStudioConfiguration.objects.current_set().filter(enabled=True) if not allow_unsupported: blocks = blocks.exclude(support_level=XBlockStudioConfiguration.UNSUPPORTED) if name: blocks = blocks.filter(name=name) return blocks
def create_support_legend_dict(): """ Returns a dict of settings information for the display of the support level legend. """ return { "show_legend": XBlockStudioConfigurationFlag.is_enabled(), "allow_unsupported_xblocks": allow_unsupported, "documentation_label": _("{platform_name} Support Levels:").format(platform_name=settings.PLATFORM_NAME) }
def filtered_list(cls): """ Filter fields based on feature flag, i.e. enabled, disabled. """ # Copy the filtered list to avoid permanently changing the class attribute. filtered_list = list(cls.FILTERED_LIST) # Do not show giturl if feature is not enabled. if not settings.FEATURES.get('ENABLE_EXPORT_GIT'): filtered_list.append('giturl') # Do not show edxnotes if the feature is disabled. if not settings.FEATURES.get('ENABLE_EDXNOTES'): filtered_list.append('edxnotes') # Do not show video auto advance if the feature is disabled if not settings.FEATURES.get('ENABLE_OTHER_COURSE_SETTINGS'): filtered_list.append('other_course_settings') # Do not show video_upload_pipeline if the feature is disabled. if not settings.FEATURES.get('ENABLE_VIDEO_UPLOAD_PIPELINE'): filtered_list.append('video_upload_pipeline') # Do not show video auto advance if the feature is disabled if not settings.FEATURES.get('ENABLE_AUTOADVANCE_VIDEOS'): filtered_list.append('video_auto_advance') # Do not show social sharing url field if the feature is disabled. if (not hasattr(settings, 'SOCIAL_SHARING_SETTINGS') or not getattr(settings, 'SOCIAL_SHARING_SETTINGS', {}).get("CUSTOM_COURSE_URLS")): filtered_list.append('social_sharing_url') # Do not show teams configuration if feature is disabled. if not settings.FEATURES.get('ENABLE_TEAMS'): filtered_list.append('teams_configuration') if not settings.FEATURES.get('ENABLE_VIDEO_BUMPER'): filtered_list.append('video_bumper') # Do not show enable_ccx if feature is not enabled. if not settings.FEATURES.get('CUSTOM_COURSES_EDX'): filtered_list.append('enable_ccx') filtered_list.append('ccx_connector') # Do not show "Issue Open Badges" in Studio Advanced Settings # if the feature is disabled. if not settings.FEATURES.get('ENABLE_OPENBADGES'): filtered_list.append('issue_badges') # If the XBlockStudioConfiguration table is not being used, there is no need to # display the "Allow Unsupported XBlocks" setting. if not XBlockStudioConfigurationFlag.is_enabled(): filtered_list.append('allow_unsupported_xblocks') return filtered_list
def filtered_list(cls): """ Filter fields based on feature flag, i.e. enabled, disabled. """ # Copy the filtered list to avoid permanently changing the class attribute. filtered_list = list(cls.FILTERED_LIST) # Do not show giturl if feature is not enabled. if not settings.FEATURES.get('ENABLE_EXPORT_GIT'): filtered_list.append('giturl') # Do not show edxnotes if the feature is disabled. if not settings.FEATURES.get('ENABLE_EDXNOTES'): filtered_list.append('edxnotes') # Do not show video_upload_pipeline if the feature is disabled. if not settings.FEATURES.get('ENABLE_VIDEO_UPLOAD_PIPELINE'): filtered_list.append('video_upload_pipeline') # Do not show social sharing url field if the feature is disabled. if (not hasattr(settings, 'SOCIAL_SHARING_SETTINGS') or not getattr(settings, 'SOCIAL_SHARING_SETTINGS', {}).get("CUSTOM_COURSE_URLS")): filtered_list.append('social_sharing_url') # Do not show teams configuration if feature is disabled. if not settings.FEATURES.get('ENABLE_TEAMS'): filtered_list.append('teams_configuration') if not settings.FEATURES.get('ENABLE_VIDEO_BUMPER'): filtered_list.append('video_bumper') # Do not show enable_ccx if feature is not enabled. if not settings.FEATURES.get('CUSTOM_COURSES_EDX'): filtered_list.append('enable_ccx') filtered_list.append('ccx_connector') # Do not show "Issue Open Badges" in Studio Advanced Settings # if the feature is disabled. if not settings.FEATURES.get('ENABLE_OPENBADGES'): filtered_list.append('issue_badges') # If the XBlockStudioConfiguration table is not being used, there is no need to # display the "Allow Unsupported XBlocks" setting. if not XBlockStudioConfigurationFlag.is_enabled(): filtered_list.append('allow_unsupported_xblocks') # TODO: https://openedx.atlassian.net/browse/EDUCATOR-736 # Before we roll out the auto-certs feature, move this to a good, shared # place such that we're not repeating code found in LMS. switches = WaffleSwitchNamespace(name=u'certificates', log_prefix=u'Certificates: ') if not switches.is_enabled(u'instructor_paced_only'): filtered_list.append('certificate_available_date') return filtered_list
def test_authorable_blocks_empty_model(self): """ Tests authorable_xblocks returns an empty list if XBlockStudioConfiguration table is empty, regardless of whether or not XBlockStudioConfigurationFlag is enabled. """ XBlockStudioConfiguration.objects.all().delete() self.assertFalse(XBlockStudioConfigurationFlag.is_enabled()) self.assertEqual(0, len(authorable_xblocks(allow_unsupported=True))) XBlockStudioConfigurationFlag(enabled=True).save() self.assertEqual(0, len(authorable_xblocks(allow_unsupported=True)))
def get_exclude_list_of_fields(cls, course_key): """ Returns a list of fields to exclude from the Studio Advanced settings based on a feature flag (i.e. enabled or disabled). """ # Copy the filtered list to avoid permanently changing the class attribute. exclude_list = list(cls.FIELDS_EXCLUDE_LIST) # Do not show giturl if feature is not enabled. if not settings.FEATURES.get('ENABLE_EXPORT_GIT'): exclude_list.append('giturl') # Do not show edxnotes if the feature is disabled. if not settings.FEATURES.get('ENABLE_EDXNOTES'): exclude_list.append('edxnotes') # Do not show video auto advance if the feature is disabled if not settings.FEATURES.get('ENABLE_OTHER_COURSE_SETTINGS'): exclude_list.append('other_course_settings') # Do not show video_upload_pipeline if the feature is disabled. if not settings.FEATURES.get('ENABLE_VIDEO_UPLOAD_PIPELINE'): exclude_list.append('video_upload_pipeline') # Do not show video auto advance if the feature is disabled if not settings.FEATURES.get('ENABLE_AUTOADVANCE_VIDEOS'): exclude_list.append('video_auto_advance') # Do not show social sharing url field if the feature is disabled. if (not hasattr(settings, 'SOCIAL_SHARING_SETTINGS') or not getattr(settings, 'SOCIAL_SHARING_SETTINGS', {}).get("CUSTOM_COURSE_URLS")): exclude_list.append('social_sharing_url') # Do not show teams configuration if feature is disabled. if not settings.FEATURES.get('ENABLE_TEAMS'): exclude_list.append('teams_configuration') if not settings.FEATURES.get('ENABLE_VIDEO_BUMPER'): exclude_list.append('video_bumper') # Do not show enable_ccx if feature is not enabled. if not settings.FEATURES.get('CUSTOM_COURSES_EDX'): exclude_list.append('enable_ccx') exclude_list.append('ccx_connector') # Do not show "Issue Open Badges" in Studio Advanced Settings # if the feature is disabled. if not settings.FEATURES.get('ENABLE_OPENBADGES'): exclude_list.append('issue_badges') # If the XBlockStudioConfiguration table is not being used, there is no need to # display the "Allow Unsupported XBlocks" setting. if not XBlockStudioConfigurationFlag.is_enabled(): exclude_list.append('allow_unsupported_xblocks') # Do not show "Course Visibility For Unenrolled Learners" in Studio Advanced Settings # if the enable_anonymous_access flag is not enabled if not COURSE_ENABLE_UNENROLLED_ACCESS_FLAG.is_enabled(course_key=course_key): exclude_list.append('course_visibility') # Do not show "Create Zendesk Tickets For Suspicious Proctored Exam Attempts" in # Studio Advanced Settings if the user is not edX staff. if not GlobalStaff().has_user(get_current_user()): exclude_list.append('create_zendesk_tickets') # Do not show "Proctortrack Exam Escalation Contact" if Proctortrack is not # an available proctoring backend. if not settings.PROCTORING_BACKENDS or settings.PROCTORING_BACKENDS.get('proctortrack') is None: exclude_list.append('proctoring_escalation_email') return exclude_list
def test_authorable_blocks_flag_disabled(self): """ Tests authorable_xblocks returns None if the configuration flag is not enabled. """ self.assertFalse(XBlockStudioConfigurationFlag.is_enabled()) self.assertIsNone(authorable_xblocks())
def get_blacklist_of_fields(cls, course_key): """ Returns a list of fields to not include in Studio Advanced settings based on a feature flag (i.e. enabled or disabled). """ # Copy the filtered list to avoid permanently changing the class attribute. black_list = list(cls.FIELDS_BLACK_LIST) # Do not show giturl if feature is not enabled. if not settings.FEATURES.get('ENABLE_EXPORT_GIT'): black_list.append('giturl') # Do not show edxnotes if the feature is disabled. if not settings.FEATURES.get('ENABLE_EDXNOTES'): black_list.append('edxnotes') # Do not show video auto advance if the feature is disabled if not settings.FEATURES.get('ENABLE_OTHER_COURSE_SETTINGS'): black_list.append('other_course_settings') # Do not show video_upload_pipeline if the feature is disabled. if not settings.FEATURES.get('ENABLE_VIDEO_UPLOAD_PIPELINE'): black_list.append('video_upload_pipeline') # Do not show video auto advance if the feature is disabled if not settings.FEATURES.get('ENABLE_AUTOADVANCE_VIDEOS'): black_list.append('video_auto_advance') # Do not show social sharing url field if the feature is disabled. if (not hasattr(settings, 'SOCIAL_SHARING_SETTINGS') or not getattr(settings, 'SOCIAL_SHARING_SETTINGS', {}).get("CUSTOM_COURSE_URLS")): black_list.append('social_sharing_url') # Do not show teams configuration if feature is disabled. if not settings.FEATURES.get('ENABLE_TEAMS'): black_list.append('teams_configuration') if not settings.FEATURES.get('ENABLE_VIDEO_BUMPER'): black_list.append('video_bumper') # Do not show enable_ccx if feature is not enabled. if not settings.FEATURES.get('CUSTOM_COURSES_EDX'): black_list.append('enable_ccx') black_list.append('ccx_connector') # Do not show "Issue Open Badges" in Studio Advanced Settings # if the feature is disabled. if not settings.FEATURES.get('ENABLE_OPENBADGES'): black_list.append('issue_badges') # If the XBlockStudioConfiguration table is not being used, there is no need to # display the "Allow Unsupported XBlocks" setting. if not XBlockStudioConfigurationFlag.is_enabled(): black_list.append('allow_unsupported_xblocks') # If the ENABLE_PROCTORING_PROVIDER_OVERRIDES waffle flag is not enabled, # do not show "Proctoring Configuration" in Studio Advanced Settings. if not ENABLE_PROCTORING_PROVIDER_OVERRIDES.is_enabled(course_key): black_list.append('proctoring_provider') # Do not show "Course Visibility For Unenrolled Learners" in Studio Advanced Settings # if the enable_anonymous_access flag is not enabled if not COURSE_ENABLE_UNENROLLED_ACCESS_FLAG.is_enabled(course_key=course_key): black_list.append('course_visibility') # Do not show "Create Zendesk Tickets For Suspicious Proctored Exam Attempts" in # Studio Advanced Settings if the user is not edX staff. if not GlobalStaff().has_user(get_current_user()): black_list.append('create_zendesk_tickets') return black_list