fix: Deleted collections not showing in audit log

feat: Show titles of objects in audit log
fix: modelId not saved with share events
fix: List item squashes avatar at small screen sizes
This commit is contained in:
Tom Moor
2019-08-07 20:52:59 -07:00
parent 0f028812e1
commit 978eda3ad2
6 changed files with 37 additions and 11 deletions

View File

@ -37,6 +37,7 @@ const Image = styled(Flex)`
max-height: 40px;
align-items: center;
user-select: none;
flex-shrink: 0;
`;
const Heading = styled.p`

View File

@ -13,7 +13,11 @@ class Event extends BaseModel {
userId: string;
createdAt: string;
actor: User;
data: { name: string, email: string };
data: {
name: string,
email: string,
title: string,
};
get model() {
return this.name.split('.')[0];

View File

@ -21,8 +21,9 @@ const description = event => {
return (
<React.Fragment>
{capitalize(event.verbPastTense)} a{' '}
<Link to={`/share/${event.modelId || ''}`}>public link</Link> to a{' '}
<Link to={`/doc/${event.documentId}`}>document</Link>
<Link to={`/share/${event.modelId || ''}`}>public link</Link> to the{' '}
<Link to={`/doc/${event.documentId}`}>{event.data.name}</Link>{' '}
document
</React.Fragment>
);
case 'users.create':
@ -61,18 +62,35 @@ const description = event => {
}
if (event.documentId) {
if (event.name === 'documents.delete') {
return (
<React.Fragment>
Deleted the <strong>{event.data.title}</strong> document
</React.Fragment>
);
}
return (
<React.Fragment>
{capitalize(event.verbPastTense)} a{' '}
<Link to={`/doc/${event.documentId}`}>document</Link>
{capitalize(event.verbPastTense)} the{' '}
<Link to={`/doc/${event.documentId}`}>{event.data.title}</Link> document
</React.Fragment>
);
}
if (event.collectionId) {
if (event.name === 'collections.delete') {
return (
<React.Fragment>
Deleted the <strong>{event.data.name}</strong> collection
</React.Fragment>
);
}
return (
<React.Fragment>
{capitalize(event.verbPastTense)} a{' '}
<Link to={`/collections/${event.collectionId || ''}`}>collection</Link>
{capitalize(event.verbPastTense)} the{' '}
<Link to={`/collections/${event.collectionId || ''}`}>
{event.data.name}
</Link>{' '}
collection
</React.Fragment>
);
}
@ -95,7 +113,7 @@ const EventListItem = ({ event }: Props) => {
subtitle={
<React.Fragment>
{description(event)} <Time dateTime={event.createdAt} /> ago &middot;{' '}
{event.name}
<strong>{event.name}</strong>
</React.Fragment>
}
actions={

View File

@ -12,11 +12,12 @@ const { authorize } = policy;
const router = new Router();
router.post('events.list', auth(), pagination(), async ctx => {
let { sort = 'updatedAt', direction, auditLog = false } = ctx.body;
let { sort = 'createdAt', direction, auditLog = false } = ctx.body;
if (direction !== 'ASC') direction = 'DESC';
const user = ctx.state.user;
const collectionIds = await user.collectionIds();
const paranoid = false;
const collectionIds = await user.collectionIds(paranoid);
let where = {
name: Event.ACTIVITY_EVENTS,

View File

@ -8,6 +8,7 @@ const Event = sequelize.define('event', {
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
modelId: DataTypes.UUID,
name: DataTypes.STRING,
ip: DataTypes.STRING,
data: DataTypes.JSONB,

View File

@ -54,7 +54,7 @@ User.associate = models => {
};
// Instance methods
User.prototype.collectionIds = async function() {
User.prototype.collectionIds = async function(paranoid: boolean = true) {
let models = await Collection.findAll({
attributes: ['id', 'private'],
where: { teamId: this.teamId },
@ -67,6 +67,7 @@ User.prototype.collectionIds = async function() {
required: false,
},
],
paranoid,
});
// Filter collections that are private and don't have an association