feat(api): add missing audit log calls to API endpoints

This commit is contained in:
yiling
2026-08-01 11:03:50 +08:00
parent 7dfb2c7f2f
commit 0324b95c7e
18 changed files with 695 additions and 2 deletions
+20
View File
@@ -3,7 +3,9 @@ import { Hono } from 'hono'
import { authzService, Permission, ResourceType } from '@shumai/core/src/authz/authz'
import { providerService } from '@shumai/core/src/provider/provider'
import { createProviderRequestSchema, updateProviderRequestSchema } from '@shumai/dtos'
import { AuditAction } from '@shumai/db'
import type { Prisma } from '@shumai/db'
import { auditLogService } from '@shumai/core/src/auditLog/auditLog'
type User = Prisma.UserGetPayload<Record<string, never>>
@@ -54,6 +56,12 @@ const route = new Hono<{ Variables: { user: User } }>()
})
const provider = await providerService.create(teamId, name, config, models)
await auditLogService.logAction({
action: AuditAction.provider_create,
teamId,
userId: user?.id,
itemId: provider.id,
})
return c.json(provider)
})
@@ -73,6 +81,12 @@ const route = new Hono<{ Variables: { user: User } }>()
if (!providerBefore) throw new Error('Provider not found')
const provider = await providerService.update(providerBefore.teamId, id, config, models)
await auditLogService.logAction({
action: AuditAction.provider_update,
teamId: providerBefore.teamId,
userId: user?.id,
itemId: id,
})
return c.json(provider)
})
@@ -91,6 +105,12 @@ const route = new Hono<{ Variables: { user: User } }>()
if (!providerBefore) throw new Error('Provider not found')
await providerService.delete(providerBefore.teamId, id)
await auditLogService.logAction({
action: AuditAction.provider_delete,
teamId: providerBefore.teamId,
userId: user?.id,
itemId: id,
})
return c.json({ success: true })
})