diff --git a/app/Exceptions/BadRequestException.php b/app/Exceptions/BadRequestException.php new file mode 100644 index 000000000..b0353bad4 --- /dev/null +++ b/app/Exceptions/BadRequestException.php @@ -0,0 +1,14 @@ +getUrl()); } + + /** + * Deletes a revision using the id of the specified revision. + * @param string $bookSlug + * @param string $pageSlug + * @param int $revisionId + * @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); + + $revision = $page->revisions()->where('id', '=', $revId)->first(); + if ($revision === null) { + throw new NotFoundException("Revision #{$revId} not found"); + } + + // Get the current revision for the page + $current = $revision->getCurrent(); + + // 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}"); + } + + $revision->delete(); + return view('pages/revisions', ['page' => $page, 'book' => $page->book, 'current' => $page]); + } + /** * Exports a page to a PDF. * https://github.com/barryvdh/laravel-dompdf diff --git a/app/PageRevision.php b/app/PageRevision.php index ffcc4f9d2..8e5c16bc9 100644 --- a/app/PageRevision.php +++ b/app/PageRevision.php @@ -48,6 +48,18 @@ class PageRevision extends Model return null; } + /** + * Get the current revision for the same page if existing + * @return \BookStack\PageRevision|null + */ + public function getCurrent() + { + if ($id = static::where('page_id', '=', $this->page_id)->max('id')) { + return static::find($id); + } + return null; + } + /** * Allows checking of the exact class, Used to check entity type. * Included here to align with entities in similar use cases. diff --git a/resources/assets/sass/_buttons.scss b/resources/assets/sass/_buttons.scss index 2c20c3f41..7738eb4ba 100644 --- a/resources/assets/sass/_buttons.scss +++ b/resources/assets/sass/_buttons.scss @@ -119,6 +119,11 @@ $button-border-radius: 2px; &.neg { color: $negative; } + &.link { + &:hover { + text-decoration: underline; + } + } } .button-group { diff --git a/resources/assets/sass/_lists.scss b/resources/assets/sass/_lists.scss index 3338b3938..e8d131b52 100644 --- a/resources/assets/sass/_lists.scss +++ b/resources/assets/sass/_lists.scss @@ -367,7 +367,7 @@ ul.pagination { padding: $-xs $-m; line-height: 1.2; } - a { + a, button { display: block; padding: $-xs $-m; color: #555; @@ -382,6 +382,10 @@ ul.pagination { width: 16px; } } + button { + width: 100%; + text-align: left; + } li.border-bottom { border-bottom: 1px solid #DDD; } diff --git a/resources/assets/sass/_tables.scss b/resources/assets/sass/_tables.scss index 38b044268..ec24e2fa6 100644 --- a/resources/assets/sass/_tables.scss +++ b/resources/assets/sass/_tables.scss @@ -41,6 +41,9 @@ table.table { .text-center { text-align: center; } + td.actions { + overflow: visible; + } } table.no-style { diff --git a/resources/views/pages/revisions.blade.php b/resources/views/pages/revisions.blade.php index d07dc6fcc..99be26153 100644 --- a/resources/views/pages/revisions.blade.php +++ b/resources/views/pages/revisions.blade.php @@ -36,16 +36,31 @@