Ejemplo n.º 1
0
 def transform(self, usage_info, block_structure):
     """
     loads override data into blocks
     """
     provider_type = DiscussionsConfiguration.get(
         usage_info.course_key).provider_type
     topic_links = DiscussionTopicLink.objects.filter(
         context_key=usage_info.course_key,
         provider_id=provider_type,
         enabled_in_context=True,
     )
     for topic_link in topic_links:
         block_structure.override_xblock_field(
             topic_link.usage_key,
             DiscussionsTopicLinkTransformer.EXTERNAL_ID,
             topic_link.external_id,
         )
         mfe_embed_link = get_discussions_mfe_topic_url(
             usage_info.course_key, topic_link.external_id)
         if mfe_embed_link:
             block_structure.override_xblock_field(
                 topic_link.usage_key,
                 DiscussionsTopicLinkTransformer.EMBED_URL,
                 mfe_embed_link,
             )
Ejemplo n.º 2
0
 def _link_func(course, reverse_func):
     config = DiscussionsConfiguration.get(course.id)
     if config.provider_type == Provider.OPEN_EDX:
         return get_learning_mfe_home_url(course_key=course.id,
                                          url_fragment=self.type)
     else:
         return legacy_link_func(course, reverse_func)
Ejemplo n.º 3
0
 def is_enabled(cls, course, user=None):
     if super().is_enabled(course, user):
         config = DiscussionsConfiguration.get(course.id)
         return (
             config.enabled and
             config.lti_configuration is not None
         )
     else:
         return False
Ejemplo n.º 4
0
def _filter_discussion_for_non_legacy_provider(all_components, course_key):
    """
    Filter out Discussion component if non-legacy discussion provider is configured for course key
    """
    discussion_provider = DiscussionsConfiguration.get(context_key=course_key).provider_type

    if discussion_provider != 'legacy':
        filtered_components = [component for component in all_components if component != 'discussion']
    else:
        filtered_components = all_components

    return filtered_components
Ejemplo n.º 5
0
 def test_tabs_enrolled_or_staff(self, provider):
     config = DiscussionsConfiguration.get(self.course.id)
     config.provider_type = provider
     config.save()
     for is_enrolled, is_staff in [(True, False), (False, True)]:
         if provider == Provider.OPEN_EDX:
             expected_link = get_learning_mfe_home_url(
                 course_key=self.course.id, url_fragment="discussion")
         else:
             expected_link = "default_discussion_link"
         self.check_discussion(tab_list=self.tabs_with_discussion,
                               expected_discussion_link=expected_link,
                               expected_can_display_value=True,
                               is_enrolled=is_enrolled,
                               is_staff=is_staff)
Ejemplo n.º 6
0
 def test_tabs_with_discussion(self, provider):
     """Test a course with a discussion tab configured"""
     config = DiscussionsConfiguration.get(self.course.id)
     config.provider_type = provider
     config.save()
     if provider == Provider.OPEN_EDX:
         expected_link = get_learning_mfe_home_url(
             course_key=self.course.id, url_fragment="discussion")
     else:
         expected_link = "default_discussion_link"
     self.check_discussion(
         tab_list=self.tabs_with_discussion,
         expected_discussion_link=expected_link,
         expected_can_display_value=True,
     )
Ejemplo n.º 7
0
 def _get_lti_config(self, course: CourseBlock) -> LtiConfiguration:
     config = DiscussionsConfiguration.get(course.id)
     return config.lti_configuration
Ejemplo n.º 8
0
def update_course_discussion_config(configuration: CourseDiscussionConfigurationData):
    """
    Update the database version of the configuration if it changes in the course structure.

    This function accepts a discussion configuration object that represents the current
    configuration and applies that state to the database. It will go over the list of topic
    links in the configuration, find the corresponding topic link in the database and apply
    any changes if needed. If a new topic link has been introduced it will create an entry.
    If a topic has been removed, it will deactivate the entry.

    When this runs on a new course it will create a new DiscussionConfiguration entry for
    the course.

    Args:
        configuration (CourseDiscussionConfigurationData): configuration data for the course
    """
    course_key = configuration.course_key
    provider_id = configuration.provider_type or DEFAULT_PROVIDER_TYPE
    new_topic_map = {
        (topic_context.usage_key or topic_context.external_id): topic_context
        for topic_context in configuration.contexts
    }
    with transaction.atomic():
        log.info(f"Updating existing discussion topic links for {course_key}")
        for topic_link in DiscussionTopicLink.objects.filter(
            context_key=course_key, provider_id=provider_id,
        ):
            lookup_key = topic_link.usage_key or topic_link.external_id
            topic_context = new_topic_map.pop(lookup_key, None)
            # TODO: handle deleting topics that are no longer in use
            # currently this will simply not work for course-wide topics since deleting the link will
            # remove access to all posts in the topic.
            if topic_context is None:
                topic_link.enabled_in_context = False
            else:
                topic_link.enabled_in_context = True
                topic_link.title = topic_context.title
            topic_link.save()
        log.info(f"Creating new discussion topic links for {course_key}")

        DiscussionTopicLink.objects.bulk_create([
            DiscussionTopicLink(
                context_key=course_key,
                usage_key=topic_context.usage_key,
                title=topic_context.title,
                provider_id=provider_id,
                external_id=topic_context.external_id or uuid4(),
                enabled_in_context=True,
            )
            for topic_context in new_topic_map.values()
        ])

        if not DiscussionsConfiguration.objects.filter(context_key=course_key).exists():
            log.info(f"Course {course_key} doesn't have discussion configuration model yet. Creating a new one.")
            DiscussionsConfiguration(
                context_key=course_key,
                provider_type=provider_id,
                plugin_configuration=configuration.plugin_configuration,
                enable_in_context=configuration.enable_in_context,
                enable_graded_units=configuration.enable_graded_units,
                unit_level_visibility=configuration.unit_level_visibility,
            ).save()
Ejemplo n.º 9
0
 def is_enabled(cls, course, user=None):
     """Check if the tab is enabled."""
     if super().is_enabled(course, user):
         return DiscussionsConfiguration.lti_discussion_enabled(course.id)
     return False