Add admin surface for partner postback access - #4210
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults 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)
📝 WalkthroughWalkthroughAdds admin postback access management with Edge Config persistence, GET/POST/DELETE API handlers, dashboard grant/revoke controls, partner states, and a new navigation tab. ChangesPostback access management
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Admin
participant PartnersPostbacksPage
participant PostbacksRoute
participant EdgeConfig
participant Prisma
Admin->>PartnersPostbacksPage: Open Postbacks tab
PartnersPostbacksPage->>PostbacksRoute: GET partner access list
PostbacksRoute->>EdgeConfig: Read configured partner IDs
PostbacksRoute->>Prisma: Query partners and enabled postback counts
Prisma-->>PostbacksRoute: Partner data
PostbacksRoute-->>PartnersPostbacksPage: Return partner list
Admin->>PartnersPostbacksPage: Submit partner ID or email
PartnersPostbacksPage->>PostbacksRoute: POST access request
PostbacksRoute->>EdgeConfig: Persist partner ID
PostbacksRoute-->>PartnersPostbacksPage: Return success
Admin->>PartnersPostbacksPage: Confirm revoke
PartnersPostbacksPage->>PostbacksRoute: DELETE partner access
PostbacksRoute->>Prisma: Disable active postbacks
PostbacksRoute->>EdgeConfig: Remove partner ID
PostbacksRoute-->>PartnersPostbacksPage: Return success
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/postbacks/page.tsx (1)
117-123: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winInput has no accessible label.
The text input relies solely on
placeholderfor its purpose; screen readers may not reliably announce placeholder text as a label.♿ Proposed fix
<input type="text" + aria-label="Partner ID or email" value={partnerIdOrEmail} onChange={(e) => setPartnerIdOrEmail(e.target.value)} placeholder="pn_123... or panic@thedis.co" className="w-full rounded-md border border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm" />🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/web/app/`(ee)/admin.dub.co/(dashboard)/partners/postbacks/page.tsx around lines 117 - 123, The partner ID/email input near partnerIdOrEmail lacks an accessible label. Add a persistent, programmatically associated label for this input using a unique id and matching htmlFor, while retaining the existing placeholder and input behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/web/app/`(ee)/admin.dub.co/(dashboard)/partners/postbacks/page.tsx:
- Around line 77-82: Update the POST request in the partner postbacks
grant-access flow to include the same application/json Content-Type header used
by the nearby DELETE request, while preserving the existing JSON.stringify body
and request behavior.
In `@apps/web/app/`(ee)/api/admin/partners/postbacks/route.ts:
- Around line 133-141: Replace the read-modify-write logic in the POST and
DELETE handlers with an atomic or serialized update mechanism for the shared
partner ID list. Update the flows around getPostbackPartnerIds and
setPostbackPartnerIds so concurrent grants and revocations cannot overwrite each
other, while preserving the existing duplicate-grant and missing-access response
behavior.
- Around line 26-62: Harden setPostbackPartnerIds by requiring both
EDGE_CONFIG_ID and EDGE_CONFIG before reading or writing Edge Config, and
propagate failures instead of swallowing get() errors or defaulting to an empty
record. Wrap the Vercel PATCH fetch with a timeout and error handling, check
res.ok, and throw on non-success responses so POST/DELETE cannot report success
for failed persistence while preserving existing partnerBetaFeatures data.
- Around line 159-177: Reorder the revocation flow so the
prisma.postback.updateMany operation completes before setPostbackPartnerIds
removes the partner from Edge Config. Preserve the existing partner access
validation and disable only active postbacks, ensuring a database failure
prevents the access-removal update from being applied.
---
Nitpick comments:
In `@apps/web/app/`(ee)/admin.dub.co/(dashboard)/partners/postbacks/page.tsx:
- Around line 117-123: The partner ID/email input near partnerIdOrEmail lacks an
accessible label. Add a persistent, programmatically associated label for this
input using a unique id and matching htmlFor, while retaining the existing
placeholder and input behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 3c6ec9e7-990b-4a2c-af04-b2ab643df7bd
📒 Files selected for processing (3)
apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/partners-nav-tabs.tsxapps/web/app/(ee)/admin.dub.co/(dashboard)/partners/postbacks/page.tsxapps/web/app/(ee)/api/admin/partners/postbacks/route.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/web/app/(ee)/api/admin/partners/postbacks/route.ts (1)
190-194: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winReturn 400 for malformed request bodies.
req.json()andz.parse()throw at the POST/DELETE entry points; without catching these before business logic runs, invalid request bodies are returned as 500s. Catch parse failures or usesafeParseand return abad_request/unprocessable_entity400 response for both the POST and DELETE handlers.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/web/app/`(ee)/api/admin/partners/postbacks/route.ts around lines 190 - 194, Handle request-body parsing failures in both the POST handler at the partnerIdOrEmail schema parse and the DELETE handler at the corresponding parse site in route.ts. Use safeParse or catch req.json()/z.parse() errors before business logic, and return the established bad_request or unprocessable_entity 400 response for malformed bodies instead of allowing them to become 500 errors.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@apps/web/app/`(ee)/api/admin/partners/postbacks/route.ts:
- Around line 190-194: Handle request-body parsing failures in both the POST
handler at the partnerIdOrEmail schema parse and the DELETE handler at the
corresponding parse site in route.ts. Use safeParse or catch
req.json()/z.parse() errors before business logic, and return the established
bad_request or unprocessable_entity 400 response for malformed bodies instead of
allowing them to become 500 errors.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 390b304e-b0c4-4943-9e3e-cf2d909245ee
📒 Files selected for processing (2)
apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/postbacks/page.tsxapps/web/app/(ee)/api/admin/partners/postbacks/route.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/postbacks/page.tsx
|
@coderabbitai Full review. Any breaking changes or security issues? |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo '=== PR diff summary ==='
git diff --stat origin/main...HEAD
git diff --name-status origin/main...HEAD
echo '=== Modified file outlines ==='
for f in \
'apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/partners-nav-tabs.tsx' \
'apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/postbacks/page.tsx' \
'apps/web/app/(ee)/api/admin/partners/postbacks/route.ts'
do
if [ -f "$f" ]; then
echo "--- $f"
ast-grep outline "$f" --items all || true
fi
done
echo '=== Full PR diff ==='
git diff --find-renames --find-copies --unified=80 origin/main...HEAD -- \
'apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/partners-nav-tabs.tsx' \
'apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/postbacks/page.tsx' \
'apps/web/app/(ee)/api/admin/partners/postbacks/route.ts'
echo '=== Related route and Edge Config patterns ==='
rg -n -C 5 --glob '*.ts' --glob '*.tsx' \
'(EDGE_CONFIG|partnerBetaFeatures|createEdgeConfigClient|edge-config|edgeConfig)' \
apps packages 2>/dev/null || true
echo '=== Relevant authorization and postback schema usages ==='
rg -n -C 5 --glob '*.ts' --glob '*.tsx' \
'(getSession|isAdmin|isOwner|ownerId|postbacks|disabledAt)' \
'apps/web/app/(ee)/api' 'apps/web' 2>/dev/null || trueLength of output: 201806 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo '=== New admin postbacks route ==='
nl -ba 'apps/web/app/(ee)/api/admin/partners/postbacks/route.ts'
echo '=== New admin page ==='
nl -ba 'apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/postbacks/page.tsx'
echo '=== Admin guard ==='
nl -ba apps/web/lib/auth/admin.ts
echo '=== Partner beta-feature reader ==='
nl -ba apps/web/lib/edge-config/get-partner-feature-flags.ts
echo '=== Admin route tests / related Edge Config writers ==='
rg -n -C 4 --glob '*.{test,spec}.{ts,tsx}' \
'(admin/partners/postbacks|partnerBetaFeatures|postback access)' \
apps packages 2>/dev/null || true
rg -n -C 4 --glob '*.{ts,tsx}' \
'(EDGE_CONFIG_REST_API_URL|EDGE_CONFIG_REST_API_TOKEN|items/batch|operation: "upsert")' \
apps packages 2>/dev/null || true
echo '=== Admin UI access controls and route configuration ==='
rg -n -C 4 --glob '*.{ts,tsx}' \
'(admin\.dub\.co|adminRole|requiredRoles|withAdmin)' \
'apps/web/app/(ee)/admin.dub.co' apps/web/middleware.ts apps/web 2>/dev/null | head -n 600
echo '=== Package scripts (static-check availability only) ==='
if [ -f package.json ]; then
node -e 'const p=require("./package.json"); console.log(JSON.stringify(p.scripts,null,2))' 2>/dev/null || cat package.json
fiLength of output: 1639 🏁 Script executed: #!/bin/bash
set -euo pipefail
print_file () {
printf '\n=== %s ===\n' "$1"
sed -n '1,360p' "$1"
}
print_file 'apps/web/app/(ee)/api/admin/partners/postbacks/route.ts'
print_file 'apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/postbacks/page.tsx'
print_file 'apps/web/lib/auth/admin.ts'
print_file 'apps/web/lib/edge-config/get-partner-feature-flags.ts'
echo '=== Tests covering this endpoint or its storage key ==='
rg -n -C 4 --glob '*.{test,spec}.{ts,tsx}' \
'(admin/partners/postbacks|partnerBetaFeatures|postback access)' \
apps packages 2>/dev/null || true
echo '=== Edge Config writer implementations ==='
rg -n -C 8 --glob '*.{ts,tsx}' \
'(EDGE_CONFIG_REST_API_URL|EDGE_CONFIG_REST_API_TOKEN|items/batch)' \
apps packages 2>/dev/null || true
echo '=== Postback feature-gate and enable/update behavior ==='
sed -n '1,130p' 'apps/web/app/(ee)/api/partner-profile/postbacks/route.ts'
sed -n '1,120p' 'apps/web/app/(ee)/api/partner-profile/postbacks/[postbackId]/route.ts'Length of output: 23859
Other findings:
I would block merge on the revoke race because it defeats the security expectation that revoking postback access stops deliveries. |
Summary by CodeRabbit