Skip to content

Conversation

@lodewiges
Copy link
Contributor

@lodewiges lodewiges commented Jan 4, 2026

Moves to grover for pdf generation because wkhtmltopdf is EOL and doesnot support ruby 3.4.8

Fixes #843
Fix authorisation issues and download button not working

TO DO

  • fix show invoice page bold header and footer table

Summary by CodeRabbit

  • New Features

    • Added a "Download" action on the invoice list for authorized users.
    • Public token-based invoice links now return PDFs without requiring login.
  • Chores

    • Switched the app to a new PDF renderer and added its default configuration; removed the old global PDF engine setup.
    • Emailed invoices now use the new PDF renderer.
    • Minor PDF-specific stylesheet tweak.
  • Bug Fixes

    • PDF generation failures are logged and handled; emails continue sending without attachments.
    • Excluded zero-spending users from the ladder listing before sorting.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings January 4, 2026 22:05
@coderabbitai
Copy link

coderabbitai bot commented Jan 4, 2026

Warning

Rate limit exceeded

@lodewiges has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 4 minutes and 14 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 55e5a91 and 436183f.

📒 Files selected for processing (2)
  • app/controllers/zatladder_controller.rb
  • app/views/invoices/show.html.erb

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Replaces WickedPdf/wkhtmltopdf with Grover/Chromium, updates Dockerfile and package.json, centralizes PDF rendering in controller and mailer using Grover, adds download? policy and invoice download UI, adds Grover initializer, and removes a PDF-specific bold CSS rule. (50 words)

Changes

Cohort / File(s) Summary
Build & JS deps
Dockerfile, package.json
Replaced wkhtmltopdf in the build image with chromium; added puppeteer dependency to package.json.
Gems
Gemfile
Removed wicked_pdf and wkhtmltopdf-binary; added grover (~> 1.2.4).
Grover config & WickedPdf removal
config/initializers/grover.rb, config/initializers/wicked_pdf.rb
Added grover.rb initializer with default Grover options (A4, print_background, display_url); removed the global wicked_pdf.rb initializer.
Controller PDF flow
app/controllers/invoices_controller.rb
Added integer_id? helper; conditional authorization for token-based access; centralized PDF rendering in render_invoice_pdf using Grover with error handling and redirect on failure; consolidated PDF response logic.
Mailer PDF flow
app/mailers/invoice_mailer.rb
Replaced WickedPdf PDF generation with Grover.from_html on rendered HTML (layout: 'pdf'), attach PDF; added error handling/logging and fall back to send email without attachment on failure.
Authorization / UI gating
app/policies/invoice_policy.rb, app/views/invoices/index.html.erb
Added download? policy (returns true for treasurers) and conditionally added a "Download" column/link (invoice_path(invoice, format: :pdf)) in the invoices index, gated by the new policy.
Stylesheet
app/assets/stylesheets/pdf.scss
Removed CSS rule forcing td in thead/tfoot to be bold; replaced with a PDF-specific comment.
Other controller tweak
app/controllers/zatladder_controller.rb
Filters out users with zero spendings before sorting in the ladder output.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Browser
  participant Rails as InvoicesController
  participant Grover
  participant ServerResp as Server Response

  Note over User,Browser: User clicks "Download" (GET /invoices/:id.pdf)
  User->>Browser: click download link
  Browser->>Rails: GET /invoices/:id.pdf
  Rails->>Rails: integer_id? -> token_based_access?
  alt integer id (authenticated)
    Rails->>Rails: authorize `@invoice` (show?/pay?)
  end
  Rails->>Rails: render invoice HTML (layout: 'pdf')
  Rails->>Grover: Grover.from_html(rendered_html, options)
  Grover-->>Rails: PDF binary
  Rails->>ServerResp: send_data (attachment, filename: Factuur-<human_id>.pdf)
  ServerResp-->>Browser: HTTP response (PDF)
  Browser-->>User: prompt/save PDF
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 I swapped a gem and tuned a spring,
Chromium hums — Grover takes wing.
Click "Download" and watch it hop,
A PDF pops out—ready to drop.
Treasurers smile; the rabbits stop.

🚥 Pre-merge checks | ✅ 2 | ❌ 3
❌ Failed checks (3 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete and does not follow the template structure; it lacks proper sections (Summary with fixes reference, Checklist for migrations, Other information). Restructure the description to follow the template with explicit Summary, Checklist, and Other information sections; include 'fixes #843' to auto-close the issue.
Out of Scope Changes check ⚠️ Warning The zatladder_controller.rb change to filter zero spendings appears unrelated to PDF generation or invoice download requirements; it is out of scope. Remove the zatladder_controller.rb change or move it to a separate pull request focused on zatladder filtering improvements.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: migrating to Grover for PDF generation and adding a dedicated download button for invoices.
Linked Issues check ✅ Passed The code changes successfully implement issue #843 requirements: added download button (index.html.erb, invoice_policy.rb), replaced wkhtmltopdf with Grover, and implemented download flow.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR migrates the PDF generation system from WickedPDF (using wkhtmltopdf) to Grover (using Chrome/Chromium) and adds a dedicated download button for invoices in the invoice list view.

  • Replaced WickedPDF with Grover for PDF generation throughout the application
  • Added a dedicated "Download" button column to the invoice index table with proper authorization
  • Updated the Dockerfile to use Chromium instead of wkhtmltopdf

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
config/initializers/wicked_pdf.rb Removed WickedPDF configuration (entire file deleted)
config/initializers/grover.rb Added Grover configuration with A4 format, background printing, and display URL settings
app/views/invoices/index.html.erb Added download button column with authorization check using the new download policy
app/policies/invoice_policy.rb Added download? policy method restricting downloads to treasurers
app/mailers/invoice_mailer.rb Updated to use Grover for PDF attachment generation instead of WickedPDF
app/controllers/invoices_controller.rb Refactored PDF rendering to use Grover with new render_invoice_pdf and integer_id? helper methods
app/assets/stylesheets/pdf.scss Removed Bootstrap table header workaround styles (previously needed for wkhtmltopdf)
Gemfile.lock Replaced wicked_pdf and wkhtmltopdf-binary dependencies with grover and its dependencies
Gemfile Updated gem dependencies: removed wicked_pdf/wkhtmltopdf-binary, added grover
Dockerfile Replaced wkhtmltopdf with chromium and chromium-driver system packages

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

coderabbitai[bot]

This comment was marked as outdated.

@codecov
Copy link

codecov bot commented Jan 4, 2026

Codecov Report

❌ Patch coverage is 39.28571% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.08%. Comparing base (656f5a2) to head (436183f).
⚠️ Report is 9 commits behind head on staging.

Files with missing lines Patch % Lines
app/controllers/invoices_controller.rb 50.00% 10 Missing ⚠️
app/mailers/invoice_mailer.rb 0.00% 5 Missing ⚠️
app/controllers/zatladder_controller.rb 0.00% 1 Missing ⚠️
app/policies/invoice_policy.rb 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           staging    #1194      +/-   ##
===========================================
- Coverage    77.62%   77.08%   -0.55%     
===========================================
  Files           54       54              
  Lines         1341     1370      +29     
===========================================
+ Hits          1041     1056      +15     
- Misses         300      314      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

coderabbitai[bot]

This comment was marked as outdated.

coderabbitai[bot]

This comment was marked as outdated.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (1)
app/controllers/invoices_controller.rb (1)

93-105: DRY violation: PDF generation duplicated in mailer.

As noted in past reviews, PDF generation logic (rendering template with Grover) is duplicated between this controller method and InvoiceMailer. Consider extracting to a shared service or helper to ensure consistency and maintainability.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5b9fe02 and 0cd8da2.

📒 Files selected for processing (1)
  • app/controllers/invoices_controller.rb
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Lint
🔇 Additional comments (4)
app/controllers/invoices_controller.rb (4)

5-5: LGTM! Exception list correctly includes show.

The verify_authorized exception list now includes show, which correctly allows token-based access in the show action without triggering authorization errors.


18-21: LGTM! Token-based access detection and conditional authorization implemented correctly.

The logic properly distinguishes between token-based access (which skips authorization) and integer ID access (which requires authorization). The implementation correctly handles both access patterns.


25-25: LGTM! Parameter removal addressed past review feedback.

The call to render_invoice_pdf correctly omits the unused parameter, as addressed in the previous review.


76-81: LGTM! Clean implementation of integer ID detection.

The helper method uses idiomatic Ruby with Integer() and exception handling to distinguish between integer IDs and token-based access. The implementation is correct and readable.

@lodewiges lodewiges added the prio label Jan 14, 2026
@lodewiges lodewiges removed the prio label Jan 16, 2026
@lodewiges lodewiges merged commit fb90056 into staging Jan 16, 2026
4 of 6 checks passed
@lodewiges lodewiges deleted the refractor/pdf-generation branch January 16, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add "factuur downloaden" button to generate a PDF and let the user download it

2 participants