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

@ -1,7 +1,6 @@
// @flow
import { uniqBy } from 'lodash';
import { User, Team } from '../models';
import events from '../events';
import { User, Event, Team } from '../models';
import mailer from '../mailer';
type Invite = { name: string, email: string };
@ -9,9 +8,11 @@ type Invite = { name: string, email: string };
export default async function userInviter({
user,
invites,
ip,
}: {
user: User,
invites: Invite[],
ip: string,
}): Promise<{ sent: Invite[] }> {
const team = await Team.findByPk(user.teamId);
@ -35,23 +36,28 @@ export default async function userInviter({
);
// send and record invites
filteredInvites.forEach(async invite => {
await mailer.invite({
to: invite.email,
name: invite.name,
actorName: user.name,
actorEmail: user.email,
teamName: team.name,
teamUrl: team.url,
});
events.add({
name: 'users.invite',
actorId: user.id,
teamId: user.teamId,
email: invite.email,
});
});
await Promise.all(
filteredInvites.map(async invite => {
await Event.create({
name: 'users.invite',
actorId: user.id,
teamId: user.teamId,
data: {
email: invite.email,
name: invite.name,
},
ip,
});
await mailer.invite({
to: invite.email,
name: invite.name,
actorName: user.name,
actorEmail: user.email,
teamName: team.name,
teamUrl: team.url,
});
})
);
return { sent: filteredInvites };
}