]> BookStack Code Mirror - bookstack/blobdiff - app/Entities/Repos/EntityRepo.php
Show bookshelves that a book belongs to on a book view
[bookstack] / app / Entities / Repos / EntityRepo.php
index c5fb3501e79fe6b2b265f756b816e3585521cb89..0dd0fbb0af650f0e3c050171a48673a030a55ee3 100644 (file)
@@ -413,6 +413,17 @@ class EntityRepo
         return collect($tree);
     }
 
+
+    /**
+     * Get the bookshelves that a book is contained in.
+     * @param Book $book
+     * @return \Illuminate\Database\Eloquent\Collection|static[]
+     */
+    public function getBookParentShelves(Book $book)
+    {
+        return $this->permissionService->enforceEntityRestrictions('shelf', $book->shelves())->get();
+    }
+
     /**
      * Get the child items for a chapter sorted by priority but
      * with draft items floated to the top.
@@ -478,14 +489,16 @@ class EntityRepo
         $entity->permissions()->delete();
 
         if ($request->filled('restrictions')) {
-            foreach ($request->get('restrictions') as $roleId => $restrictions) {
-                foreach ($restrictions as $action => $value) {
-                    $entity->permissions()->create([
+            $entityPermissionData = collect($request->get('restrictions'))->flatMap(function($restrictions, $roleId) {
+                return collect($restrictions)->keys()->map(function($action) use ($roleId) {
+                    return [
                         'role_id' => $roleId,
-                        'action'  => strtolower($action),
-                    ]);
-                }
-            }
+                        'action' => strtolower($action),
+                    ] ;
+                });
+            });
+
+            $entity->permissions()->createMany($entityPermissionData);
         }
 
         $entity->save();
@@ -525,10 +538,9 @@ class EntityRepo
 
     /**
      * Update entity details from request input.
-     * Used for books and chapters.
-     * TODO: Remove type param
+     * Used for shelves, books and chapters.
      */
-    public function updateFromInput(string $type, Entity $entityModel, array $input = []): Entity
+    public function updateFromInput(Entity $entityModel, array $input): Entity
     {
         $entityModel->fill($input);
         $entityModel->updated_by = user()->id;