<?php namespace BookStack\Http\Controllers;
-use Activity;
+use BookStack\Entities\Tools\BookContents;
+use BookStack\Entities\Tools\PageContent;
+use BookStack\Entities\Tools\PageEditActivity;
+use BookStack\Entities\Models\Page;
+use BookStack\Entities\Repos\PageRepo;
+use BookStack\Entities\Tools\PermissionsUpdater;
use BookStack\Exceptions\NotFoundException;
-use BookStack\Repos\UserRepo;
-use BookStack\Services\ExportService;
+use BookStack\Exceptions\NotifyException;
+use BookStack\Exceptions\PermissionsException;
+use Exception;
use Illuminate\Http\Request;
-use BookStack\Http\Requests;
-use BookStack\Repos\BookRepo;
-use BookStack\Repos\ChapterRepo;
-use BookStack\Repos\PageRepo;
-use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
+use Illuminate\Validation\ValidationException;
+use Throwable;
use Views;
class PageController extends Controller
{
protected $pageRepo;
- protected $bookRepo;
- protected $chapterRepo;
- protected $exportService;
- protected $userRepo;
/**
* PageController constructor.
- * @param PageRepo $pageRepo
- * @param BookRepo $bookRepo
- * @param ChapterRepo $chapterRepo
- * @param ExportService $exportService
- * @param UserRepo $userRepo
*/
- public function __construct(PageRepo $pageRepo, BookRepo $bookRepo, ChapterRepo $chapterRepo, ExportService $exportService, UserRepo $userRepo)
+ public function __construct(PageRepo $pageRepo)
{
$this->pageRepo = $pageRepo;
- $this->bookRepo = $bookRepo;
- $this->chapterRepo = $chapterRepo;
- $this->exportService = $exportService;
- $this->userRepo = $userRepo;
- parent::__construct();
}
/**
* Show the form for creating a new page.
- * @param $bookSlug
- * @param bool $chapterSlug
- * @return Response
- * @internal param bool $pageSlug
+ * @throws Throwable
*/
- public function create($bookSlug, $chapterSlug = false)
+ public function create(string $bookSlug, string $chapterSlug = null)
{
- $book = $this->bookRepo->getBySlug($bookSlug);
- $chapter = $chapterSlug ? $this->chapterRepo->getBySlug($chapterSlug, $book->id) : false;
- $parent = $chapter ? $chapter : $book;
+ $parent = $this->pageRepo->getParentFromSlugs($bookSlug, $chapterSlug);
$this->checkOwnablePermission('page-create', $parent);
- $this->setPageTitle('Create New Page');
- return view('pages/create', ['book' => $book, 'chapter' => $chapter]);
+
+ // Redirect to draft edit screen if signed in
+ if ($this->isSignedIn()) {
+ $draft = $this->pageRepo->getNewDraftPage($parent);
+ return redirect($draft->getUrl());
+ }
+
+ // Otherwise show the edit view if they're a guest
+ $this->setPageTitle(trans('entities.pages_new'));
+ return view('pages.guest-create', ['parent' => $parent]);
}
/**
- * Store a newly created page in storage.
- * @param Request $request
- * @param $bookSlug
- * @return Response
+ * Create a new page as a guest user.
+ * @throws ValidationException
*/
- public function store(Request $request, $bookSlug)
+ public function createAsGuest(Request $request, string $bookSlug, string $chapterSlug = null)
{
$this->validate($request, [
- 'name' => 'required|string|max:255'
+ 'name' => 'required|string|max:255'
]);
- $input = $request->all();
- $book = $this->bookRepo->getBySlug($bookSlug);
- $chapterId = ($request->has('chapter') && $this->chapterRepo->idExists($request->get('chapter'))) ? $request->get('chapter') : null;
- $parent = $chapterId !== null ? $this->chapterRepo->getById($chapterId) : $book;
+ $parent = $this->pageRepo->getParentFromSlugs($bookSlug, $chapterSlug);
$this->checkOwnablePermission('page-create', $parent);
- $input['priority'] = $this->bookRepo->getNewPriority($book);
- $page = $this->pageRepo->saveNew($input, $book, $chapterId);
+ $page = $this->pageRepo->getNewDraftPage($parent);
+ $this->pageRepo->publishDraft($page, [
+ 'name' => $request->get('name'),
+ 'html' => ''
+ ]);
+
+ return redirect($page->getUrl('/edit'));
+ }
+
+ /**
+ * Show form to continue editing a draft page.
+ * @throws NotFoundException
+ */
+ public function editDraft(string $bookSlug, int $pageId)
+ {
+ $draft = $this->pageRepo->getById($pageId);
+ $this->checkOwnablePermission('page-create', $draft->getParent());
+ $this->setPageTitle(trans('entities.pages_edit_draft'));
+
+ $draftsEnabled = $this->isSignedIn();
+ $templates = $this->pageRepo->getTemplates(10);
+
+ return view('pages.edit', [
+ 'page' => $draft,
+ 'book' => $draft->book,
+ 'isDraft' => true,
+ 'draftsEnabled' => $draftsEnabled,
+ 'templates' => $templates,
+ ]);
+ }
+
+ /**
+ * Store a new page by changing a draft into a page.
+ * @throws NotFoundException
+ * @throws ValidationException
+ */
+ public function store(Request $request, string $bookSlug, int $pageId)
+ {
+ $this->validate($request, [
+ 'name' => 'required|string|max:255'
+ ]);
+ $draftPage = $this->pageRepo->getById($pageId);
+ $this->checkOwnablePermission('page-create', $draftPage->getParent());
+
+ $page = $this->pageRepo->publishDraft($draftPage, $request->all());
- Activity::add($page, 'page_create', $book->id);
return redirect($page->getUrl());
}
/**
* Display the specified page.
- * If the page is not found via the slug the
- * revisions are searched for a match.
- * @param $bookSlug
- * @param $pageSlug
- * @return Response
+ * If the page is not found via the slug the revisions are searched for a match.
+ * @throws NotFoundException
*/
- public function show($bookSlug, $pageSlug)
+ public function show(string $bookSlug, string $pageSlug)
{
- $book = $this->bookRepo->getBySlug($bookSlug);
-
try {
- $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+ $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
} catch (NotFoundException $e) {
- $page = $this->pageRepo->findPageUsingOldSlug($pageSlug, $bookSlug);
- if ($page === null) abort(404);
+ $page = $this->pageRepo->getByOldSlug($bookSlug, $pageSlug);
+
+ if ($page === null) {
+ throw $e;
+ }
+
return redirect($page->getUrl());
}
- $sidebarTree = $this->bookRepo->getChildren($book);
+ $this->checkOwnablePermission('page-view', $page);
+
+ $pageContent = (new PageContent($page));
+ $page->html = $pageContent->render();
+ $sidebarTree = (new BookContents($page->book))->getTree();
+ $pageNav = $pageContent->getNavigation($page->html);
+
+ // Check if page comments are enabled
+ $commentsEnabled = !setting('app-disable-comments');
+ if ($commentsEnabled) {
+ $page->load(['comments.createdBy']);
+ }
+
Views::add($page);
$this->setPageTitle($page->getShortName());
- return view('pages/show', ['page' => $page, 'book' => $book, 'current' => $page, 'sidebarTree' => $sidebarTree]);
+ return view('pages.show', [
+ 'page' => $page,
+ 'book' => $page->book,
+ 'current' => $page,
+ 'sidebarTree' => $sidebarTree,
+ 'commentsEnabled' => $commentsEnabled,
+ 'pageNav' => $pageNav
+ ]);
}
/**
* Get page from an ajax request.
- * @param $pageId
- * @return \Illuminate\Http\JsonResponse
+ * @throws NotFoundException
*/
- public function getPageAjax($pageId)
+ public function getPageAjax(int $pageId)
{
$page = $this->pageRepo->getById($pageId);
+ $page->setHidden(array_diff($page->getHidden(), ['html', 'markdown']));
+ $page->addHidden(['book']);
return response()->json($page);
}
/**
* Show the form for editing the specified page.
- * @param $bookSlug
- * @param $pageSlug
- * @return Response
+ * @throws NotFoundException
*/
- public function edit($bookSlug, $pageSlug)
+ public function edit(string $bookSlug, string $pageSlug)
{
- $book = $this->bookRepo->getBySlug($bookSlug);
- $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+ $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
$this->checkOwnablePermission('page-update', $page);
- $this->setPageTitle('Editing Page ' . $page->getShortName());
+
$page->isDraft = false;
+ $editActivity = new PageEditActivity($page);
- // Check for active editing and drafts
+ // Check for active editing
$warnings = [];
- if ($this->pageRepo->isPageEditingActive($page, 60)) {
- $warnings[] = $this->pageRepo->getPageEditingActiveMessage($page, 60);
+ if ($editActivity->hasActiveEditing()) {
+ $warnings[] = $editActivity->activeEditingMessage();
}
- if ($this->pageRepo->hasUserGotPageDraft($page, $this->currentUser->id)) {
- $draft = $this->pageRepo->getUserPageDraft($page, $this->currentUser->id);
- $page->name = $draft->name;
- $page->html = $draft->html;
+ // Check for a current draft version for this user
+ $userDraft = $this->pageRepo->getUserDraft($page);
+ if ($userDraft !== null) {
+ $page->forceFill($userDraft->only(['name', 'html', 'markdown']));
$page->isDraft = true;
- $warnings [] = $this->pageRepo->getUserPageDraftMessage($draft);
+ $warnings[] = $editActivity->getEditingActiveDraftMessage($userDraft);
}
- if (count($warnings) > 0) session()->flash('warning', implode("\n", $warnings));
+ if (count($warnings) > 0) {
+ $this->showWarningNotification(implode("\n", $warnings));
+ }
- return view('pages/edit', ['page' => $page, 'book' => $book, 'current' => $page]);
+ $templates = $this->pageRepo->getTemplates(10);
+ $draftsEnabled = $this->isSignedIn();
+ $this->setPageTitle(trans('entities.pages_editing_named', ['pageName' => $page->getShortName()]));
+ return view('pages.edit', [
+ 'page' => $page,
+ 'book' => $page->book,
+ 'current' => $page,
+ 'draftsEnabled' => $draftsEnabled,
+ 'templates' => $templates,
+ ]);
}
/**
* Update the specified page in storage.
- * @param Request $request
- * @param $bookSlug
- * @param $pageSlug
- * @return Response
+ * @throws ValidationException
+ * @throws NotFoundException
*/
- public function update(Request $request, $bookSlug, $pageSlug)
+ public function update(Request $request, string $bookSlug, string $pageSlug)
{
$this->validate($request, [
- 'name' => 'required|string|max:255'
+ 'name' => 'required|string|max:255'
]);
- $book = $this->bookRepo->getBySlug($bookSlug);
- $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+ $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
$this->checkOwnablePermission('page-update', $page);
- $this->pageRepo->updatePage($page, $book->id, $request->all());
- Activity::add($page, 'page_update', $book->id);
+
+ $this->pageRepo->update($page, $request->all());
+
return redirect($page->getUrl());
}
/**
* Save a draft update as a revision.
- * @param Request $request
- * @param $pageId
- * @return \Illuminate\Http\JsonResponse
+ * @throws NotFoundException
*/
- public function saveUpdateDraft(Request $request, $pageId)
+ public function saveDraft(Request $request, int $pageId)
{
- $this->validate($request, [
- 'name' => 'required|string|max:255'
- ]);
$page = $this->pageRepo->getById($pageId);
$this->checkOwnablePermission('page-update', $page);
- $draft = $this->pageRepo->saveUpdateDraft($page, $request->only(['name', 'html']));
- $updateTime = $draft->updated_at->format('H:i');
- return response()->json(['status' => 'success', 'message' => 'Draft saved at ' . $updateTime]);
+
+ if (!$this->isSignedIn()) {
+ return $this->jsonError(trans('errors.guests_cannot_save_drafts'), 500);
+ }
+
+ $draft = $this->pageRepo->updatePageDraft($page, $request->only(['name', 'html', 'markdown']));
+
+ $updateTime = $draft->updated_at->timestamp;
+ return response()->json([
+ 'status' => 'success',
+ 'message' => trans('entities.pages_edit_draft_save_at'),
+ 'timestamp' => $updateTime
+ ]);
}
/**
- * Redirect from a special link url which
- * uses the page id rather than the name.
- * @param $pageId
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ * Redirect from a special link url which uses the page id rather than the name.
+ * @throws NotFoundException
*/
- public function redirectFromLink($pageId)
+ public function redirectFromLink(int $pageId)
{
$page = $this->pageRepo->getById($pageId);
return redirect($page->getUrl());
/**
* Show the deletion page for the specified page.
- * @param $bookSlug
- * @param $pageSlug
- * @return \Illuminate\View\View
+ * @throws NotFoundException
*/
- public function showDelete($bookSlug, $pageSlug)
+ public function showDelete(string $bookSlug, string $pageSlug)
{
- $book = $this->bookRepo->getBySlug($bookSlug);
- $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+ $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
$this->checkOwnablePermission('page-delete', $page);
- $this->setPageTitle('Delete Page ' . $page->getShortName());
- return view('pages/delete', ['book' => $book, 'page' => $page, 'current' => $page]);
+ $this->setPageTitle(trans('entities.pages_delete_named', ['pageName'=>$page->getShortName()]));
+ return view('pages.delete', [
+ 'book' => $page->book,
+ 'page' => $page,
+ 'current' => $page
+ ]);
}
/**
- * Remove the specified page from storage.
- *
- * @param $bookSlug
- * @param $pageSlug
- * @return Response
- * @internal param int $id
+ * Show the deletion page for the specified page.
+ * @throws NotFoundException
*/
- public function destroy($bookSlug, $pageSlug)
+ public function showDeleteDraft(string $bookSlug, int $pageId)
{
- $book = $this->bookRepo->getBySlug($bookSlug);
- $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
- $this->checkOwnablePermission('page-delete', $page);
- Activity::addMessage('page_delete', $book->id, $page->name);
- $this->pageRepo->destroy($page);
- return redirect($book->getUrl());
+ $page = $this->pageRepo->getById($pageId);
+ $this->checkOwnablePermission('page-update', $page);
+ $this->setPageTitle(trans('entities.pages_delete_draft_named', ['pageName'=>$page->getShortName()]));
+ return view('pages.delete', [
+ 'book' => $page->book,
+ 'page' => $page,
+ 'current' => $page
+ ]);
}
/**
- * Shows the last revisions for this page.
- * @param $bookSlug
- * @param $pageSlug
- * @return \Illuminate\View\View
+ * Remove the specified page from storage.
+ * @throws NotFoundException
+ * @throws Throwable
+ * @throws NotifyException
*/
- public function showRevisions($bookSlug, $pageSlug)
+ public function destroy(string $bookSlug, string $pageSlug)
{
- $book = $this->bookRepo->getBySlug($bookSlug);
- $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
- $this->setPageTitle('Revisions For ' . $page->getShortName());
- return view('pages/revisions', ['page' => $page, 'book' => $book, 'current' => $page]);
- }
+ $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
+ $this->checkOwnablePermission('page-delete', $page);
+ $parent = $page->getParent();
- /**
- * Shows a preview of a single revision
- * @param $bookSlug
- * @param $pageSlug
- * @param $revisionId
- * @return \Illuminate\View\View
- */
- public function showRevision($bookSlug, $pageSlug, $revisionId)
- {
- $book = $this->bookRepo->getBySlug($bookSlug);
- $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
- $revision = $this->pageRepo->getRevisionById($revisionId);
- $page->fill($revision->toArray());
- $this->setPageTitle('Page Revision For ' . $page->getShortName());
- return view('pages/revision', ['page' => $page, 'book' => $book]);
+ $this->pageRepo->destroy($page);
+
+ return redirect($parent->getUrl());
}
/**
- * Restores a page using the content of the specified revision.
- * @param $bookSlug
- * @param $pageSlug
- * @param $revisionId
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ * Remove the specified draft page from storage.
+ * @throws NotFoundException
+ * @throws NotifyException
+ * @throws Throwable
*/
- public function restoreRevision($bookSlug, $pageSlug, $revisionId)
+ public function destroyDraft(string $bookSlug, int $pageId)
{
- $book = $this->bookRepo->getBySlug($bookSlug);
- $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+ $page = $this->pageRepo->getById($pageId);
+ $book = $page->book;
+ $chapter = $page->chapter;
$this->checkOwnablePermission('page-update', $page);
- $page = $this->pageRepo->restoreRevision($page, $book, $revisionId);
- Activity::add($page, 'page_restore', $book->id);
- return redirect($page->getUrl());
+
+ $this->pageRepo->destroy($page);
+
+ $this->showSuccessNotification(trans('entities.pages_delete_draft_success'));
+
+ if ($chapter && userCan('view', $chapter)) {
+ return redirect($chapter->getUrl());
+ }
+ return redirect($book->getUrl());
}
/**
- * Exports a page to pdf format using barryvdh/laravel-dompdf wrapper.
- * https://github.com/barryvdh/laravel-dompdf
- * @param $bookSlug
- * @param $pageSlug
- * @return \Illuminate\Http\Response
+ * Show a listing of recently created pages.
*/
- public function exportPdf($bookSlug, $pageSlug)
+ public function showRecentlyUpdated()
{
- $book = $this->bookRepo->getBySlug($bookSlug);
- $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
- $pdfContent = $this->exportService->pageToPdf($page);
- return response()->make($pdfContent, 200, [
- 'Content-Type' => 'application/octet-stream',
- 'Content-Disposition' => 'attachment; filename="'.$pageSlug.'.pdf'
+ $pages = Page::visible()->orderBy('updated_at', 'desc')
+ ->paginate(20)
+ ->setPath(url('/pages/recently-updated'));
+
+ return view('pages.detailed-listing', [
+ 'title' => trans('entities.recently_updated_pages'),
+ 'pages' => $pages
]);
}
/**
- * Export a page to a self-contained HTML file.
- * @param $bookSlug
- * @param $pageSlug
- * @return \Illuminate\Http\Response
+ * Show the view to choose a new parent to move a page into.
+ * @throws NotFoundException
*/
- public function exportHtml($bookSlug, $pageSlug)
+ public function showMove(string $bookSlug, string $pageSlug)
{
- $book = $this->bookRepo->getBySlug($bookSlug);
- $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
- $containedHtml = $this->exportService->pageToContainedHtml($page);
- return response()->make($containedHtml, 200, [
- 'Content-Type' => 'application/octet-stream',
- 'Content-Disposition' => 'attachment; filename="'.$pageSlug.'.html'
+ $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
+ $this->checkOwnablePermission('page-update', $page);
+ $this->checkOwnablePermission('page-delete', $page);
+ return view('pages.move', [
+ 'book' => $page->book,
+ 'page' => $page
]);
}
/**
- * Export a page to a simple plaintext .txt file.
- * @param $bookSlug
- * @param $pageSlug
- * @return \Illuminate\Http\Response
+ * Does the action of moving the location of a page.
+ * @throws NotFoundException
+ * @throws Throwable
*/
- public function exportPlainText($bookSlug, $pageSlug)
+ public function move(Request $request, string $bookSlug, string $pageSlug)
{
- $book = $this->bookRepo->getBySlug($bookSlug);
- $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
- $containedHtml = $this->exportService->pageToPlainText($page);
- return response()->make($containedHtml, 200, [
- 'Content-Type' => 'application/octet-stream',
- 'Content-Disposition' => 'attachment; filename="'.$pageSlug.'.txt'
- ]);
+ $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
+ $this->checkOwnablePermission('page-update', $page);
+ $this->checkOwnablePermission('page-delete', $page);
+
+ $entitySelection = $request->get('entity_selection', null);
+ if ($entitySelection === null || $entitySelection === '') {
+ return redirect($page->getUrl());
+ }
+
+ try {
+ $parent = $this->pageRepo->move($page, $entitySelection);
+ } catch (Exception $exception) {
+ if ($exception instanceof PermissionsException) {
+ $this->showPermissionError();
+ }
+
+ $this->showErrorNotification(trans('errors.selected_book_chapter_not_found'));
+ return redirect()->back();
+ }
+
+ $this->showSuccessNotification(trans('entities.pages_move_success', ['parentName' => $parent->name]));
+ return redirect($page->getUrl());
}
/**
- * Show a listing of recently created pages
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ * Show the view to copy a page.
+ * @throws NotFoundException
*/
- public function showRecentlyCreated()
+ public function showCopy(string $bookSlug, string $pageSlug)
{
- $pages = $this->pageRepo->getRecentlyCreatedPaginated(20);
- return view('pages/detailed-listing', [
- 'title' => 'Recently Created Pages',
- 'pages' => $pages
+ $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
+ $this->checkOwnablePermission('page-view', $page);
+ session()->flashInput(['name' => $page->name]);
+ return view('pages.copy', [
+ 'book' => $page->book,
+ 'page' => $page
]);
}
+
/**
- * Show a listing of recently created pages
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ * Create a copy of a page within the requested target destination.
+ * @throws NotFoundException
+ * @throws Throwable
*/
- public function showRecentlyUpdated()
+ public function copy(Request $request, string $bookSlug, string $pageSlug)
{
- $pages = $this->pageRepo->getRecentlyUpdatedPaginated(20);
- return view('pages/detailed-listing', [
- 'title' => 'Recently Updated Pages',
- 'pages' => $pages
- ]);
+ $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
+ $this->checkOwnablePermission('page-view', $page);
+
+ $entitySelection = $request->get('entity_selection', null) ?? null;
+ $newName = $request->get('name', null);
+
+ try {
+ $pageCopy = $this->pageRepo->copy($page, $entitySelection, $newName);
+ } catch (Exception $exception) {
+ if ($exception instanceof PermissionsException) {
+ $this->showPermissionError();
+ }
+
+ $this->showErrorNotification(trans('errors.selected_book_chapter_not_found'));
+ return redirect()->back();
+ }
+
+ $this->showSuccessNotification(trans('entities.pages_copy_success'));
+ return redirect($pageCopy->getUrl());
}
/**
- * Show the Restrictions view.
- * @param $bookSlug
- * @param $pageSlug
- * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
+ * Show the Permissions view.
+ * @throws NotFoundException
*/
- public function showRestrict($bookSlug, $pageSlug)
+ public function showPermissions(string $bookSlug, string $pageSlug)
{
- $book = $this->bookRepo->getBySlug($bookSlug);
- $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+ $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
$this->checkOwnablePermission('restrictions-manage', $page);
- $roles = $this->userRepo->getRestrictableRoles();
- return view('pages/restrictions', [
- 'page' => $page,
- 'roles' => $roles
+ return view('pages.permissions', [
+ 'page' => $page,
]);
}
/**
- * Set the restrictions for this page.
- * @param $bookSlug
- * @param $pageSlug
- * @param Request $request
- * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
+ * Set the permissions for this page.
+ * @throws NotFoundException
+ * @throws Throwable
*/
- public function restrict($bookSlug, $pageSlug, Request $request)
+ public function permissions(Request $request, PermissionsUpdater $permissionsUpdater, string $bookSlug, string $pageSlug)
{
- $book = $this->bookRepo->getBySlug($bookSlug);
- $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+ $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
$this->checkOwnablePermission('restrictions-manage', $page);
- $this->pageRepo->updateRestrictionsFromRequest($request, $page);
- session()->flash('success', 'Page Restrictions Updated');
+
+ $permissionsUpdater->updateFromPermissionsForm($page, $request);
+
+ $this->showSuccessNotification(trans('entities.pages_permissions_success'));
return redirect($page->getUrl());
}
-
}