Ejemplo n.º 1
0
    def test_sequential_and_problem_have_group_access(self):
        """ Tests when group_access is set on a few different components. """
        self.set_group_access(self.sequential, {1: [0]})
        # This is a no-op.
        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))

        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))
Ejemplo n.º 2
0
def add_container_page_publishing_info(xblock, xblock_info):  # pylint: disable=invalid-name
    """
    Adds information about the xblock's publish state to the supplied
    xblock_info for the container page.
    """
    def safe_get_username(user_id):
        """
        Guard against bad user_ids, like the infamous "**replace_user**".
        Note that this will ignore our special known IDs (ModuleStoreEnum.UserID).
        We should consider adding special handling for those values.

        :param user_id: the user id to get the username of
        :return: username, or None if the user does not exist or user_id is None
        """
        if user_id:
            try:
                return User.objects.get(id=user_id).username
            except:  # pylint: disable=bare-except
                pass

        return None

    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)
    if xblock_info["release_date"]:
        xblock_info["release_date_from"] = _get_release_date_from(xblock)
    if xblock_info["visibility_state"] == VisibilityState.staff_only:
        xblock_info["staff_lock_from"] = _get_staff_lock_from(xblock)
    else:
        xblock_info["staff_lock_from"] = None
Ejemplo n.º 3
0
def add_container_page_publishing_info(xblock, xblock_info):  # pylint: disable=invalid-name
    """
    Adds information about the xblock's publish state to the supplied
    xblock_info for the container page.
    """
    def safe_get_username(user_id):
        """
        Guard against bad user_ids, like the infamous "**replace_user**".
        Note that this will ignore our special known IDs (ModuleStoreEnum.UserID).
        We should consider adding special handling for those values.

        :param user_id: the user id to get the username of
        :return: username, or None if the user does not exist or user_id is None
        """
        if user_id:
            try:
                return User.objects.get(id=user_id).username
            except:  # pylint: disable=bare-except
                pass

        return None

    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)
    if xblock_info["release_date"]:
        xblock_info["release_date_from"] = _get_release_date_from(xblock)
    if xblock_info["visibility_state"] == VisibilityState.staff_only:
        xblock_info["staff_lock_from"] = _get_staff_lock_from(xblock)
    else:
        xblock_info["staff_lock_from"] = None
Ejemplo n.º 4
0
    def test_sequential_and_problem_have_group_access(self):
        """ Tests when group_access is set on a few different components. """
        self.set_group_access(self.sequential, {1: [0]})
        # This is a no-op.
        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))

        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))
Ejemplo n.º 5
0
 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))
Ejemplo n.º 6
0
 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))