Skip to content

Add admin surface for partner postback access - #4210

Open
pepeladeira wants to merge 6 commits into
mainfrom
admin-partner-postback-access
Open

Add admin surface for partner postback access#4210
pepeladeira wants to merge 6 commits into
mainfrom
admin-partner-postback-access

Conversation

@pepeladeira

@pepeladeira pepeladeira commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Added a Postbacks tab to partner administration navigation.
    • Introduced an admin Postback access page to grant or revoke postback permissions for partners by partner ID or email.
    • Added a complete access management experience, including partner listing with copyable IDs, active postback counts, loading skeletons, empty states, confirmation prompts, and success/error toasts.
    • Implemented a new admin API to list, grant, and revoke postback access to keep the UI in sync.

@vercel

vercel Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
dub Ready Ready Preview Jul 23, 2026 9:33pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7f58f070-e5aa-4b0a-83cd-d12cad4e0d23

📥 Commits

Reviewing files that changed from the base of the PR and between 7187603 and c1a25ee.

📒 Files selected for processing (1)
  • apps/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)/api/admin/partners/postbacks/route.ts

📝 Walkthrough

Walkthrough

Adds admin postback access management with Edge Config persistence, GET/POST/DELETE API handlers, dashboard grant/revoke controls, partner states, and a new navigation tab.

Changes

Postback access management

Layer / File(s) Summary
Postback access API and persistence
apps/web/app/(ee)/api/admin/partners/postbacks/route.ts
Stores configured partner IDs in Edge Config and provides owner-only handlers to list, grant, and revoke postback access. Revocation disables the partner’s active postbacks and rolls back database changes if Edge Config removal fails.
Admin postback management page
apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/postbacks/page.tsx
Adds the client page for granting and revoking access, refreshing SWR data, showing toasts, and rendering loading, empty, and partner-list states.
Partners navigation entry
apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/partners-nav-tabs.tsx
Adds a Webhook-icon “Postbacks” tab to partner navigation.

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
Loading

Suggested reviewers: steven-tey

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: an admin surface for managing partner postback access.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch admin-partner-postback-access

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Input has no accessible label.

The text input relies solely on placeholder for 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9056f6a and 89b84cf.

📒 Files selected for processing (3)
  • 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

Comment thread apps/web/app/(ee)/api/admin/partners/postbacks/route.ts Outdated
Comment thread apps/web/app/(ee)/api/admin/partners/postbacks/route.ts Outdated
Comment thread apps/web/app/(ee)/api/admin/partners/postbacks/route.ts Outdated
Comment thread apps/web/app/(ee)/api/admin/partners/postbacks/route.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Return 400 for malformed request bodies.

req.json() and z.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 use safeParse and return a bad_request/unprocessable_entity 400 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

📥 Commits

Reviewing files that changed from the base of the PR and between 411f7a4 and 7187603.

📒 Files selected for processing (2)
  • apps/web/app/(ee)/admin.dub.co/(dashboard)/partners/postbacks/page.tsx
  • apps/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

@pepeladeira

Copy link
Copy Markdown
Collaborator Author

@coderabbitai Full review. Any breaking changes or security issues?

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

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 || true

Length 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
fi

Length 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


@pepeladeira Full review complete. I found one security-sensitive concurrency issue that should be addressed before merge.

  • High — revoking access can leave active postbacks delivering events. DELETE checks Edge Config, disables the partner’s postbacks, then removes the partner from partnerBetaFeatures. If two revoke requests overlap, request A can disable the postbacks, request B can successfully remove access, and then A observes that access is already absent and executes its rollback—re-enabling the postbacks. The partner is now revoked in Edge Config but still has active endpoints; send-partner-postback.ts dispatches based on disabledAt, so deliveries can continue.
    The underlying cause is the non-atomic read-modify-write in updatePostbackPartnerIds (Line 60 onward), combined with compensating rollback in the delete handler (Line 264 onward). Use serialized/conditional Edge Config updates (or a durable transactional source of truth/lock) and make the revoke flow idempotent so one request cannot undo a concurrent successful revocation.

Other findings:

  • No authorization bypass found: GET requires an admin session; POST and DELETE require the owner role through withAdmin.
  • Breaking behavior: revocation intentionally disables every active endpoint, and re-granting does not re-enable them. The new UI clearly communicates this, so it is an intentional operational behavior rather than an undocumented API break.
  • Reliability: simultaneous grants/revokes can also lose updates because each mutation overwrites the whole partnerBetaFeatures.postbacks array from a stale read. This can silently drop another partner’s recently granted access.
  • Coverage: no tests were found for the new endpoint, Edge Config failures, or concurrent mutation/revocation scenarios. Add handler-level tests for grant/revoke idempotency, failed writes, and overlapping mutations.

I would block merge on the revoke race because it defeats the security expectation that revoking postback access stops deliveries.

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