fix: correct upstream field for migrated libraries
This is to fix an issue in the following common migration situation:
- An existing course references content in a legacy content library.
- The legacy content library is migrated to the new library system.
- The user clicks on "Update reference" from the Randomized Content Block in the course.
This action is supposed to update the children of the LibraryContentBlock (usually ProblemBlocks) so that the "upstream" attribute is set to point at the UsageKeys of the content in the new libraries they were migrated to. What was happening instead was that the upstream entries for these child blocks were left blank, breaking the upstream/sync connection and making it so that the courses did not receive any updates from the migrated libraries.
There were two issues:
- get_forwarding_for_blocks() was being called with the child UsageKeys in the course, when it should have been called with the v1 library usage keys instead (since those are the things being forwarded).
- We were checking that the target_key was a v2 Library key, but really the upstream target_key is supposed to be a LibraryUsageLocatorV2, i.e. the key of the specific piece of content, not the library it ended up in.
Fixes #37802
I still need to write a test for this, and test a bit more to make sure it's otherwise functioning as expected.
@kdmccormick: Please take a look at this when you get back from PTO. I'm not sure what the best way to write tests for this is. The release has been delayed until 1/8 at the earliest, so I'm going to park this here and come back to it after I'm back from PTO. If you want to take it over at that point, you're more than welcome to.