+ /**
+ * Show the permissions view.
+ * @param string $slug
+ * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ * @throws \BookStack\Exceptions\NotFoundException
+ */
+ public function showPermissions(string $slug)
+ {
+ $shelf = $this->entityRepo->getBySlug('bookshelf', $slug);
+ $this->checkOwnablePermission('restrictions-manage', $shelf);
+
+ $roles = $this->userRepo->getRestrictableRoles();
+ return view('shelves.permissions', [
+ 'shelf' => $shelf,
+ 'roles' => $roles
+ ]);
+ }
+
+ /**
+ * Set the permissions for this bookshelf.
+ * @param string $slug
+ * @param Request $request
+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ * @throws \BookStack\Exceptions\NotFoundException
+ * @throws \Throwable
+ */
+ public function permissions(string $slug, Request $request)
+ {
+ $shelf = $this->entityRepo->getBySlug('bookshelf', $slug);
+ $this->checkOwnablePermission('restrictions-manage', $shelf);
+
+ $this->entityRepo->updateEntityPermissionsFromRequest($request, $shelf);
+ session()->flash('success', trans('entities.shelves_permissions_updated'));
+ return redirect($shelf->getUrl());
+ }
+
+ /**
+ * Copy the permissions of a bookshelf to the child books.
+ * @param string $slug
+ * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ * @throws \BookStack\Exceptions\NotFoundException
+ */
+ public function copyPermissions(string $slug)
+ {
+ $shelf = $this->entityRepo->getBySlug('bookshelf', $slug);
+ $this->checkOwnablePermission('restrictions-manage', $shelf);
+
+ $updateCount = $this->entityRepo->copyBookshelfPermissions($shelf);
+ session()->flash('success', trans('entities.shelves_copy_permission_success', ['count' => $updateCount]));
+ return redirect($shelf->getUrl());
+ }
+
+ /**
+ * Common actions to run on bookshelf update.
+ * @param Bookshelf $shelf
+ * @param Request $request
+ * @throws \BookStack\Exceptions\ImageUploadException
+ */
+ protected function shelfUpdateActions(Bookshelf $shelf, Request $request)
+ {
+ // Update the books that the shelf references
+ $this->entityRepo->updateShelfBooks($shelf, $request->get('books', ''));
+
+ // Update the cover image if in request
+ if ($request->has('image')) {
+ $newImage = $request->file('image');
+ $this->imageRepo->destroyImage($shelf->cover);
+ $image = $this->imageRepo->saveNew($newImage, 'cover_shelf', $shelf->id, 512, 512, true);
+ $shelf->image_id = $image->id;
+ $shelf->save();
+ }
+
+ if ($request->has('image_reset')) {
+ $this->imageRepo->destroyImage($shelf->cover);
+ $shelf->image_id = 0;
+ $shelf->save();
+ }
+ }