Repository navigation
Conversation
Any user who could open the shop admin could refund an order or change payment keys. The refund route, payment-setting changes, payment connection checks, subscription cancel and resume, and vendor payout changes now check `ctx.user.role` and answer 403 for anyone who isn't an EmDash Admin. The admin hides the refund form and greys out the payment cards for non-admins. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
moset15
force-pushed
the
feat/admin-only-money
branch
from
December 6, 2026 11:06
1310276 to
3b1e34f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
DashCommerce's admin routes don't check who is calling. EmDash's default
plugins:managepermission keeps them to Admins today, but once the shop admin is opened to Editors (a route declaring a lowerpermission, so Editors can manage orders or reviews, say), every Editor could also refund orders, change payment keys and set up vendor payouts.This keeps money admin-only, using EmDash's roles (
ctx.user.role, Admin = 50). It's the "Refunds and payment settings for admins only" item on #108.Behaviour
These now answer 403 with a plain message for anyone who isn't an Admin, including a call with no signed-in user:
admin/orders/refund.admin/settings. Other settings stay open to whoever can open the admin. An untouched masked secret counts as no change.admin/stripe/ping,admin/payments/check-connection.admin/subscriptions/action).Reading stays open: an Editor still sees orders, subscriptions, vendors and settings.
In the admin: the order page shows an Editor "Only an admin can issue refunds" instead of the refund form, and the Settings page greys out the payment cards (
_canManagePaymentson the settings response tells it).Changes
packages/core/src/routes/admin-api.ts:isAdmin,adminOnlyandisPaymentSettinghelpers; the checks above;canRefundon the order detail.packages/core/src/admin/pages/OrderDetailPage.tsx,SettingsPage.tsx: the Editor view.packages/core/README.md: a short section on who can do what.packages/core/test/helpers/route-harness.ts:ADMIN_USERandEDITOR_USER.@dashcommerce/core.Tests
packages/core/test/admin-only-money.test.ts(new): each money route refuses an Editor and a call with no user, and moves no money or saves nothing; an Admin gets through; an Editor still reads the order and changes non-payment settings.provider-*,refund-idempotency,vendor-payment-accounts, and the Paystack and Flutterwavecore-integrationtests).The new tests fail without the change. Suites run locally: core 469, paystack 106, flutterwave 137, all passing.
tsc --noEmitand the build are clean;bun.lockis unchanged. It also passes merged with #152, #153 and #154.Also tested by hand on a running shop (EmDash 1.6, Paystack test mode, KES):
admin/orders/refundADMIN_ONLYadmin/settingswithcheckoutModeadmin/payments/check-connectionadmin/subscriptions/actionWith EmDash's default
plugins:manage, an Editor gets EmDash's own 403 before any of this runs. To reach these checks I lowered that default tocontent:readlocally for the Editor run, then put it back.Review points
ctx.user.roleand not a permission? EmDash exposes the role on the route context; Admin (50) is the one role every site has. If you'd rather have a DashCommerce permission that sites can grant, the checks sit in one helper,isAdmin.