mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-30 04:44:28 +00:00
feat(api): add missing audit log calls to API endpoints
This commit is contained in:
@@ -12,6 +12,8 @@ import {
|
||||
} from '@shumai/dtos'
|
||||
|
||||
import type { Prisma } from '@shumai/db'
|
||||
import { prisma, AuditAction } from '@shumai/db'
|
||||
import { auditLogService } from '@shumai/core/src/auditLog/auditLog'
|
||||
|
||||
type User = Prisma.UserGetPayload<Record<string, never>>
|
||||
|
||||
@@ -94,6 +96,13 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
deniedTools: config.deniedTools || [],
|
||||
}
|
||||
|
||||
await auditLogService.logAction({
|
||||
action: AuditAction.agent_create,
|
||||
teamId,
|
||||
userId: userReq?.id,
|
||||
itemId: agent.id,
|
||||
})
|
||||
|
||||
return c.json(info, 200)
|
||||
})
|
||||
.put('/agents/:agentId', zValidator('json', updateAgentRequestSchema), async (c) => {
|
||||
@@ -113,6 +122,13 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
...req,
|
||||
})
|
||||
|
||||
await auditLogService.logAction({
|
||||
action: AuditAction.agent_update,
|
||||
teamId: agent.teamId,
|
||||
userId: userReq?.id,
|
||||
itemId: agent.id,
|
||||
})
|
||||
|
||||
const config = agent.config as unknown as PrismaJson.AgentConfig
|
||||
const info: AgentInfo = {
|
||||
id: agent.id,
|
||||
@@ -146,10 +162,24 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
id: agentId,
|
||||
})
|
||||
|
||||
const existingAgent = await prisma.agent.findUnique({
|
||||
where: { id: agentId },
|
||||
select: { teamId: true },
|
||||
})
|
||||
|
||||
await agentService.deleteAgent({
|
||||
agentId,
|
||||
})
|
||||
|
||||
if (existingAgent) {
|
||||
await auditLogService.logAction({
|
||||
action: AuditAction.agent_delete,
|
||||
teamId: existingAgent.teamId,
|
||||
userId: userReq?.id,
|
||||
itemId: agentId,
|
||||
})
|
||||
}
|
||||
|
||||
return new Response(null, { status: 204 })
|
||||
})
|
||||
.get('/agent-sessions/:sessionId/entries', async (c) => {
|
||||
|
||||
Reference in New Issue
Block a user