Repository navigation
fix(app): prevent uninstall of apps required by billing - #4924
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughApp uninstall now uses synchronous lifecycle hooks. The billing validator blocks removal when active billing profiles or non-final invoices reference the app. Deletion and deletion-event publication are sequenced around a transaction, with Stripe and invoice snapshot integration tests. ChangesApp uninstall lifecycle
Estimated code review effort: 4 (Complex) | ~45 minutes Mergeability Score: ⚪ Minimal · up to The PR adds transactional billing checks that prevent uninstalling apps still needed by non-final invoices or active billing profiles, with regression coverage for the affected flows. No actionable merge-blocking risk remains beyond normal checks and review. Possibly related PRs
Suggested labels: Sequence Diagram(s)sequenceDiagram
participant AppHTTPDriver
participant AppService
participant BillingAppUninstallValidator
participant BillingService
AppHTTPDriver->>AppService: UninstallApp
AppService->>BillingAppUninstallValidator: Handle(LifecycleEvent)
BillingAppUninstallValidator->>BillingService: IsAppUsed(app ID)
BillingService-->>BillingAppUninstallValidator: usage result
BillingAppUninstallValidator-->>AppService: validation result
AppService->>AppService: delete in transaction
AppService-->>AppHTTPDriver: result after commit
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ 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 |
20c0efe to
3cd4bc1
Compare
3cd4bc1 to
8ec918a
Compare
Summary
Root cause
App usage validation lived at the HTTP boundary, so service-level uninstall callers could bypass it. The invoice usage query also enumerated selected active statuses and omitted draft states. After a billing profile was replaced or deleted, its draft invoices still owned snapshotted app references, but those references did not prevent the Stripe app from being uninstalled. Later invoice advancement then failed while resolving the missing app.
The guard now runs at the app service boundary before provider resources are removed, and billing blocks on every non-final standard invoice instead of maintaining an incomplete active-state allowlist.
Impact
Apps required to complete non-final invoices cannot be uninstalled. Once the referencing invoices reach a final state, uninstall is allowed again.
Validation
POSTGRES_HOST=127.0.0.1 go test -tags=dynamic ./test/billing ./test/app/stripe -count=1make lint-go-fastfor affected packagesmake lint-go-stylefor affected packagesmake lint-goContext
Maintenance follow-up to #4923. No Jira ticket.
Summary by CodeRabbit
New Features
Bug Fixes
Tests
Greptile Summary
The PR moves billing app-usage enforcement into the app service’s transactional uninstall lifecycle and protects apps referenced by active profiles or non-final standard invoices.
Confidence Score: 5/5
The PR appears safe to merge because no blocking failure remains within the eligible follow-up-review scope.
No blocking failure remains.
Important Files Changed
Sequence Diagram
sequenceDiagram participant Caller participant AppService participant Hooks participant Billing participant Provider participant Database Caller->>AppService: UninstallApp(app ID) AppService->>Database: Begin transaction and load app AppService->>Hooks: Invoke uninstall lifecycle event Hooks->>Billing: IsAppUsed(app ID) Billing->>Database: Check active profiles and non-final invoices alt App is referenced Billing-->>Hooks: Conflict Hooks-->>AppService: Veto uninstall AppService->>Database: Roll back AppService-->>Caller: Conflict else App is unused Billing-->>Hooks: Allowed AppService->>Provider: Remove provider resources AppService->>Database: Soft-delete app and commit AppService-->>Caller: Success endReviews (4): Last reviewed commit: "refactor(app): generalize lifecycle hook" | Re-trigger Greptile
Context used (3)