3 namespace BookStack\Http\Controllers;
5 use BookStack\Entities\Models\Book;
6 use BookStack\Entities\Models\Bookshelf;
7 use BookStack\Entities\Models\Chapter;
8 use BookStack\Entities\Models\Page;
9 use BookStack\Entities\Tools\PermissionsUpdater;
10 use Illuminate\Http\Request;
12 class PermissionsController extends Controller
14 protected PermissionsUpdater $permissionsUpdater;
16 public function __construct(PermissionsUpdater $permissionsUpdater)
18 $this->permissionsUpdater = $permissionsUpdater;
22 * Show the Permissions view for a page.
24 public function showForPage(string $bookSlug, string $pageSlug)
26 $page = Page::getBySlugs($bookSlug, $pageSlug);
27 $this->checkOwnablePermission('restrictions-manage', $page);
29 return view('pages.permissions', [
35 * Set the permissions for a page.
37 public function updateForPage(Request $request, string $bookSlug, string $pageSlug)
39 $page = Page::getBySlugs($bookSlug, $pageSlug);
40 $this->checkOwnablePermission('restrictions-manage', $page);
42 $this->permissionsUpdater->updateFromPermissionsForm($page, $request);
44 $this->showSuccessNotification(trans('entities.pages_permissions_success'));
46 return redirect($page->getUrl());
50 * Show the Restrictions view for a chapter.
52 public function showForChapter(string $bookSlug, string $chapterSlug)
54 $chapter = Chapter::getBySlugs($bookSlug, $chapterSlug);
55 $this->checkOwnablePermission('restrictions-manage', $chapter);
57 return view('chapters.permissions', [
58 'chapter' => $chapter,
63 * Set the restrictions for a chapter.
65 public function updateForChapter(Request $request, string $bookSlug, string $chapterSlug)
67 $chapter = Chapter::getBySlugs($bookSlug, $chapterSlug);
68 $this->checkOwnablePermission('restrictions-manage', $chapter);
70 $this->permissionsUpdater->updateFromPermissionsForm($chapter, $request);
72 $this->showSuccessNotification(trans('entities.chapters_permissions_success'));
74 return redirect($chapter->getUrl());
78 * Show the permissions view for a book.
80 public function showForBook(string $slug)
82 $book = Book::getBySlug($slug);
83 $this->checkOwnablePermission('restrictions-manage', $book);
85 return view('books.permissions', [
91 * Set the restrictions for a book.
93 public function updateForBook(Request $request, string $slug)
95 $book = Book::getBySlug($slug);
96 $this->checkOwnablePermission('restrictions-manage', $book);
98 $this->permissionsUpdater->updateFromPermissionsForm($book, $request);
100 $this->showSuccessNotification(trans('entities.books_permissions_updated'));
102 return redirect($book->getUrl());
106 * Show the permissions view for a shelf.
108 public function showForShelf(string $slug)
110 $shelf = Bookshelf::getBySlug($slug);
111 $this->checkOwnablePermission('restrictions-manage', $shelf);
113 return view('shelves.permissions', [
119 * Set the permissions for a shelf.
121 public function updateForShelf(Request $request, string $slug)
123 $shelf = Bookshelf::getBySlug($slug);
124 $this->checkOwnablePermission('restrictions-manage', $shelf);
126 $this->permissionsUpdater->updateFromPermissionsForm($shelf, $request);
128 $this->showSuccessNotification(trans('entities.shelves_permissions_updated'));
130 return redirect($shelf->getUrl());
134 * Copy the permissions of a bookshelf to the child books.
136 public function copyShelfPermissionsToBooks(string $slug)
138 $shelf = Bookshelf::getBySlug($slug);
139 $this->checkOwnablePermission('restrictions-manage', $shelf);
141 $updateCount = $this->permissionsUpdater->updateBookPermissionsFromShelf($shelf);
142 $this->showSuccessNotification(trans('entities.shelves_copy_permission_success', ['count' => $updateCount]));
144 return redirect($shelf->getUrl());