Repository navigation
fix(home): show Cancel button for own scheduled purchases - #1421
Conversation
Standard users with cancel-own:purchases could not cancel their own upcoming purchases from the Home page widget because: 1. The backend deletePlannedPurchase handler required delete:purchases (a management verb) as its entry gate, which Standard users do not hold. Only cancel-own:purchases is in their default permission set. 2. The frontend canCancelUpcomingPurchase checked delete:purchases as a necessary gate before allowing the creator-scope path, so Standard users never saw the Cancel button even for rows they created. Backend: add requireDeleteOrCancelPurchasePermission (accepts delete:purchases, cancel-any:purchases, or cancel-own:purchases) and authorizePlannedPurchaseCancel (extends authorizeExecutionManagement to also accept cancel-any as a full-scope grant). deletePlannedPurchase now uses these in place of the old requirePermission + authorizeExecution- Management pair, keeping all existing behavior intact. Frontend: canCancelUpcomingPurchase now grants full-scope access to admin/cancel-any/update-any, and creator-scope access to delete:purchases OR cancel-own:purchases holders who match the row's created_by_user_id. The original ownership semantics for delete:purchases holders are preserved. Tests added: - backend: TestHandler_deletePlannedPurchase_CancelOwn_Creator_Allowed, TestHandler_deletePlannedPurchase_CancelOwn_NonCreator_Rejected (handler_purchases_test.go) - backend: two cancel-own sub-tests in TestDeletePlannedPurchase_ PermissionGate (router_660_permission_flips_test.go) - frontend: "Dashboard upcoming-purchase cancel-own gating (issue #1400)" describe block with 4 cases in dashboard-ownership-950.test.ts Closes #1400
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 41 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
Merged to main after independent adversarial review (verdict SHIP, fail-before/pass-after verified) + all CI green; closes #1400. Standard users can cancel their OWN scheduled purchases on the Home page (backend gate now accepts cancel-own with a server-side ownership check; non-owner 403). |
… page (closes #1442) (#1443) canDisablePlan in plans.ts required delete:purchases, which Standard users do not hold. PR #1421 updated the backend (deletePlannedPurchase) and the Home-page widget (canCancelUpcomingPurchase) to accept cancel-own:purchases, but the Plans-page Disable-button gate was not updated. The creator's canManagePurchase was already true via canManageScheduledPurchase; only the verb check was wrong. Accept cancel-own:purchases and cancel-any:purchases alongside delete:purchases in canDisablePlan, mirroring the backend requireDeleteOrCancelPurchasePermission gate and the dashboard canCancelUpcomingPurchase logic from PR #1421. Regression tests added to plans-ownership-950.test.ts: - Creator with cancel-own (no delete) sees Disable on their own row - Non-creator with cancel-own does not see Disable (ownership gate holds) - Legacy NULL-creator row shows no Disable for cancel-own user - cancel-any creator also sees Disable (backend supports it)
…ion check (#1491) requireDeleteOrCancelPurchasePermission hand-rolled its own auth dispatch (admin API key -> session) and dropped the user-API-key branch that every other permission gate relies on via requirePermission/authorizeAPIKey. Scoped API-key automation clients presenting only an x-api-key header got a 401 "no authorization token provided" instead of being authorized against their key's granted verbs, even when the key held delete:purchases. Add requireAnyPermission/authorizeAPIKeyAny as the multi-verb counterparts to the existing requirePermission/authorizeAPIKey dispatch chain, and delegate requireDeleteOrCancelPurchasePermission to it so the delete/cancel gate cannot drift from the single-verb dispatch order used everywhere else. Also widen the verb set to include update-any so a custom group holding only that permission clears this entry gate before ownership is checked. Follow-up to #1421, which introduced the hand-rolled gate. Also updates a pre-existing sibling test (TestDeletePlannedPurchase_PermissionGate) whose mock set predates the update-any verb addition.
Summary
cancel-own:purchasescould not cancel their own upcoming purchases from the Home page "Upcoming Scheduled Purchases" widget even though the backend supports creator-scope cancel (closes ux(home): Standard user cannot cancel own scheduled purchases from Home page #1400)deletePlannedPurchaserequireddelete:purchasesas its entry gate; Standard users holdcancel-own:purchases(notdelete:purchases), so the endpoint returned 403 for themcanCancelUpcomingPurchasegated ondelete:purchasesbefore allowing the creator-scope path, so Standard users never saw the Cancel button for their own rowsChanges
Backend (
internal/api/handler_purchases.go)requireDeleteOrCancelPurchasePermission: new entry-gate helper acceptingdelete:purchases,cancel-any:purchases, orcancel-own:purchasesauthorizePlannedPurchaseCancel: new ownership-check function (replacesauthorizeExecutionManagementin the delete path) that acceptsupdate-anyorcancel-anyfor full-scope and creator-match for creator-scope; cyclomatic complexity kept at 10Frontend (
frontend/src/dashboard.ts)canCancelUpcomingPurchase: full-scope viaadmin:*/cancel-any/update-any; creator-scope viadelete:purchasesORcancel-own:purchases+ creator match; original ownership semantics fordelete:purchasesholders are preservedTests
TestHandler_deletePlannedPurchase_CancelOwn_Creator_Allowed,TestHandler_deletePlannedPurchase_CancelOwn_NonCreator_Rejectedinhandler_purchases_test.gocancel-ownsub-tests inTestDeletePlannedPurchase_PermissionGateinrouter_660_permission_flips_test.godashboard-ownership-950.test.tsunder "Dashboard upcoming-purchase cancel-own gating (issue ux(home): Standard user cannot cancel own scheduled purchases from Home page #1400)"Test plan
go build ./...exit 0go vet ./...exit 0go test ./internal/api/...1665 passed, exit 0-over 10on touched files: exit 0 (no new violations)--new-from-rev=origin/main: 0 new issues