use BookStack\Exceptions\NotFoundException;
use BookStack\Repos\UserRepo;
use BookStack\Services\ExportService;
+use Carbon\Carbon;
use Illuminate\Http\Request;
use BookStack\Http\Requests;
use BookStack\Repos\BookRepo;
{
$book = $this->bookRepo->getBySlug($bookSlug);
$draft = $this->pageRepo->getById($pageId, true);
- $this->checkOwnablePermission('page-create', $draft);
+ $this->checkOwnablePermission('page-create', $book);
$this->setPageTitle('Edit Page Draft');
- return view('pages/create', ['draft' => $draft, 'book' => $book]);
+ return view('pages/edit', ['page' => $draft, 'book' => $book, 'isDraft' => true]);
}
/**
$draftPage = $this->pageRepo->getById($pageId, true);
- $chapterId = $draftPage->chapter_id;
+ $chapterId = intval($draftPage->chapter_id);
$parent = $chapterId !== 0 ? $this->chapterRepo->getById($chapterId) : $book;
$this->checkOwnablePermission('page-create', $parent);
return redirect($page->getUrl());
}
+ $this->checkOwnablePermission('page-view', $page);
+
$sidebarTree = $this->bookRepo->getChildren($book);
Views::add($page);
$this->setPageTitle($page->getShortName());
} else {
$draft = $this->pageRepo->saveUpdateDraft($page, $request->only(['name', 'html', 'markdown']));
}
- $updateTime = $draft->updated_at->format('H:i');
- return response()->json(['status' => 'success', 'message' => 'Draft saved at ' . $updateTime]);
+
+ $updateTime = $draft->updated_at->timestamp;
+ $utcUpdateTimestamp = $updateTime + Carbon::createFromTimestamp(0)->offset;
+ return response()->json([
+ 'status' => 'success',
+ 'message' => 'Draft saved at ',
+ 'timestamp' => $utcUpdateTimestamp
+ ]);
}
/**
*/
public function showRecentlyCreated()
{
- $pages = $this->pageRepo->getRecentlyCreatedPaginated(20);
+ $pages = $this->pageRepo->getRecentlyCreatedPaginated(20)->setPath(baseUrl('/pages/recently-created'));
return view('pages/detailed-listing', [
'title' => 'Recently Created Pages',
'pages' => $pages
*/
public function showRecentlyUpdated()
{
- $pages = $this->pageRepo->getRecentlyUpdatedPaginated(20);
+ $pages = $this->pageRepo->getRecentlyUpdatedPaginated(20)->setPath(baseUrl('/pages/recently-updated'));
return view('pages/detailed-listing', [
'title' => 'Recently Updated Pages',
'pages' => $pages
}
/**
- * Set the restrictions for this page.
+ * Show the view to choose a new parent to move a page into.
+ * @param $bookSlug
+ * @param $pageSlug
+ * @return mixed
+ * @throws NotFoundException
+ */
+ public function showMove($bookSlug, $pageSlug)
+ {
+ $book = $this->bookRepo->getBySlug($bookSlug);
+ $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+ $this->checkOwnablePermission('page-update', $page);
+ return view('pages/move', [
+ 'book' => $book,
+ 'page' => $page
+ ]);
+ }
+
+ /**
+ * Does the action of moving the location of a page
+ * @param $bookSlug
+ * @param $pageSlug
+ * @param Request $request
+ * @return mixed
+ * @throws NotFoundException
+ */
+ public function move($bookSlug, $pageSlug, Request $request)
+ {
+ $book = $this->bookRepo->getBySlug($bookSlug);
+ $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+ $this->checkOwnablePermission('page-update', $page);
+
+ $entitySelection = $request->get('entity_selection', null);
+ if ($entitySelection === null || $entitySelection === '') {
+ return redirect($page->getUrl());
+ }
+
+ $stringExploded = explode(':', $entitySelection);
+ $entityType = $stringExploded[0];
+ $entityId = intval($stringExploded[1]);
+
+ $parent = false;
+
+ if ($entityType == 'chapter') {
+ $parent = $this->chapterRepo->getById($entityId);
+ } else if ($entityType == 'book') {
+ $parent = $this->bookRepo->getById($entityId);
+ }
+
+ if ($parent === false || $parent === null) {
+ session()->flash('The selected Book or Chapter was not found');
+ return redirect()->back();
+ }
+
+ $this->pageRepo->changePageParent($page, $parent);
+ Activity::add($page, 'page_move', $page->book->id);
+ session()->flash('success', sprintf('Page moved to "%s"', $parent->name));
+
+ return redirect($page->getUrl());
+ }
+
+ /**
+ * Set the permissions for this page.
* @param $bookSlug
* @param $pageSlug
* @param Request $request
$book = $this->bookRepo->getBySlug($bookSlug);
$page = $this->pageRepo->getBySlug($pageSlug, $book->id);
$this->checkOwnablePermission('restrictions-manage', $page);
- $this->pageRepo->updateRestrictionsFromRequest($request, $page);
- session()->flash('success', 'Page Restrictions Updated');
+ $this->pageRepo->updateEntityPermissionsFromRequest($request, $page);
+ session()->flash('success', 'Page Permissions Updated');
return redirect($page->getUrl());
}