feat: Events / audit log (#1008)

* feat: Record events in DB

* feat: events API

* First pass, hacky activity feed

* WIP

* Reset dashboard

* feat: audit log UI
feat: store ip address

* chore: Document events.list api

* fix: command specs

* await event create

* fix: backlinks service

* tidy

* fix: Hide audit log menu item if not admin
This commit is contained in:
Tom Moor
2019-08-05 20:38:31 -07:00
committed by GitHub
parent 75b03fdba2
commit fb4f6822a4
37 changed files with 911 additions and 148 deletions

View File

@ -4,7 +4,7 @@ import Sequelize from 'sequelize';
import auth from '../middlewares/authentication';
import pagination from './middlewares/pagination';
import { presentShare } from '../presenters';
import { Document, User, Share, Team } from '../models';
import { Document, User, Event, Share, Team } from '../models';
import policy from '../policies';
const Op = Sequelize.Op;
@ -50,6 +50,7 @@ router.post('shares.list', auth(), pagination(), async ctx => {
});
ctx.body = {
pagination: ctx.state.pagination,
data: shares.map(presentShare),
};
});
@ -73,6 +74,17 @@ router.post('shares.create', auth(), async ctx => {
},
});
await Event.create({
name: 'shares.create',
documentId,
collectionId: document.collectionId,
modelId: share.id,
teamId: user.teamId,
actorId: user.id,
data: { name: document.title },
ip: ctx.request.ip,
});
share.user = user;
share.document = document;
@ -91,6 +103,19 @@ router.post('shares.revoke', auth(), async ctx => {
await share.revoke(user.id);
const document = await Document.findByPk(share.documentId);
await Event.create({
name: 'shares.revoke',
documentId: document.id,
collectionId: document.collectionId,
modelId: share.id,
teamId: user.teamId,
actorId: user.id,
data: { name: document.title },
ip: ctx.request.ip,
});
ctx.body = {
success: true,
};