]> BookStack Code Mirror - bookstack/commitdiff
Fixed error causing permissions to be deleted on book sort
authorDan Brown <redacted>
Mon, 23 Jan 2017 22:27:11 +0000 (22:27 +0000)
committerDan Brown <redacted>
Mon, 23 Jan 2017 22:27:11 +0000 (22:27 +0000)
Closes #282

app/Http/Controllers/BookController.php
app/Services/PermissionService.php

index 57ac486d5e71122b49b057b9fc7dc25dd36ef3ed..408192ff9085dadb68363c1c1eb821704572301c 100644 (file)
@@ -208,7 +208,7 @@ class BookController extends Controller
         }
 
         // Update permissions on changed models
-        $this->entityRepo->buildJointPermissions($updatedModels);
+        if (count($updatedModels) === 0) $this->entityRepo->buildJointPermissions($updatedModels);
 
         return redirect($book->getUrl());
     }
index 39a2c38beda24f795dbe4d0d0d88c3fec3a9f40f..72a810b6b4ebf657f6c29cd681141b930652a34c 100644 (file)
@@ -243,13 +243,14 @@ class PermissionService
      */
     protected function deleteManyJointPermissionsForEntities($entities)
     {
+        if (count($entities) === 0) return;
         $query = $this->jointPermission->newQuery();
-        foreach ($entities as $entity) {
-            $query->orWhere(function($query) use ($entity) {
-                $query->where('entity_id', '=', $entity->id)
-                    ->where('entity_type', '=', $entity->getMorphClass());
-            });
-        }
+            foreach ($entities as $entity) {
+                $query->orWhere(function($query) use ($entity) {
+                    $query->where('entity_id', '=', $entity->id)
+                        ->where('entity_type', '=', $entity->getMorphClass());
+                });
+            }
         $query->delete();
     }