Skip to content

Plugin system: sale document view hooks and a webhook CSRF exemption - #4605

Merged
objecttothis merged 2 commits into
opensourcepos:plugin-system-freshfrom
joshua1234511:feature/plugin-sales-doc-hooks
Jul 28, 2026
Merged

objecttothis merged 2 commits into
opensourcepos:plugin-system-freshfrom
joshua1234511:feature/plugin-sales-doc-hooks

Conversation

@joshua1234511

Copy link
Copy Markdown
Contributor

The plugin system can inject content into the sales receipt, but the invoice, quote and work order views have no hook point, so a plugin that delivers sale documents can only reach one of the four. Plugins also have no way to expose an inbound provider webhook, because a server-to-server callback carries no CSRF token and the global csrf filter has no plugin-safe exemption — leaving a core edit as the only option, which is what the plugin system exists to avoid.

This adds view:sales_invoice_buttons, view:sales_quote_buttons and view:sales_work_order_buttons — same position and same ['saleId' => ...] payload as the existing receipt hook — and exempts the plugins/*/webhook path from CSRF, with the plugin responsible for authenticating the caller itself. Documented in app/Plugins/README.md. Groundwork for the WhatsApp plugin, but not specific to it.

Plugins can already inject buttons into the receipt via
view:sales_receipt_buttons, but the invoice, quote and work order views have
no hook point, so a plugin that delivers sale documents can only reach one of
the four. Add the matching hooks, keeping the same name/data shape:

  view:sales_invoice_buttons
  view:sales_quote_buttons
  view:sales_work_order_buttons

Each passes ['saleId' => $sale_id_num] and sits in the same position as the
existing receipt hook, so one plugin callback can serve all four and branch on
the document type.

Also allow a plugin to expose an inbound provider webhook. A server-to-server
delivery carries no CSRF token and no session, so the global csrf filter now
excludes the pattern plugins/*/webhook. Plugins are responsible for
authenticating such requests themselves (typically by verifying the provider's
signature header against a shared secret) — this is documented alongside the
change.

While editing that line, the except list becomes an array. CodeIgniter matches
every entry as \A<pattern>\z, so the previous 'login|migrate' string produced a
single pattern whose inner alternatives were unanchored: 'login/anything' was
CSRF-exempt. Listing the entries separately anchors each one, which closes that
and keeps the new plugin pattern tight — plugins/whatsapp/webhook is exempt
while plugins/whatsapp/send is not.
@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d04fb146-e0fa-4e36-bd22-394627a0631e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@objecttothis objecttothis 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.

Just the comments IMO. Fix those and I'll approve/merge the code.

Comment thread app/Config/Filters.php Outdated
'before' => [
'honeypot',
'csrf' => ['except' => 'login|migrate'],
// Listed as an array rather than a pipe-delimited string so each entry is

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 change is fine as long as an array is acceptable for CI4. No need to comment it though, so let's remove the comments.

Comment thread app/Config/Filters.php Outdated
// string form 'login|migrate' produced one pattern whose inner alternatives
// were unanchored and matched far more than intended.
//
// 'plugins/*/webhook' lets a plugin expose an inbound provider callback.

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.

It makes sense why we would need to add the exception for plugins/*/webhook so as the folder notation is understood by CI4 then it's fine, but we don't need the comments to remain in the code so let's remove those.

@objecttothis
objecttothis merged commit 6bdeb4f into opensourcepos:plugin-system-fresh Jul 28, 2026
2 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants