mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-10-25 06:37:36 +03:00
Permissions: Updated usage of controller methods to use enum
This commit is contained in:
@@ -17,6 +17,7 @@ use BookStack\Exceptions\ImageUploadException;
|
||||
use BookStack\Exceptions\NotFoundException;
|
||||
use BookStack\Facades\Activity;
|
||||
use BookStack\Http\Controller;
|
||||
use BookStack\Permissions\Permission;
|
||||
use BookStack\References\ReferenceFetcher;
|
||||
use BookStack\Util\DatabaseTransaction;
|
||||
use BookStack\Util\SimpleListOptions;
|
||||
@@ -73,12 +74,12 @@ class BookController extends Controller
|
||||
*/
|
||||
public function create(?string $shelfSlug = null)
|
||||
{
|
||||
$this->checkPermission('book-create-all');
|
||||
$this->checkPermission(Permission::BookCreateAll);
|
||||
|
||||
$bookshelf = null;
|
||||
if ($shelfSlug !== null) {
|
||||
$bookshelf = $this->shelfQueries->findVisibleBySlugOrFail($shelfSlug);
|
||||
$this->checkOwnablePermission('bookshelf-update', $bookshelf);
|
||||
$this->checkOwnablePermission(Permission::BookshelfUpdate, $bookshelf);
|
||||
}
|
||||
|
||||
$this->setPageTitle(trans('entities.books_create'));
|
||||
@@ -96,7 +97,7 @@ class BookController extends Controller
|
||||
*/
|
||||
public function store(Request $request, ?string $shelfSlug = null)
|
||||
{
|
||||
$this->checkPermission('book-create-all');
|
||||
$this->checkPermission(Permission::BookCreateAll);
|
||||
$validated = $this->validate($request, [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'description_html' => ['string', 'max:2000'],
|
||||
@@ -108,7 +109,7 @@ class BookController extends Controller
|
||||
$bookshelf = null;
|
||||
if ($shelfSlug !== null) {
|
||||
$bookshelf = $this->shelfQueries->findVisibleBySlugOrFail($shelfSlug);
|
||||
$this->checkOwnablePermission('bookshelf-update', $bookshelf);
|
||||
$this->checkOwnablePermission(Permission::BookshelfUpdate, $bookshelf);
|
||||
}
|
||||
|
||||
$book = $this->bookRepo->create($validated);
|
||||
@@ -154,7 +155,7 @@ class BookController extends Controller
|
||||
public function edit(string $slug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlugOrFail($slug);
|
||||
$this->checkOwnablePermission('book-update', $book);
|
||||
$this->checkOwnablePermission(Permission::BookUpdate, $book);
|
||||
$this->setPageTitle(trans('entities.books_edit_named', ['bookName' => $book->getShortName()]));
|
||||
|
||||
return view('books.edit', ['book' => $book, 'current' => $book]);
|
||||
@@ -170,7 +171,7 @@ class BookController extends Controller
|
||||
public function update(Request $request, string $slug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlugOrFail($slug);
|
||||
$this->checkOwnablePermission('book-update', $book);
|
||||
$this->checkOwnablePermission(Permission::BookUpdate, $book);
|
||||
|
||||
$validated = $this->validate($request, [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
@@ -197,7 +198,7 @@ class BookController extends Controller
|
||||
public function showDelete(string $bookSlug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
|
||||
$this->checkOwnablePermission('book-delete', $book);
|
||||
$this->checkOwnablePermission(Permission::BookDelete, $book);
|
||||
$this->setPageTitle(trans('entities.books_delete_named', ['bookName' => $book->getShortName()]));
|
||||
|
||||
return view('books.delete', ['book' => $book, 'current' => $book]);
|
||||
@@ -211,7 +212,7 @@ class BookController extends Controller
|
||||
public function destroy(string $bookSlug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
|
||||
$this->checkOwnablePermission('book-delete', $book);
|
||||
$this->checkOwnablePermission(Permission::BookDelete, $book);
|
||||
|
||||
$this->bookRepo->destroy($book);
|
||||
|
||||
@@ -226,7 +227,7 @@ class BookController extends Controller
|
||||
public function showCopy(string $bookSlug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
|
||||
$this->checkOwnablePermission('book-view', $book);
|
||||
$this->checkOwnablePermission(Permission::BookView, $book);
|
||||
|
||||
session()->flashInput(['name' => $book->name]);
|
||||
|
||||
@@ -243,8 +244,8 @@ class BookController extends Controller
|
||||
public function copy(Request $request, Cloner $cloner, string $bookSlug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
|
||||
$this->checkOwnablePermission('book-view', $book);
|
||||
$this->checkPermission('book-create-all');
|
||||
$this->checkOwnablePermission(Permission::BookView, $book);
|
||||
$this->checkPermission(Permission::BookCreateAll);
|
||||
|
||||
$newName = $request->get('name') ?: $book->name;
|
||||
$bookCopy = $cloner->cloneBook($book, $newName);
|
||||
@@ -259,10 +260,10 @@ class BookController extends Controller
|
||||
public function convertToShelf(HierarchyTransformer $transformer, string $bookSlug)
|
||||
{
|
||||
$book = $this->queries->findVisibleBySlugOrFail($bookSlug);
|
||||
$this->checkOwnablePermission('book-update', $book);
|
||||
$this->checkOwnablePermission('book-delete', $book);
|
||||
$this->checkPermission('bookshelf-create-all');
|
||||
$this->checkPermission('book-create-all');
|
||||
$this->checkOwnablePermission(Permission::BookUpdate, $book);
|
||||
$this->checkOwnablePermission(Permission::BookDelete, $book);
|
||||
$this->checkPermission(Permission::BookshelfCreateAll);
|
||||
$this->checkPermission(Permission::BookCreateAll);
|
||||
|
||||
$shelf = (new DatabaseTransaction(function () use ($book, $transformer) {
|
||||
return $transformer->transformBookToShelf($book);
|
||||
|
||||
Reference in New Issue
Block a user