Prevents accidental overwriting of another users work

This commit is contained in:
Tom Moor
2017-11-25 13:04:54 -08:00
parent 7945abbe54
commit 98f317c74a
6 changed files with 36 additions and 2 deletions

View File

@ -242,7 +242,7 @@ router.post('documents.create', auth(), async ctx => {
});
router.post('documents.update', auth(), async ctx => {
const { id, title, text } = ctx.body;
const { id, title, text, lastRevision } = ctx.body;
ctx.assertPresent(id, 'id is required');
ctx.assertPresent(title || text, 'title or text is required');
@ -250,6 +250,10 @@ router.post('documents.update', auth(), async ctx => {
const document = await Document.findById(id);
const collection = document.collection;
if (lastRevision && lastRevision !== document.revisionCount) {
throw httpErrors.BadRequest('Document has changed since last revision');
}
authDocumentForUser(ctx, document);
// Update document