feat(taxcode): prevent deletion of add-on-referenced tax codes#4561
feat(taxcode): prevent deletion of add-on-referenced tax codes#4561borbelyr-kong wants to merge 3 commits into
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 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 |
|
@greptileai review this draft |
Greptile SummaryThis PR introduces a pre-delete guard that prevents a tax code from being deleted while it is still referenced by add-on rate cards. It follows the same hook pattern as the existing plan-validator hook.
Confidence Score: 4/5The change is safe to merge; the core guard logic correctly blocks deletion whenever any add-on holds a live rate-card reference to the tax code. The hook and adapter filter are well-structured and closely mirror the proven plan-validator hook. The only gap is that add-ons in Invalid status (effectiveTo < effectiveFrom) are not checked, so a tax code could be deleted while a broken add-on still references it, preventing that add-on from ever being repaired. Both unit and integration tests cover the happy and blocking paths. openmeter/taxcode/service/hooks/addonhook.go — the status list in PreDelete warrants a second look Important Files Changed
|
| affectedAddons, err := e.addonService.ListAddons(ctx, addon.ListAddonsInput{ | ||
| Namespaces: []string{tc.Namespace}, | ||
| Status: []productcatalog.AddonStatus{ | ||
| productcatalog.AddonStatusActive, | ||
| productcatalog.AddonStatusDraft, | ||
| productcatalog.AddonStatusArchived, | ||
| }, |
There was a problem hiding this comment.
The
PreDelete check omits AddonStatusInvalid, unlike the plan validator hook which covers all plan statuses. An add-on enters Invalid state when effectiveTo < effectiveFrom (an already-inconsistent record), but it still holds a tax_code_id FK on its rate cards. Allowing the tax code to be deleted while such an add-on exists would deepen the inconsistency and make the add-on unrecoverable if someone later tries to fix its time range.
| affectedAddons, err := e.addonService.ListAddons(ctx, addon.ListAddonsInput{ | |
| Namespaces: []string{tc.Namespace}, | |
| Status: []productcatalog.AddonStatus{ | |
| productcatalog.AddonStatusActive, | |
| productcatalog.AddonStatusDraft, | |
| productcatalog.AddonStatusArchived, | |
| }, | |
| affectedAddons, err := e.addonService.ListAddons(ctx, addon.ListAddonsInput{ | |
| Namespaces: []string{tc.Namespace}, | |
| Status: []productcatalog.AddonStatus{ | |
| productcatalog.AddonStatusActive, | |
| productcatalog.AddonStatusDraft, | |
| productcatalog.AddonStatusArchived, | |
| productcatalog.AddonStatusInvalid, | |
| }, |
8a31078 to
7a906df
Compare
e850ada to
5946f52
Compare
2f9c5ab to
3a58a03
Compare
@coderabbitai