From 2d0fd863ddac418cdd9ffd793c0f8d06e6d2c42f Mon Sep 17 00:00:00 2001
From: Andrei Cioromila <andrei.cioromila@thinslices.com>
Date: Tue, 30 Oct 2018 11:16:29 +0200
Subject: [PATCH] fix(invite): Return error when inviting reviewers on older
 manuscript versions

---
 .../src/routes/fragmentsInvitations/post.js                 | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/packages/component-invite/src/routes/fragmentsInvitations/post.js b/packages/component-invite/src/routes/fragmentsInvitations/post.js
index 2eab3d2d1..4442ae74c 100644
--- a/packages/component-invite/src/routes/fragmentsInvitations/post.js
+++ b/packages/component-invite/src/routes/fragmentsInvitations/post.js
@@ -11,6 +11,8 @@ const {
 
 const emailInvitations = require('./emails/invitations')
 
+const { last } = require('lodash')
+
 module.exports = models => async (req, res) => {
   const { email, role } = req.body
 
@@ -40,6 +42,10 @@ module.exports = models => async (req, res) => {
       return res.status(400).json({
         error: `Fragment ${fragmentId} does not match collection ${collectionId}.`,
       })
+    if (last(collection.fragments) !== fragmentId)
+      return res.status(400).json({
+        error: `Fragment ${fragmentId} is an older version.`,
+      })
     fragment = await models.Fragment.find(fragmentId)
   } catch (e) {
     const notFoundError = await services.handleNotFoundError(e, 'item')
-- 
GitLab