Skip to content

Fix versioned URLs for XBlock handlers in v2 runtime [FC-0062] - #35676

Merged
bradenmacdonald merged 5 commits into
openedx:masterfrom
open-craft:braden/fix-handler-versioned-urls
Oct 21, 2024
Merged

Fix versioned URLs for XBlock handlers in v2 runtime [FC-0062]#35676
bradenmacdonald merged 5 commits into
openedx:masterfrom
open-craft:braden/fix-handler-versioned-urls

Conversation

@bradenmacdonald

@bradenmacdonald bradenmacdonald commented Oct 18, 2024

Copy link
Copy Markdown
Contributor

Fixes #35673

Handlers weren't working in some cases if the handler URL contained a query string, due to assumptions made in the capa XBlock JS (and probably others).

This PR moves the version specifier into the URL path, instead of the query string. Also made some other cleanups.

How to test:

  1. Create a multiple choice problem in a library and copy it
  2. Paste it into a course
  3. Edit the problem and publish the changes
  4. Press the "update" button in the course, and see the comparison modal.
  5. Try submitting the question in the comparison modal. With the fixes from this PR, it should work.

Screenshot

@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @bradenmacdonald!

What's next?

Please work through the following steps to get your changes 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.

🔘 Let us know that your PR is ready for review:

Who will review my changes?

This repository is currently maintained by @openedx/wg-maintenance-edx-platform. Tag them in a comment and let them know that your changes are ready for review.

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.

@bradenmacdonald
bradenmacdonald force-pushed the braden/fix-handler-versioned-urls branch from 8d10909 to ea7b049 Compare October 18, 2024 20:37
@bradenmacdonald

Copy link
Copy Markdown
Contributor Author

@ormsbee Could you take a look at this when you have time, please?

msg = f"XBlock {endpoint_parameters.get('block_key')} does not exist, or you don't have permission to view it."
self.assertEqual(response.json(), {
'detail': msg,
})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because I moved the usage key parsing into Django's URL router, we still get a 404 response here but it's not a customized one for this API anymore.

@ormsbee ormsbee left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Optional suggestion–not a blocker.

raise NotFound(invalid_not_found_fmt.format(usage_key=usage_key_str)) from e

block = load_block(usage_key, request.user)
block = load_block(usage_key, request.user, version=parse_version_request(version))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[Nit, optional]: Per your earlier convention, the version param passed into this view could be renamed version_str to clarify that it hasn't been parsed yet, or you could create another URL param converter to do the translation before it invokes the view.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure - I pushed a commit with the URL param converter. I don't know if it's any cleaner than just using version_str, but I agree that doing one or the other is an improvement. Thx!

from opaque_keys.edx.keys import UsageKeyV2


class UsageKeyV2Converter:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like that you're making one of these–I think it really helps clean things up.

@bradenmacdonald bradenmacdonald added the FC Relates to an Axim Funded Contribution project label Oct 19, 2024
@bradenmacdonald
bradenmacdonald force-pushed the braden/fix-handler-versioned-urls branch from 9a166c2 to a850821 Compare October 19, 2024 16:21
@bradenmacdonald
bradenmacdonald merged commit e2d6765 into openedx:master Oct 21, 2024
@bradenmacdonald
bradenmacdonald deleted the braden/fix-handler-versioned-urls branch October 21, 2024 16:14
@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

2U Release Notice: This PR has been deployed to the edX staging environment in preparation for a release to production.

@edx-pipeline-bot

Copy link
Copy Markdown
Contributor

2U Release Notice: This PR has been deployed to the edX production environment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

FC Relates to an Axim Funded Contribution project open-source-contribution PR author is not from Axim or 2U

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

When viewing a specific version of a v2 library "problem" component, cannot submit answers

4 participants