fix: API key create/delete should create audit events

closes #1101
This commit is contained in:
Tom Moor
2020-01-02 22:20:02 -08:00
parent 321e5c9cbd
commit 9c66a14fec
3 changed files with 33 additions and 1 deletions

View File

@ -4,7 +4,7 @@ import Router from 'koa-router';
import auth from '../middlewares/authentication';
import pagination from './middlewares/pagination';
import { presentApiKey } from '../presenters';
import { ApiKey } from '../models';
import { ApiKey, Event } from '../models';
import policy from '../policies';
const { authorize } = policy;
@ -22,6 +22,15 @@ router.post('apiKeys.create', auth(), async ctx => {
userId: user.id,
});
await Event.create({
name: 'api_keys.create',
modelId: key.id,
teamId: user.teamId,
actorId: user.id,
data: { name },
ip: ctx.request.ip,
});
ctx.body = {
data: presentApiKey(key),
};
@ -54,6 +63,15 @@ router.post('apiKeys.delete', auth(), async ctx => {
await key.destroy();
await Event.create({
name: 'api_keys.delete',
modelId: key.id,
teamId: user.teamId,
actorId: user.id,
data: { name: key.name },
ip: ctx.request.ip,
});
ctx.body = {
success: true,
};