mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-02 05:54:44 +00:00
feat(api): add missing audit log calls to API endpoints
This commit is contained in:
@@ -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 })
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user