Skip to content

Commit

Permalink
Fixed error causing permissions to be deleted on book sort
Browse files Browse the repository at this point in the history
Closes #282
  • Loading branch information
ssddanbrown committed Jan 23, 2017
1 parent 380f0f2 commit 492e2f1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/BookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public function saveSort($bookSlug, Request $request)
}

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

return redirect($book->getUrl());
}
Expand Down
13 changes: 7 additions & 6 deletions app/Services/PermissionService.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,14 @@ public function deleteJointPermissionsForEntity(Entity $entity)
*/
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();
}

Expand Down

0 comments on commit 492e2f1

Please sign in to comment.