Fixed error causing permissions to be deleted on book sort
Closes #282
Showing
2 changed files
with
8 additions
and
7 deletions
| ... | @@ -208,7 +208,7 @@ class BookController extends Controller | ... | @@ -208,7 +208,7 @@ class BookController extends Controller |
| 208 | } | 208 | } |
| 209 | 209 | ||
| 210 | // Update permissions on changed models | 210 | // Update permissions on changed models |
| 211 | - $this->entityRepo->buildJointPermissions($updatedModels); | 211 | + if (count($updatedModels) === 0) $this->entityRepo->buildJointPermissions($updatedModels); |
| 212 | 212 | ||
| 213 | return redirect($book->getUrl()); | 213 | return redirect($book->getUrl()); |
| 214 | } | 214 | } | ... | ... |
| ... | @@ -243,13 +243,14 @@ class PermissionService | ... | @@ -243,13 +243,14 @@ class PermissionService |
| 243 | */ | 243 | */ |
| 244 | protected function deleteManyJointPermissionsForEntities($entities) | 244 | protected function deleteManyJointPermissionsForEntities($entities) |
| 245 | { | 245 | { |
| 246 | + if (count($entities) === 0) return; | ||
| 246 | $query = $this->jointPermission->newQuery(); | 247 | $query = $this->jointPermission->newQuery(); |
| 247 | - foreach ($entities as $entity) { | 248 | + foreach ($entities as $entity) { |
| 248 | - $query->orWhere(function($query) use ($entity) { | 249 | + $query->orWhere(function($query) use ($entity) { |
| 249 | - $query->where('entity_id', '=', $entity->id) | 250 | + $query->where('entity_id', '=', $entity->id) |
| 250 | - ->where('entity_type', '=', $entity->getMorphClass()); | 251 | + ->where('entity_type', '=', $entity->getMorphClass()); |
| 251 | - }); | 252 | + }); |
| 252 | - } | 253 | + } |
| 253 | $query->delete(); | 254 | $query->delete(); |
| 254 | } | 255 | } |
| 255 | 256 | ... | ... |
-
Please register or sign in to post a comment