Add PDF Download endpoint#1568
Merged
Merged
Conversation
aba940a to
62afa91
Compare
|
Coverage report for commit: 9c3aae0 Summary - Lines: 92.96% | Methods: 88.24% | Branches: 81.37%
🤖 Jest coverage report |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1c1b36f to
c212b92
Compare
|
Coverage report for commit: 9c3aae0 Summary - Lines: 82.29% | Methods: 88.67%
🤖 PHPUnit coverage report |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
c212b92 to
8190f40
Compare
1c06676 to
f58e5ad
Compare
6fddabc to
614b312
Compare
Add a REST endpoint (gravity-pdf/v1/download/<entry>/<pdf>) that generates and returns a PDF for a Gravity Forms entry as base64-encoded data, with capability- and entry-owner-based access control and HAL links. Wire the controller into the Router and add PHPUnit coverage for route registration, permissions (anonymous, non-owner, owner, restrict_owner) and generation. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
614b312 to
9c3aae0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a new REST endpoint that generates an entry's PDF on demand. The document can be returned inline (base64) or as a short-lived signed URL that streams the file — so integrations can fetch a finished PDF without going through the browser-based download links.
Endpoint
<entry>— the Gravity Forms entry ID (validated against the form database).<pdf>— the 13-character PDF ID (validated against the entry's active PDFs).POST — request the PDF
Body parameters:
typebase64|urlbase64urlExpirytype=url. A relative time string ("30 minutes","2 hours"). Falls back to the global signed-URL timeout (logged_out_timeout) when omitted or invalid.type=base64(default) returns the document inline:{ "filename": "example.pdf", "size": 12345, "data": "<base64-encoded PDF>" }type=urlgenerates and caches the PDF, then returns a signed proxy URL instead of the bytes:{ "filename": "example.pdf", "size": 12345, "url": "https://site/wp-json/gravity-pdf/v1/download/<entry>/<pdf>?expires=…&signature=…" }The response also includes HAL
_links(self,pdf, and — when the Gravity Forms REST API v2 is enabled — directformandentrylinks).GET — the signed-URL proxy
The
urlreturned above points back at the same route viaGET. The signature acts as the bearer token: the request is authorised purely by verifying the signature and expiry (reusing the sameHelper_Url_Signerinfrastructure as Gravity PDF's front-end signed PDF links), then the PDF is streamed to the browser as a download. No login is required, which is what makes the URL shareable.Access control (POST)
A request is authorised if either:
created_by), and owner access has not been disabled via the PDF's "Restrict Owner" setting.Otherwise the request is rejected.
Supporting changes
Rest_Form_Settings— exposes theid,form,activeand per-group setting fields in theembedcontext as well asedit, so the new endpoint's embeddedpdflink returns useful data. Also switches a couple of direct\GFAPI::calls to the injected$this->gformhelper for consistency and testability.Rest_Pdf_Preview— same\GFAPI::→$this->gformswap.Model_PDF::set_watermark_font()— falls back to the global default font when neither a watermark font nor a form font is set, instead of triggering an "undefined array key" warning during PDF generation.bootstrap.php— registers the newRest_Download_Pdfcontroller (now also wired withHelper_Url_Signer).Testing instructions
POSTtogravity-pdf/v1/download/<entry>/<pdf>and confirm a JSON payload whose decodeddatabegins with%PDF-.POSTthe same route with{"type":"url"}and confirm aurlis returned containingexpiresandsignature. Open it in a browser and confirm the PDF downloads. Wait past the expiry (or pass a shorturlExpirylike"1 second") and confirm the link is then rejected.POSTsucceeds — and fails once the PDF's "Restrict Owner" option is enabled.POSTis rejected, and that a tampered/expired signed URL is rejected onGET.400validation error.Automated coverage lives in
tests/phpunit/integration/Rest/Test_Rest_Download_Pdf.php(route registration, the permission matrix, base64 + url generation, and signed-URL verification).Checklist: