X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/a3ead5062acc169ae3486d90ac2befe3db86bfe6..refs/pull/3579/head:/app/Http/Controllers/BookshelfController.php diff --git a/app/Http/Controllers/BookshelfController.php b/app/Http/Controllers/BookshelfController.php index 3bcdfbfb8..feb581c78 100644 --- a/app/Http/Controllers/BookshelfController.php +++ b/app/Http/Controllers/BookshelfController.php @@ -2,7 +2,6 @@ namespace BookStack\Http\Controllers; -use Activity; use BookStack\Actions\ActivityQueries; use BookStack\Actions\View; use BookStack\Entities\Models\Book; @@ -69,7 +68,7 @@ class BookshelfController extends Controller public function create() { $this->checkPermission('bookshelf-create-all'); - $books = Book::hasPermission('update')->get(); + $books = Book::visible()->get(); $this->setPageTitle(trans('entities.shelves_create')); return view('shelves.create', ['books' => $books]); @@ -84,15 +83,15 @@ class BookshelfController extends Controller public function store(Request $request) { $this->checkPermission('bookshelf-create-all'); - $this->validate($request, [ + $validated = $this->validate($request, [ 'name' => ['required', 'string', 'max:255'], 'description' => ['string', 'max:1000'], 'image' => array_merge(['nullable'], $this->getImageValidationRules()), + 'tags' => ['array'], ]); $bookIds = explode(',', $request->get('books', '')); - $shelf = $this->bookshelfRepo->create($request->all(), $bookIds); - $this->bookshelfRepo->updateCoverImage($shelf, $request->file('image', null)); + $shelf = $this->bookshelfRepo->create($validated, $bookIds); return redirect($shelf->getUrl()); } @@ -105,7 +104,7 @@ class BookshelfController extends Controller public function show(ActivityQueries $activities, string $slug) { $shelf = $this->bookshelfRepo->getBySlug($slug); - $this->checkOwnablePermission('book-view', $shelf); + $this->checkOwnablePermission('bookshelf-view', $shelf); $sort = setting()->getForCurrentUser('shelf_books_sort', 'default'); $order = setting()->getForCurrentUser('shelf_books_sort_order', 'asc'); @@ -140,7 +139,7 @@ class BookshelfController extends Controller $this->checkOwnablePermission('bookshelf-update', $shelf); $shelfBookIds = $shelf->books()->get(['id'])->pluck('id'); - $books = Book::hasPermission('update')->whereNotIn('id', $shelfBookIds)->get(); + $books = Book::visible()->whereNotIn('id', $shelfBookIds)->get(); $this->setPageTitle(trans('entities.shelves_edit_named', ['name' => $shelf->getShortName()])); @@ -161,16 +160,21 @@ class BookshelfController extends Controller { $shelf = $this->bookshelfRepo->getBySlug($slug); $this->checkOwnablePermission('bookshelf-update', $shelf); - $this->validate($request, [ + $validated = $this->validate($request, [ 'name' => ['required', 'string', 'max:255'], 'description' => ['string', 'max:1000'], 'image' => array_merge(['nullable'], $this->getImageValidationRules()), + 'tags' => ['array'], ]); + if ($request->has('image_reset')) { + $validated['image'] = null; + } elseif (array_key_exists('image', $validated) && is_null($validated['image'])) { + unset($validated['image']); + } + $bookIds = explode(',', $request->get('books', '')); - $shelf = $this->bookshelfRepo->update($shelf, $request->all(), $bookIds); - $resetCover = $request->has('image_reset'); - $this->bookshelfRepo->updateCoverImage($shelf, $request->file('image', null), $resetCover); + $shelf = $this->bookshelfRepo->update($shelf, $validated, $bookIds); return redirect($shelf->getUrl()); }