Repository navigation
Plugin system: sale document view hooks and a webhook CSRF exemption - #4605
Conversation
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.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
objecttothis
left a comment
There was a problem hiding this comment.
Just the comments IMO. Fix those and I'll approve/merge the code.
| 'before' => [ | ||
| 'honeypot', | ||
| 'csrf' => ['except' => 'login|migrate'], | ||
| // Listed as an array rather than a pipe-delimited string so each entry is |
There was a problem hiding this comment.
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.
| // 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. |
There was a problem hiding this comment.
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.
6bdeb4f
into
opensourcepos:plugin-system-fresh
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.