Skip to content

feat: gotenberg support for PDF block - #291

Open
Kelketek wants to merge 2 commits into
openedx:mainfrom
open-craft:fox/gotenberg-support
Open

Kelketek wants to merge 2 commits into
openedx:mainfrom
open-craft:fox/gotenberg-support

Conversation

@Kelketek

@Kelketek Kelketek commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

This Pull Request adds support for conversion of documents to PDF via the Gotenberg service if it is available.

Supporting information

Testing instructions

  1. Follow the instructions in the frontend-app-authoring repository and use the linked version.
  2. Install the Tutor plugin for Gotenberg linked above.
  3. Switch to the platform version linked above.
  4. Clone this repository and switch to this branch. Add it to the mounts for Tutor via tutor mounts add /path/to/xblocks-core
  5. tutor images build openedx-dev
  6. Conversion to PDF should now be enabled. Go to a course and find PDF in the advanced components. Add it. Select an office document and verify the document is auto-converted and embedded.
  7. Upload a PDF to verify that still works fine.
  8. Go to a library and do the same-- upload an office document. Verify it's auto-converted and embedded.
  9. Do it again with a PDF to verify that still works fine.

Dependencies

This PR depends on this platform PR, which must be merged first.

@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 Aug 15, 2026
@openedx-webhooks

openedx-webhooks commented Aug 15, 2026 •

Copy link
Copy Markdown

Thanks for the pull request, @Kelketek!

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.

@github-project-automation github-project-automation Bot moved this to Needs Triage in Contributions Aug 15, 2026
@Kelketek
Kelketek force-pushed the fox/gotenberg-support branch from 5005fe8 to 098edae Compare August 19, 2026 16:09
@Kelketek
Kelketek marked this pull request as draft August 19, 2026 16:11
@Kelketek Kelketek changed the title wip: gotenberg support feat: gotenberg support for PDF block Aug 19, 2026
@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Aug 19, 2026
@Kelketek
Kelketek force-pushed the fox/gotenberg-support branch 6 times, most recently from 8ec0747 to b25204b Compare August 28, 2026 00:09
Comment thread xblock_pdf/utils.py Outdated
from openedx_content import api as content_api

if not source_url.startswith("/"):
response = requests.get(source_url, timeout=(10, 120))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Shouldn't we check what URL the user sends (like scheme allowlist, the host or resolved IP and redirects)? Otherwise it could result in the same class of bug that this commit fixes in the edx-platform: openedx/openedx-platform@00b7c3ce41

Comment thread xblock_pdf/pdf.py Outdated
Checks if the current user has authoring permissions.
"""
user_service = self.runtime.service(self, "user")
permissions_service = self.runtime.service(self, "studio_user_permissions")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This doesn't work in content library v2. Only django admins get user_is_staff as true so any other library authors will get blocked.

@Kelketek Kelketek Sep 1, 2026 •

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.

Tested and verified you are correct here. It looks like the only sensible way to fix this is going to be changing how the platform handles the permissions in one or the other service. I've been in conversation with @kdmccormick about this. Thought I'd managed to side-step it, but apparently not.

Will get a PR up for that and ping you when it's ready.

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.

Noting here that the platform PR is up, for the record :)

Comment thread src/xblock_pdf/utils.py
if not (conversion_url := get_conversion_url()): # pragma: no cover
return None

pdf_response = requests.post(conversion_url, files={"file": (source_filename, data)}, timeout=(2, 120))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: Could be useful to put this in a try/except block and handle the error incase the Gotenberg container becomes unreachable for some reason.

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.

I want it to raise in that case, as that problem should be very noisy.

@Kelketek
Kelketek force-pushed the fox/gotenberg-support branch 2 times, most recently from b30117f to 4f4d1df Compare September 9, 2026 18:41
@Kelketek
Kelketek marked this pull request as ready for review September 11, 2026 18:30
Comment thread xblock_pdf/utils.py Outdated
Fetches an 'external' URL, which is only actually permitted if it's from the LMS,
and returns its byte content.
"""
if not url.startswith(settings.LMS_ROOT_URL):

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Could we strengthen this like below?

Suggested change
if not url.startswith(settings.LMS_ROOT_URL):
allowed = urlparse(settings.LMS_ROOT_URL)
target = urlparse(url)
if (target.scheme.lower(), target.netloc.lower()) != (allowed.scheme.lower(), allowed.netloc.lower()):
raise HTTPError("Unpermitted URL.")

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.

@pkulkark Done. Thanks!

@pkulkark pkulkark left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@Kelketek Just the one suggestion, otherwise LGTM 👍

  • I tested this: Verified it works as described in the testing instructions
  • I read through the code

@Kelketek
Kelketek force-pushed the fox/gotenberg-support branch 2 times, most recently from 6d27020 to f8fb66d Compare September 11, 2026 20:04
@Kelketek

Copy link
Copy Markdown
Contributor Author

@kdmccormick Could you take a look at this?

@Kelketek
Kelketek marked this pull request as draft September 18, 2026 17:56
@Kelketek

Copy link
Copy Markdown
Contributor Author

Moving to draft until a question about modifying the underlying permissions service is resolved.

@Kelketek
Kelketek marked this pull request as ready for review September 21, 2026 19:38
@Kelketek
Kelketek force-pushed the fox/gotenberg-support branch from a4167ae to 36004ef Compare October 20, 2026 00:58
@Kelketek

Copy link
Copy Markdown
Contributor Author

@kdmccormick The platform has been updated with the improved permissions service, so this is ready for review and merge if all is well.

@mphilbrick211 mphilbrick211 moved this from Waiting on Author to In Eng Review in Contributions Nov 4, 2026
@Kelketek
Kelketek force-pushed the fox/gotenberg-support branch 3 times, most recently from 5ccc0c2 to f308b57 Compare November 9, 2026 19:46

@kdmccormick kdmccormick left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this will be a cool feature. sorry to throw a bit of wrench in it.

Comment thread src/xblock_pdf/utils.py
Comment on lines +52 to +56
# pylint: disable=import-error,import-outside-toplevel
from cms.djangoapps.contentstore.asset_storage_handlers import update_course_run_asset

# pylint: disable=import-error,import-outside-toplevel
from openedx.core.djangoapps.content_libraries.api import add_library_block_static_asset_file

@kdmccormick kdmccormick Nov 9, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

external packages should not be imported from openedx-platform. I realize that the PR does it because we lack a proper add_asset API for XBlocks, but I'd much rather fix the API than pollute xblocks-core with platform dependencies.

@bradenmacdonald is currently working on a new openedx-core-based asset API, which will be implemented on a course-by-course-opt-in-basis by the Willow cutoff, and probably enabled by-default on all courses by Xylon. xblock_video could call that new API (and report "unsupported" for courses which haven't migrated to the new API). Braden, let me know if you disagree.

if that timeline isn't workable, then an alternative to unblock this PR could be:

  • add an abstract Runtime.add_asset API method to https://github.com/openedx/xblock
  • implement Runtime.add_asset for both the modulestore and library runtimes in openedx-platform
  • call self.runtime.add_asset here

I'm a little more reluctant about that, though, because anything that touches drafts/publishing/versioning ends up a bit hacky when exposed through the XBlock runtime rather than in the data stores (ie modulestore and openedx-core).

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.

@kdmccormick What about exposing it as an XBlock service, like the permissions are now, and then replacing/updating the implementation of that service as the APIs become available?

@kdmccormick kdmccormick Nov 10, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Kelketek yeah, I like that. Something like:

class AssetService:

    def add_asset_to_block(usage_key, ...): ... 

    def add_asset_to_context(context_key, ...): ...

in the current system, add_asset_to_block only would work in libraries and add_asset_to_context only would work in courses. But if you phrase the logic as "try add_asset_to_block, fall back to add_asset_to_context" then it will stay openedx-platform-agnostic and it will be future-proof for when course runs begin support block-level assets (Willow/Xylon-ish).

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.

@kdmccormick OK, I'll get started on that. Thanks!

@Kelketek
Kelketek force-pushed the fox/gotenberg-support branch from f308b57 to 14bcff9 Compare December 2, 2026 14:25
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: In Eng Review

Development

Successfully merging this pull request may close these issues.

4 participants