From 4a702826913e262079a49206badb665318828c16 Mon Sep 17 00:00:00 2001
From: Mihail Hagiu <mihail.hagiu@thinslices.com>
Date: Wed, 12 Dec 2018 13:05:06 +0200
Subject: [PATCH] fix(authsome-mode): Bugfixes

---
 packages/xpub-faraday/config/authsome-mode.js | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/packages/xpub-faraday/config/authsome-mode.js b/packages/xpub-faraday/config/authsome-mode.js
index d22fb6c8a..c54dac097 100644
--- a/packages/xpub-faraday/config/authsome-mode.js
+++ b/packages/xpub-faraday/config/authsome-mode.js
@@ -335,11 +335,25 @@ async function applyAdminPolicy(user, operation, object, context) {
     }
   }
   if (operation === 'PATCH') {
+    if (get(object, 'current.type') === 'collection') {
+      return !isCollectionInStatuses(get(object, 'current'), [
+        'rejected',
+        'accepted',
+        'withdrawn',
+      ])
+    }
     if (get(object, 'current.type') === 'fragment') {
       const collection = await context.models.Collection.find(
         get(object, 'current.collectionId'),
       )
-      return helpers.isLastFragment(collection, get(object, 'current'))
+      return (
+        helpers.isLastFragment(collection, get(object, 'current')) &&
+        !isCollectionInStatuses(collection, [
+          'rejected',
+          'accepted',
+          'withdrawn',
+        ])
+      )
     }
   }
   return true
@@ -396,6 +410,9 @@ async function applyEditorInChiefPolicy(user, operation, object, context) {
     }
   }
   if (operation === 'PATCH') {
+    if (get(object, 'current.type') === 'collection') {
+      return false
+    }
     if (get(object, 'current.type') === 'fragment') {
       return false
     }
-- 
GitLab