Skip to content

fix: close the Poll gaps from the built-in block - #364

Open
irfanuddinahmad wants to merge 1 commit into
openedx:mainfrom
irfanuddinahmad:irfanuddinahmad/poll-leftovers
Open

irfanuddinahmad wants to merge 1 commit into
openedx:mainfrom
irfanuddinahmad:irfanuddinahmad/poll-leftovers

Conversation

@irfanuddinahmad

Copy link
Copy Markdown
Contributor

Summary

Why it's needed: openedx/openedx-platform#38744 removes the built-in Poll block, which is the only fallback for these issues today, so it merges after this is released.

Changes

#363 item Fix
1. Poll renders empty when the question or an answer has an HTML attribute, < or & poll.html no longer uses |safe on the configuration JSON, so Django escapes it; poll.js reads and writes it with .text(). As in the built-in block, the question renders as HTML and answers as plain text.
2. CSS restyles other blocks; the scoped half never applies poll.css is the built-in stylesheet with its .xmodule_display.xmodule_PollBlock div.poll_question scope replaced by the block's own root, div.poll_question
3. Reset isn't guarded handle_reset_state refuses ({"error": "Unknown Command!"}, as the built-in did) unless the learner has voted and the OLX doesn't set reset="false"

Not changed (smaller differences from the built-in, left for a follow-up if wanted): the "XML data format changed" error when the answer list no longer matches stored votes, and display_name's default ("poll_question" instead of none).

Test plan

  • 6 new tests in src/xblock_poll_question/tests/test_poll.py. 5 fail on main; test_reset_after_vote checks the happy path, which already worked.

    • test_configuration_json_survives_html renders student_view with a link, < and &, and parses the hidden div's text the way poll.js does.
    • test_reset_after_vote, test_reset_without_vote, test_reset_disabled.
    • test_js_reads_configuration_as_text, test_css_rules_are_scoped_to_the_block.
  • pytest src: 870 passed. ruff check, ruff format --check and pylint src/xblock_poll_question are clean.

  • Live in a local Tutor (platform master, xblocks-core 4.0.0 with this PR's four Poll files on top; Poll is unchanged between 4.0.0 and main), as a learner, in a unit with a plain poll, a poll whose question has a link, and a Problem:

    Stock This PR
    Poll with a link in the question Empty Question and both answers
    Problem's <p> in the same unit font-weight: 700, text-align: justify 400, left
    Vote, then "Change your vote" Works Works (stats show, then reset)
Stock This PR
stock this PR

Closes #363. Part of the Slash-n-Burn Built-In XBlocks epic.

🤖 Generated with Claude Code

- Escape the configuration JSON in the template and read it with .text()
  in poll.js. A question or answer with an HTML attribute, "<" or "&"
  broke JSON.parse, and the poll rendered empty.
- Show answers as plain text and the question as HTML, as the built-in
  block did.
- Restore the built-in stylesheet scoped to the block's root
  (div.poll_question). The unscoped copy made every <p> on the page bold
  and justified, and the scoped copy targeted the XModule wrapper, which
  the extracted block doesn't have.
- Only reset a vote when the learner has voted and the poll allows it
  (reset="false"), as the built-in block did. Resetting before voting
  raised a KeyError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@openedx-webhooks openedx-webhooks added open-source-contribution PR author is not from Axim or 2U core contributor PR author is a Core Contributor (who may or may not have write access to this repo). labels Dec 4, 2026
@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @irfanuddinahmad!

This repository is currently maintained by @openedx/axim-engineering.

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.

Details
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.

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

Labels

core contributor PR author is a Core Contributor (who may or may not have write access to this repo). open-source-contribution PR author is not from Axim or 2U

Projects

Status: Needs Triage

Development

Successfully merging this pull request may close these issues.

Poll: empty render for questions with HTML attributes, unscoped CSS, unguarded reset

2 participants