Repository navigation
feat(dashboard): bulk activate/deactivate/retest for selected provider connections #3271
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
Merged
diegosouzapw
merged 2 commits into
cheaper-inference:release/v3.8.12
from
leninejunior:feat/bulk-account-actions
Jun 6, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import { | |
| getProviderConnections, | ||
| createProviderConnection, | ||
| deleteProviderConnections, | ||
| updateProviderConnection, | ||
| getProviderNodeById, | ||
| isCloudEnabled, | ||
| } from "@/models"; | ||
|
|
@@ -18,7 +19,10 @@ import { | |
| } from "@/shared/constants/providers"; | ||
| import { getConsistentMachineId } from "@/shared/utils/machineId"; | ||
| import { syncToCloud } from "@/lib/cloudSync"; | ||
| import { createProviderSchema } from "@/shared/validation/schemas"; | ||
| import { | ||
| createProviderSchema, | ||
| batchUpdateProviderConnectionsSchema, | ||
| } from "@/shared/validation/schemas"; | ||
| import { isValidationFailure, validateBody } from "@/shared/validation/helpers"; | ||
| import { normalizeQoderPatProviderData } from "@omniroute/open-sse/services/qoderCli"; | ||
| import { | ||
|
|
@@ -195,6 +199,62 @@ export async function POST(request: Request) { | |
| } | ||
| } | ||
|
|
||
| // PATCH /api/providers - Bulk activate/deactivate connections | ||
| export async function PATCH(request: Request) { | ||
| const authError = await requireManagementAuth(request); | ||
| if (authError) return authError; | ||
|
|
||
| const auditContext = getAuditRequestContext(request); | ||
|
|
||
| let rawBody; | ||
| try { | ||
| rawBody = await request.json(); | ||
| } catch { | ||
| return NextResponse.json({ error: "Invalid JSON body" }, { status: 400 }); | ||
| } | ||
|
|
||
| const validation = validateBody(batchUpdateProviderConnectionsSchema, rawBody); | ||
| if (isValidationFailure(validation)) { | ||
| return NextResponse.json({ error: validation.error }, { status: 400 }); | ||
| } | ||
| const { ids, isActive } = validation.data; | ||
|
|
||
| try { | ||
| // Partial-failure semantics: report unknown IDs instead of failing the whole batch | ||
| const updatedIds: string[] = []; | ||
| const notFoundIds: string[] = []; | ||
| for (const id of ids) { | ||
| const updated = await updateProviderConnection(id, { isActive }); | ||
| if (updated) updatedIds.push(id); | ||
| else notFoundIds.push(id); | ||
| } | ||
|
|
||
| await syncToCloudIfEnabled(); | ||
|
|
||
| logAuditEvent({ | ||
| action: "provider.credentials.batch_updated", | ||
| actor: "admin", | ||
| resourceType: "provider_credentials", | ||
| status: "success", | ||
| ipAddress: auditContext.ipAddress || undefined, | ||
| requestId: auditContext.requestId, | ||
| metadata: { isActive, updated: updatedIds.length, notFound: notFoundIds, ids }, | ||
| }); | ||
|
|
||
| return NextResponse.json( | ||
| { | ||
| message: `${isActive ? "Activated" : "Deactivated"} ${updatedIds.length} connection(s)`, | ||
| updated: updatedIds.length, | ||
| notFound: notFoundIds, | ||
| }, | ||
| { status: 200 } | ||
| ); | ||
| } catch (error) { | ||
| console.log("Error batch updating connections:", error); | ||
|
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. CRITICAL: Error logging uses |
||
| return NextResponse.json({ error: "Failed to batch update connections" }, { status: 500 }); | ||
| } | ||
| } | ||
|
|
||
| export async function DELETE(request: Request) { | ||
| const authError = await requireManagementAuth(request); | ||
| if (authError) return authError; | ||
|
|
||
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
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
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
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
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
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
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
Oops, something went wrong.
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.
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.
WARNING: Audit event status is always "success" even when
notFoundIdscontains items (partial failure). Consider either logging a separate audit event for unknown IDs, or changing the status to reflect partial success (e.g., "partial_success"). The metadata includes all requested IDs plus thenotFoundarray which helps, but the status should accurately reflect the outcome.