use Activity;
use BookStack\Exceptions\NotFoundException;
-use BookStack\Exceptions\BadRequestException;
use BookStack\Repos\EntityRepo;
use BookStack\Repos\UserRepo;
use BookStack\Services\ExportService;
* Deletes a revision using the id of the specified revision.
* @param string $bookSlug
* @param string $pageSlug
- * @param int $revisionId
+ * @param int $revId
* @throws NotFoundException
* @throws BadRequestException
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
public function destroyRevision($bookSlug, $pageSlug, $revId)
{
$page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
- $this->checkOwnablePermission('page-update', $page);
+ $this->checkOwnablePermission('page-delete', $page);
$revision = $page->revisions()->where('id', '=', $revId)->first();
if ($revision === null) {
}
// Get the current revision for the page
- $current = $revision->getCurrent();
+ $currentRevision = $page->getCurrentRevision();
// Check if its the latest revision, cannot delete latest revision.
- if (intval($current->id) === intval($revId)) {
- throw new BadRequestException("Cannot delete the current revision #{$revId}");
+ if (intval($currentRevision->id) === intval($revId)) {
+ session()->flash('error', trans('entities.revision_cannot_delete_latest'));
+ return response()->view('pages/revisions', ['page' => $page, 'book' => $page->book, 'current' => $page], 400);
}
$revision->delete();
+ session()->flash('success', trans('entities.revision_delete_success'));
return view('pages/revisions', ['page' => $page, 'book' => $page->book, 'current' => $page]);
}