This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/server/models/Event.js

97 lines
1.9 KiB
JavaScript

// @flow
import { DataTypes, sequelize } from '../sequelize';
import events from '../events';
const Event = sequelize.define('event', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
modelId: DataTypes.UUID,
name: DataTypes.STRING,
ip: DataTypes.STRING,
data: DataTypes.JSONB,
});
Event.associate = models => {
Event.belongsTo(models.User, {
as: 'user',
foreignKey: 'userId',
});
Event.belongsTo(models.User, {
as: 'actor',
foreignKey: 'actorId',
});
Event.belongsTo(models.Collection, {
as: 'collection',
foreignKey: 'collectionId',
});
Event.belongsTo(models.Collection, {
as: 'document',
foreignKey: 'documentId',
});
Event.belongsTo(models.Team, {
as: 'team',
foreignKey: 'teamId',
});
};
Event.beforeCreate(event => {
if (event.ip) {
// cleanup IPV6 representations of IPV4 addresses
event.ip = event.ip.replace(/^::ffff:/, '');
}
});
Event.afterCreate(event => {
events.add(event);
});
Event.ACTIVITY_EVENTS = [
'users.create',
'documents.publish',
'documents.archive',
'documents.unarchive',
'documents.pin',
'documents.unpin',
'documents.delete',
'documents.restore',
'collections.create',
'collections.delete',
];
Event.AUDIT_EVENTS = [
'api_keys.create',
'api_keys.delete',
'users.create',
'users.promote',
'users.demote',
'users.invite',
'users.suspend',
'users.activate',
'users.delete',
'documents.publish',
'documents.update',
'documents.archive',
'documents.unarchive',
'documents.pin',
'documents.unpin',
'documents.move',
'documents.delete',
'shares.create',
'shares.revoke',
'groups.create',
'groups.update',
'groups.delete',
'collections.create',
'collections.update',
'collections.add_user',
'collections.remove_user',
'collections.add_group',
'collections.remove_group',
'collections.delete',
];
export default Event;