[BB-112] Fix the order randomization behaviour of Randomized Content Block

Description

This PR (supersedes PRs #23265, #20723, #18675 which were merged and then reverted due to issues) contains changes to the Randomized Content Block XBlock. The XBlock has unpredictable randomization of the order of the selected child blocks due to the usage of sets, which are unordered, for storing the selected blocks. This becomes apparent when all the available child blocks in a library are chosen for a Randomized Content Block to randomize just the order of the child blocks.

This PR modifies the XBlock to store the selected child blocks in a list after randomly shuffling them.

The `ContentLibraryOrderTransformer`, a new block structure transformer added in this PR, uses the order of the selections made in the existing `ContentLibraryTransformer` to re-order the blocks. However, as other transformers affecting the block structure (like those used for content type gating, visibility etc.) can run after the `ContentLibraryTransformer` and before the `ContentLibraryOrderTransformer` and modify the block structure to make the stored selections invalid, the `ContentLibraryOrderTransformer` transforms the order only when the stored selections and the current children of the randomized content block match. Otherwise, it just logs an informational message when this happens.

*JIRA tickets*: None

*Dependencies*: None

*Sandbox URL*: TBD

*Merge deadline*: None

*Testing instructions*:
1. Login to the CMS as a user who can create and edit courses.
1. Create a library with a few child components.
1. Add a unit to a course.
1. Add a Randomized Content Block to the unit.
1. Select the library created above as the source for this XBlock.
1. Select all types of children to be shown.
1. Specify the total number of components present in the library as the number of components to display.
1. Save the unit and publish it.
1. Register a few students to this course.
1. Navigate to the unit containing this Randomized Content Block.
1. Verify that the order of the content blocks are randomized for every student.
1. Also verify that the same order of children blocks is returned by the `course_blocks` API for that randomized content block.
1. Add some type of content gating/visibility changes to make the randomized content block hidden from the test user.
1. Verify that there are no exceptions thrown when the LMS returns the block structure for that user - for example, when opening the course outline page. Also verify that the expected hidden blocks stay hidden.

*Reviewers*

  • [ ] @kaizoku

  • [ ] edX reviewer[s] TBD (@ormsbee maybe?)

Assignee

Braden MacDonald

Reporter

Open Source Pull Request Bot

Contributor Name

Guruprasad Lakshmi Narayanan

Repo

edx/edx-platform

Customer

Epic Link

None

OSCM Assignee

None

Platform Map Area (Levels 1 & 2)

Educator Experiences - Content Blocks & interactives

Platform Map Area (Levels 3 & 4)

None

Blended Hour Utilization Percentage

None

Priority

Unset
Configure