]> BookStack Code Mirror - bookstack/blobdiff - app/Permissions/PermissionsController.php
Tests: Updated comment test to account for new editor usage
[bookstack] / app / Permissions / PermissionsController.php
index f2014ea73f6e50e459d588fc29c09800d3a68d1c..5d2035870bccd79ba4328ec973a18a4140201475 100644 (file)
@@ -2,10 +2,7 @@
 
 namespace BookStack\Permissions;
 
-use BookStack\Entities\Models\Book;
-use BookStack\Entities\Models\Bookshelf;
-use BookStack\Entities\Models\Chapter;
-use BookStack\Entities\Models\Page;
+use BookStack\Entities\Queries\EntityQueries;
 use BookStack\Entities\Tools\PermissionsUpdater;
 use BookStack\Http\Controller;
 use BookStack\Permissions\Models\EntityPermission;
@@ -14,19 +11,18 @@ use Illuminate\Http\Request;
 
 class PermissionsController extends Controller
 {
-    protected PermissionsUpdater $permissionsUpdater;
-
-    public function __construct(PermissionsUpdater $permissionsUpdater)
-    {
-        $this->permissionsUpdater = $permissionsUpdater;
+    public function __construct(
+        protected PermissionsUpdater $permissionsUpdater,
+        protected EntityQueries $queries,
+    ) {
     }
 
     /**
-     * Show the Permissions view for a page.
+     * Show the permissions view for a page.
      */
     public function showForPage(string $bookSlug, string $pageSlug)
     {
-        $page = Page::getBySlugs($bookSlug, $pageSlug);
+        $page = $this->queries->pages->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
         $this->checkOwnablePermission('restrictions-manage', $page);
 
         $this->setPageTitle(trans('entities.pages_permissions'));
@@ -41,7 +37,7 @@ class PermissionsController extends Controller
      */
     public function updateForPage(Request $request, string $bookSlug, string $pageSlug)
     {
-        $page = Page::getBySlugs($bookSlug, $pageSlug);
+        $page = $this->queries->pages->findVisibleBySlugsOrFail($bookSlug, $pageSlug);
         $this->checkOwnablePermission('restrictions-manage', $page);
 
         $this->permissionsUpdater->updateFromPermissionsForm($page, $request);
@@ -52,11 +48,11 @@ class PermissionsController extends Controller
     }
 
     /**
-     * Show the Restrictions view for a chapter.
+     * Show the permissions view for a chapter.
      */
     public function showForChapter(string $bookSlug, string $chapterSlug)
     {
-        $chapter = Chapter::getBySlugs($bookSlug, $chapterSlug);
+        $chapter = $this->queries->chapters->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
         $this->checkOwnablePermission('restrictions-manage', $chapter);
 
         $this->setPageTitle(trans('entities.chapters_permissions'));
@@ -67,11 +63,11 @@ class PermissionsController extends Controller
     }
 
     /**
-     * Set the restrictions for a chapter.
+     * Set the permissions for a chapter.
      */
     public function updateForChapter(Request $request, string $bookSlug, string $chapterSlug)
     {
-        $chapter = Chapter::getBySlugs($bookSlug, $chapterSlug);
+        $chapter = $this->queries->chapters->findVisibleBySlugsOrFail($bookSlug, $chapterSlug);
         $this->checkOwnablePermission('restrictions-manage', $chapter);
 
         $this->permissionsUpdater->updateFromPermissionsForm($chapter, $request);
@@ -86,7 +82,7 @@ class PermissionsController extends Controller
      */
     public function showForBook(string $slug)
     {
-        $book = Book::getBySlug($slug);
+        $book = $this->queries->books->findVisibleBySlugOrFail($slug);
         $this->checkOwnablePermission('restrictions-manage', $book);
 
         $this->setPageTitle(trans('entities.books_permissions'));
@@ -97,11 +93,11 @@ class PermissionsController extends Controller
     }
 
     /**
-     * Set the restrictions for a book.
+     * Set the permissions for a book.
      */
     public function updateForBook(Request $request, string $slug)
     {
-        $book = Book::getBySlug($slug);
+        $book = $this->queries->books->findVisibleBySlugOrFail($slug);
         $this->checkOwnablePermission('restrictions-manage', $book);
 
         $this->permissionsUpdater->updateFromPermissionsForm($book, $request);
@@ -116,7 +112,7 @@ class PermissionsController extends Controller
      */
     public function showForShelf(string $slug)
     {
-        $shelf = Bookshelf::getBySlug($slug);
+        $shelf = $this->queries->shelves->findVisibleBySlugOrFail($slug);
         $this->checkOwnablePermission('restrictions-manage', $shelf);
 
         $this->setPageTitle(trans('entities.shelves_permissions'));
@@ -131,7 +127,7 @@ class PermissionsController extends Controller
      */
     public function updateForShelf(Request $request, string $slug)
     {
-        $shelf = Bookshelf::getBySlug($slug);
+        $shelf = $this->queries->shelves->findVisibleBySlugOrFail($slug);
         $this->checkOwnablePermission('restrictions-manage', $shelf);
 
         $this->permissionsUpdater->updateFromPermissionsForm($shelf, $request);
@@ -146,7 +142,7 @@ class PermissionsController extends Controller
      */
     public function copyShelfPermissionsToBooks(string $slug)
     {
-        $shelf = Bookshelf::getBySlug($slug);
+        $shelf = $this->queries->shelves->findVisibleBySlugOrFail($slug);
         $this->checkOwnablePermission('restrictions-manage', $shelf);
 
         $updateCount = $this->permissionsUpdater->updateBookPermissionsFromShelf($shelf);