Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: static assets in problem bank and library content block #36173

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

DanielVZ96
Copy link
Contributor

Description

Handles static asset sync when creating or refreshing library content and problem bank components to a unit.

This is done through refactoring the logic already in place in the staged content app which implemented generic logic for the clipboard feature.

Supporting information

Testing instructions

  1. create a text library component

  2. upload an image either in the advanced tab or directly in the text editor

  3. if uploaded in the advanced tab, add it to the component html

  4. Publish the component

  5. Now in the cms add a new library v2 component referencing the text component above.

  6. Assert it renders the image.
    image

  7. Repeat the steps above with the problem bank component

image

Deadline

ASAP

Other information

@openedx-webhooks
Copy link

openedx-webhooks commented Jan 25, 2025

Thanks for the pull request, @DanielVZ96!

This repository is currently maintained by @openedx/wg-maintenance-edx-platform.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.

🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads

🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.


Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Jan 25, 2025
@DanielVZ96
Copy link
Contributor Author

@ormsbee @bradenmacdonald here's the fix for static assets not being synced from libraries v2 to a library/bank component. it took me some time to figure out a clean way to reuse staged content. my only gripe is that my implementation almost unnecessarily creates a user library sync record. but it's there because all the code in content staging expects a model that relates a component to multiple staged contents. I think it could be ok because in the future it can enable other metadata for the library sync process.

I'm currently working on linting and testing but the overall idea is implemented in case you want to review it.

@DanielVZ96 DanielVZ96 force-pushed the dvz/fix-library2-static branch from 77c8103 to 3355545 Compare January 27, 2025 12:24
@DanielVZ96 DanielVZ96 force-pushed the dvz/fix-library2-static branch from 3355545 to f12ff12 Compare January 27, 2025 12:30
Copy link
Contributor

@bradenmacdonald bradenmacdonald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some suggestions for simplifying this. I'm worried that making this code too specific to "library sync" is going to be really confusing for people coming later and trying to figure out where the library sync code is when we have the upstream/downstream code in edx-platform, this "library sync" code for assets only, and openedx/openedx-learning#269 for tracking links.

I'm also not sure that using StagedContent is worth the extra time for copying all the files and creating the staged content. Is the algorithm for finding static asset references in staged content and copying those referenced files into "Files & Uploads" really more complex than all the changes that are in this PR?

cms/djangoapps/contentstore/helpers.py Outdated Show resolved Hide resolved
cms/djangoapps/contentstore/helpers.py Outdated Show resolved Hide resolved
cms/djangoapps/contentstore/helpers.py Outdated Show resolved Hide resolved
cms/djangoapps/contentstore/helpers.py Outdated Show resolved Hide resolved
openedx/core/djangoapps/content_staging/models.py Outdated Show resolved Hide resolved
openedx/core/djangoapps/content_staging/api.py Outdated Show resolved Hide resolved
@DanielVZ96 DanielVZ96 force-pushed the dvz/fix-library2-static branch from ecdc8dc to 5a9b68f Compare January 29, 2025 12:13
Comment on lines +664 to +665
# The file already exists and matches exactly, so no action is needed except substitutions
return None, {clipboard_file_path: f"static/{import_path}"}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

library sync was failing when updating downstream blocks with the following button
image

Copy link
Contributor

@bradenmacdonald bradenmacdonald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for those changes. I think this is looking much simpler and nicer!

I do have one more request, though it can come in a separate PR if you want: because creating StagedContent is potentially slow, I think that as an optimization, we should skip the whole [stage xblock -> insert static assets] workflow entirely if the upstream component doesn't have any associated static assets.

FYI @ormsbee and @kdmccormick on this new use of Staged Content / modification of upstream-downstream syncing.

cms/djangoapps/contentstore/helpers.py Outdated Show resolved Hide resolved
cms/djangoapps/contentstore/helpers.py Outdated Show resolved Hide resolved
openedx/core/djangoapps/content_staging/api.py Outdated Show resolved Hide resolved
cms/djangoapps/contentstore/helpers.py Outdated Show resolved Hide resolved
Comment on lines 351 to 354
if not XBlockSerializer(
lib_block,
fetch_asset_data=True,
).static_files:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not XBlockSerializer(
lib_block,
fetch_asset_data=True,
).static_files:
if not lib_block.runtime.get_block_assets(lib_block, fetch_asset_data=False):
# This block doesn't have any static asset files for us to worry about.

@bradenmacdonald
Copy link
Contributor

Thanks for addressing all my concerns so quickly @DanielVZ96 :) I will test this tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Status: In Eng Review
Development

Successfully merging this pull request may close these issues.

Copy static assets when using a library component in a course (via Problem Bank or Library Content)
3 participants