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;
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'));
*/
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);
}
/**
- * 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'));
}
/**
- * 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);
*/
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'));
}
/**
- * 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);
*/
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'));
*/
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);
*/
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);