]> BookStack Code Mirror - bookstack/blobdiff - app/Repos/BookRepo.php
replace GPL diff lib with MIT lib
[bookstack] / app / Repos / BookRepo.php
index 864b1e24095ca65f70e0d913ab395f13ae9e5d28..a11ed2763c9ce51ad7efc23d1678e1f06eeb9af1 100644 (file)
@@ -30,7 +30,7 @@ class BookRepo extends EntityRepo
      */
     private function bookQuery()
     {
-        return $this->restrictionService->enforceBookRestrictions($this->book, 'view');
+        return $this->permissionService->enforceBookRestrictions($this->book, 'view');
     }
 
     /**
@@ -134,7 +134,7 @@ class BookRepo extends EntityRepo
         $book->created_by = auth()->user()->id;
         $book->updated_by = auth()->user()->id;
         $book->save();
-        $this->restrictionService->buildEntityPermissionsForEntity($book);
+        $this->permissionService->buildJointPermissionsForEntity($book);
         return $book;
     }
 
@@ -150,7 +150,7 @@ class BookRepo extends EntityRepo
         $book->slug = $this->findSuitableSlug($book->name, $book->id);
         $book->updated_by = auth()->user()->id;
         $book->save();
-        $this->restrictionService->buildEntityPermissionsForEntity($book);
+        $this->permissionService->buildJointPermissionsForEntity($book);
         return $book;
     }
 
@@ -168,18 +168,18 @@ class BookRepo extends EntityRepo
             $this->chapterRepo->destroy($chapter);
         }
         $book->views()->delete();
-        $book->restrictions()->delete();
-        $this->restrictionService->deleteEntityPermissionsForEntity($book);
+        $book->permissions()->delete();
+        $this->permissionService->deleteJointPermissionsForEntity($book);
         $book->delete();
     }
 
     /**
-     * Alias method to update the book permissions in the RestrictionService.
+     * Alias method to update the book jointPermissions in the PermissionService.
      * @param Book $book
      */
     public function updateBookPermissions(Book $book)
     {
-        $this->restrictionService->buildEntityPermissionsForEntity($book);
+        $this->permissionService->buildJointPermissionsForEntity($book);
     }
 
     /**
@@ -237,7 +237,7 @@ class BookRepo extends EntityRepo
     public function getChildren(Book $book, $filterDrafts = false)
     {
         $pageQuery = $book->pages()->where('chapter_id', '=', 0);
-        $pageQuery = $this->restrictionService->enforcePageRestrictions($pageQuery, 'view');
+        $pageQuery = $this->permissionService->enforcePageRestrictions($pageQuery, 'view');
 
         if ($filterDrafts) {
             $pageQuery = $pageQuery->where('draft', '=', false);
@@ -246,12 +246,15 @@ class BookRepo extends EntityRepo
         $pages = $pageQuery->get();
 
         $chapterQuery = $book->chapters()->with(['pages' => function($query) use ($filterDrafts) {
-            $this->restrictionService->enforcePageRestrictions($query, 'view');
+            $this->permissionService->enforcePageRestrictions($query, 'view');
             if ($filterDrafts) $query->where('draft', '=', false);
         }]);
-        $chapterQuery = $this->restrictionService->enforceChapterRestrictions($chapterQuery, 'view');
+        $chapterQuery = $this->permissionService->enforceChapterRestrictions($chapterQuery, 'view');
         $chapters = $chapterQuery->get();
-        $children = $pages->merge($chapters);
+        $children = $pages->values();
+        foreach ($chapters as $chapter) {
+            $children->push($chapter);
+        }
         $bookSlug = $book->slug;
 
         $children->each(function ($child) use ($bookSlug) {
@@ -286,8 +289,9 @@ class BookRepo extends EntityRepo
     public function getBySearch($term, $count = 20, $paginationAppends = [])
     {
         $terms = $this->prepareSearchTerms($term);
-        $books = $this->restrictionService->enforceBookRestrictions($this->book->fullTextSearchQuery(['name', 'description'], $terms))
-            ->paginate($count)->appends($paginationAppends);
+        $bookQuery = $this->permissionService->enforceBookRestrictions($this->book->fullTextSearchQuery(['name', 'description'], $terms));
+        $bookQuery = $this->addAdvancedSearchQueries($bookQuery, $term);
+        $books = $bookQuery->paginate($count)->appends($paginationAppends);
         $words = join('|', explode(' ', preg_quote(trim($term), '/')));
         foreach ($books as $book) {
             //highlight