Skip to content

fix: SCO-173 gate order menu items to what the server allows - #397

Merged
scottcarlton merged 1 commit into
devfrom
fix/sco-173-gate-clone-order
Oct 29, 2026
Merged

scottcarlton merged 1 commit into
devfrom
fix/sco-173-gate-clone-order

Conversation

@scottcarlton

Copy link
Copy Markdown
Owner

Summary

  • New orderMenuItems predicate (src/lib/utils/order-menu-permissions.ts) decides which "More actions" items the order detail page offers, each mirroring its server rule:
    • Clone: own-org only, writing roles (loadOwnOrgOrder + ORDER_WRITE_ROLES). Hidden for buyers, guests, and federated viewers.
    • Download PDF: own-org or federated, ORDER_PDF_ROLES. Hidden for buyers and guests.
    • Cancel: RLS-backed client update. Own-org writing roles; federated admin/owner only (Brand admin updates federated order status); never buyers (their policy's WITH CHECK only allows draft/submitted).
  • The clone and PDF endpoints now read their role sets from the same modules, so the UI and server can't drift.
  • The trigger hides when no item is left, instead of opening an empty menu.
  • Cancel now toasts an error when RLS refuses the update; before, it closed the dialog and silently did nothing.

Why

The menu offered every action to every viewer, so buyers, guests, and federated viewers saw actions guaranteed to fail. The ticket's open question (should buyers clone?) is settled by the server: the clone endpoint already 404s for buyers, and buyer re-order belongs to the cart path in SCO-168.

Sibling audit

  • Return entry is resolved server-side by resolveReturnEntry and is role-blind, as is the /returns/new action. That's a server gap, filed as SCO-213.

Verification

  • bun run lint passes
  • bun run check passes (0 errors)
  • bun run test:run: 2046 pass, including 16 new tests for orderMenuItems. The 10 local recent-searches failures are pre-existing (Node v26 localStorage) and pass in CI.
  • Not exercised in the browser as a buyer, guest, and sales member: no seeded accounts for each role locally.

Test plan

  • Open /orders/[id] as a guest: no "More actions" button (unless a return entry applies).
  • As a buyer: no Clone, PDF, or Cancel.
  • As a brand admin on a federated rep order: PDF and Cancel, no Clone. As brand sales on the same order: PDF only.
  • As own-org sales: Clone, PDF, and Cancel; Cancel disappears once shipped.

Closes SCO-173

🤖 Generated with Claude Code

The order detail "More actions" menu offered Clone, Download PDF, and
Cancel to every viewer, so buyers, guests, and federated viewers saw
actions guaranteed to fail. A new orderMenuItems predicate mirrors each
action's server rule, the clone and PDF endpoints now read their role
sets from the same place, and the trigger hides when no item is left.
Cancel also surfaces an error instead of failing silently when RLS
refuses the update.

SCO-173

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
threadline Ready Ready Preview Oct 29, 2026 9:50pm UTC

@scottcarlton
scottcarlton merged commit 4812c79 into dev Oct 29, 2026
8 checks passed
@scottcarlton
scottcarlton deleted the fix/sco-173-gate-clone-order branch October 29, 2026 21:53

This branch was successfully deployed

1 active deployment
Preview — 93698ba0 Deployed Oct 29, 2026 by vercel[bot]
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.

1 participant