Skip to content

Commit 492e2f1

Browse files
committed
Fixed error causing permissions to be deleted on book sort
Closes #282
1 parent 380f0f2 commit 492e2f1

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

app/Http/Controllers/BookController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public function saveSort($bookSlug, Request $request)
208208
}
209209

210210
// Update permissions on changed models
211-
$this->entityRepo->buildJointPermissions($updatedModels);
211+
if (count($updatedModels) === 0) $this->entityRepo->buildJointPermissions($updatedModels);
212212

213213
return redirect($book->getUrl());
214214
}

app/Services/PermissionService.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,14 @@ public function deleteJointPermissionsForEntity(Entity $entity)
243243
*/
244244
protected function deleteManyJointPermissionsForEntities($entities)
245245
{
246+
if (count($entities) === 0) return;
246247
$query = $this->jointPermission->newQuery();
247-
foreach ($entities as $entity) {
248-
$query->orWhere(function($query) use ($entity) {
249-
$query->where('entity_id', '=', $entity->id)
250-
->where('entity_type', '=', $entity->getMorphClass());
251-
});
252-
}
248+
foreach ($entities as $entity) {
249+
$query->orWhere(function($query) use ($entity) {
250+
$query->where('entity_id', '=', $entity->id)
251+
->where('entity_type', '=', $entity->getMorphClass());
252+
});
253+
}
253254
$query->delete();
254255
}
255256

0 commit comments

Comments
 (0)