-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add deactivating partner feature #2915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -24,10 +24,10 @@ export const POST = withReferralsEmbedToken( | |||||||||||||||||||||||||||
| .pick({ url: true, key: true }) | ||||||||||||||||||||||||||||
| .parse(await parseRequestBody(req)); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if (programEnrollment.status === "banned") { | ||||||||||||||||||||||||||||
| if (["banned", "deactivated"].includes(programEnrollment.status)) { | ||||||||||||||||||||||||||||
| throw new DubApiError({ | ||||||||||||||||||||||||||||
| code: "forbidden", | ||||||||||||||||||||||||||||
| message: "You are banned from this program hence cannot create links.", | ||||||||||||||||||||||||||||
| message: `You are ${programEnrollment.status} from this program hence cannot create links.`, | ||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+27
to
32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainFix grammar and verify status completeness. The expanded status check and dynamic error message are correct improvements. However, there are two concerns:
Apply this diff to improve the error message grammar: - message: `You are ${programEnrollment.status} from this program hence cannot create links.`,
+ message: `You have been ${programEnrollment.status} from this program and cannot create links.`,Run the following script to verify if "rejected" status is blocked elsewhere and should be included here: 🏁 Script executed: #!/bin/bash
# Description: Check if "rejected" status is blocked in other partner API routes
# Search for status checks in partner-related API routes
rg -n --type=ts -C3 '\["banned",.*"deactivated".*"rejected"\]' apps/web/app
# Also check for any other status validation patterns
rg -n --type=ts -C3 'programEnrollment\.status.*rejected' apps/web/appLength of output: 2523 Include "rejected" status and improve error message grammar.
- if (["banned", "deactivated"].includes(programEnrollment.status)) {
+ if (["banned", "deactivated", "rejected"].includes(programEnrollment.status)) {
throw new DubApiError({
code: "forbidden",
- message: `You are ${programEnrollment.status} from this program hence cannot create links.`,
+ message: `You have been ${programEnrollment.status} from this program and cannot create links.`,
});
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,10 +56,7 @@ export function ProgramLinksPageClient() { | |
| links && maxPartnerLinks && links.length >= maxPartnerLinks; | ||
| const hasAdditionalLinks = additionalLinks && additionalLinks.length > 0; | ||
|
|
||
| const canCreateNewLink = | ||
| !hasLinksLimitReached && | ||
| hasAdditionalLinks && | ||
| programEnrollment?.status !== "banned"; | ||
| const canCreateNewLink = !hasLinksLimitReached && hasAdditionalLinks; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify that enrollment status validation exists at the server layer. The removal of the
Run the following script to verify server-side status validation: 🏁 Script executed: #!/bin/bash
# Description: Find server actions or API routes that handle partner link creation
# and verify they validate enrollment status
# Search for partner link creation endpoints/actions
echo "=== Searching for partner link creation server actions/APIs ==="
rg -n --type=ts --type=tsx -C5 'createPartnerLink|create.*link' -g '!node_modules' -g '!*.test.*' -g '!*.spec.*'
echo -e "\n=== Searching for enrollment status validation in server code ==="
rg -n --type=ts --type=tsx -C3 'enrollment.*status|status.*banned|status.*deactivated' -g '!node_modules' -g '!*.test.*' -g '!*.spec.*' -g '**/app/**/route.ts' -g '**/lib/actions/**' -g '**/app/**/actions.ts'Length of output: 186 🏁 Script executed: #!/bin/bash
echo "=== Searching for createPartnerLink definitions ==="
rg -n 'createPartnerLink' --glob '*.ts' --glob '*.tsx' --glob '!node_modules/*' --glob '!*.test.*' --glob '!*.spec.*'
echo -e "\n=== Searching for Next.js POST route handlers ==="
rg -n "export\s+async\s+function\s+POST" -g 'route.ts' --glob '!node_modules/*'
echo -e "\n=== Searching for enrollment status validation ==="
rg -nE 'status.*(banned|deactivated)' --glob '*.ts' --glob '*.tsx' --glob '!node_modules/*' --glob '!*.test.*' --glob '!*.spec.*'Length of output: 7432 🏁 Script executed: #!/bin/bash
echo "=== Displaying first 200 lines of partner links route ==="
sed -n '1,200p' 'apps/web/app/(ee)/api/partners/links/route.ts'
echo -e "\n=== Searching for status checks in this route file ==="
rg -n 'status' 'apps/web/app/(ee)/api/partners/links/route.ts'Length of output: 5120 Enforce enrollment status in link-creation API if (partner.status === "banned" || partner.status === "deactivated") {
throw new DubApiError({ code: "forbidden", message: "Partner is deactivated." });
}🤖 Prompt for AI Agents |
||
|
|
||
| useKeyboardShortcut("c", () => setShowPartnerLinkModal(true), { | ||
| enabled: canCreateNewLink ?? false, | ||
|
|
@@ -81,13 +78,11 @@ export function ProgramLinksPageClient() { | |
| onClick={() => setShowPartnerLinkModal(true)} | ||
| disabled={!canCreateNewLink} | ||
| disabledTooltip={ | ||
| programEnrollment?.status === "banned" | ||
| ? "You are banned from this program." | ||
| : hasLinksLimitReached | ||
| ? `You have reached the limit of ${maxPartnerLinks} referral links.` | ||
| : !hasAdditionalLinks | ||
| ? `${program?.name ?? "This"} program does not allow partners to create new links.` | ||
| : undefined | ||
| hasLinksLimitReached | ||
| ? `You have reached the limit of ${maxPartnerLinks} referral links.` | ||
| : !hasAdditionalLinks | ||
| ? `${program?.name ?? "This"} program does not allow partners to create new links.` | ||
| : undefined | ||
| } | ||
| /> | ||
| </div> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix misleading error message.
The error message says "cannot create links" but this is a PATCH endpoint for updating links. The message should reflect the actual operation being blocked.
Apply this diff to fix the error message:
throw new DubApiError({ code: "forbidden", - message: `You are ${programEnrollment.status} from this program hence cannot create links.`, + message: `You are ${programEnrollment.status} from this program hence cannot update links.`, });🤖 Prompt for AI Agents