fix profile activity and migration remediation

This commit is contained in:
IanShaw027
2026-04-21 02:08:56 +08:00
parent a27a7add3d
commit ebe7524415
12 changed files with 703 additions and 28 deletions

View File

@@ -13,6 +13,7 @@ vi.mock('@/api/client', () => ({
}))
import {
bindUserAuthIdentity,
getAuthIdentityMigrationReportSummary,
listAuthIdentityMigrationReports,
resolveAuthIdentityMigrationReport,
@@ -81,4 +82,31 @@ describe('admin users auth identity migration reports API', () => {
})
expect(result).toBe(response)
})
it('binds a canonical auth identity to a user for remediation', async () => {
const response = {
identity_id: 11,
provider_type: 'oidc',
provider_key: 'https://issuer.example',
provider_subject: 'subject-123',
}
post.mockResolvedValue({ data: response })
const result = await bindUserAuthIdentity(42, {
provider_type: 'oidc',
provider_key: 'https://issuer.example',
provider_subject: 'subject-123',
issuer: 'https://issuer.example',
metadata: { source: 'migration-report' },
})
expect(post).toHaveBeenCalledWith('/admin/users/42/auth-identities', {
provider_type: 'oidc',
provider_key: 'https://issuer.example',
provider_subject: 'subject-123',
issuer: 'https://issuer.example',
metadata: { source: 'migration-report' },
})
expect(result).toBe(response)
})
})

View File

@@ -24,6 +24,30 @@ export interface AuthIdentityMigrationReportSummary {
by_type: Record<string, number>
}
export interface AdminBindAuthIdentityChannelRequest {
channel: string
channel_app_id?: string
channel_subject: string
metadata?: Record<string, unknown>
}
export interface AdminBindAuthIdentityRequest {
provider_type: string
provider_key: string
provider_subject: string
issuer?: string
metadata?: Record<string, unknown>
channel?: AdminBindAuthIdentityChannelRequest
}
export interface AdminBoundAuthIdentity {
identity_id: number
provider_type: string
provider_key: string
provider_subject: string
channel_id?: number | null
}
export interface ListAuthIdentityMigrationReportsParams {
page?: number
pageSize?: number
@@ -308,6 +332,17 @@ export async function resolveAuthIdentityMigrationReport(
return data
}
export async function bindUserAuthIdentity(
userId: number,
input: AdminBindAuthIdentityRequest
): Promise<AdminBoundAuthIdentity> {
const { data } = await apiClient.post<AdminBoundAuthIdentity>(
`/admin/users/${userId}/auth-identities`,
input
)
return data
}
export const usersAPI = {
list,
getById,
@@ -321,6 +356,7 @@ export const usersAPI = {
getUserUsageStats,
getUserBalanceHistory,
replaceGroup,
bindUserAuthIdentity,
getAuthIdentityMigrationReportSummary,
listAuthIdentityMigrationReports,
resolveAuthIdentityMigrationReport