diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php index 25a0503eb..e3079047c 100644 --- a/app/Http/Controllers/PageController.php +++ b/app/Http/Controllers/PageController.php @@ -454,6 +454,40 @@ class PageController extends Controller return redirect($page->getUrl()); } + + /** + * Deletes a revision using the id of the specified revision. + * @param string $bookSlug + * @param string $pageSlug + * @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-delete', $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 + $currentRevision = $page->getCurrentRevision(); + + // Check if its the latest revision, cannot delete latest revision. + 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]); + } + /** * Exports a page to a PDF. * https://github.com/barryvdh/laravel-dompdf diff --git a/app/Page.php b/app/Page.php index 9554504b3..5c03e7d66 100644 --- a/app/Page.php +++ b/app/Page.php @@ -112,4 +112,13 @@ class Page extends Entity $htmlQuery = $withContent ? 'html' : "'' as html"; return "'BookStack\\\\Page' as entity_type, id, id as entity_id, slug, name, {$this->textField} as text, {$htmlQuery}, book_id, priority, chapter_id, draft, created_by, updated_by, updated_at, created_at"; } + + /** + * Get the current revision for the page if existing + * @return \BookStack\PageRevision|null + */ + public function getCurrentRevision() + { + return $this->revisions()->first(); + } } 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/lang/de/entities.php b/resources/lang/de/entities.php index 96aaa9b0e..7c27be17b 100644 --- a/resources/lang/de/entities.php +++ b/resources/lang/de/entities.php @@ -256,4 +256,11 @@ return [ 'comment_updated_success' => 'Kommentar aktualisiert', 'comment_delete_confirm' => 'Möchten Sie diesen Kommentar wirklich löschen?', 'comment_in_reply_to' => 'Antwort auf :commentId', + + /** + * Revision + */ + 'revision_delete_confirm' => 'Sind Sie sicher, dass Sie diese Revision löschen wollen?', + 'revision_delete_success' => 'Revision gelöscht', + 'revision_cannot_delete_latest' => 'Die letzte Version kann nicht gelöscht werden.' ]; diff --git a/resources/lang/en/entities.php b/resources/lang/en/entities.php index 93025ffd4..c99887401 100644 --- a/resources/lang/en/entities.php +++ b/resources/lang/en/entities.php @@ -265,4 +265,11 @@ return [ 'comment_updated_success' => 'Comment updated', 'comment_delete_confirm' => 'Are you sure you want to delete this comment?', 'comment_in_reply_to' => 'In reply to :commentId', + + /** + * Revision + */ + 'revision_delete_confirm' => 'Are you sure you want to delete this revision?', + 'revision_delete_success' => 'Revision deleted', + 'revision_cannot_delete_latest' => 'Cannot delete the latest revision.' ]; \ No newline at end of file diff --git a/resources/lang/es/entities.php b/resources/lang/es/entities.php index 8c5c9f07f..a84d72fff 100644 --- a/resources/lang/es/entities.php +++ b/resources/lang/es/entities.php @@ -265,4 +265,11 @@ return [ 'comment_updated_success' => 'Comentario actualizado', 'comment_delete_confirm' => '¿Está seguro de que quiere borrar este comentario?', 'comment_in_reply_to' => 'En respuesta a :commentId', + + /** + * Revision + */ + 'revision_delete_confirm' => '¿Está seguro de que desea eliminar esta revisión?', + 'revision_delete_success' => 'Revisión eliminada', + 'revision_cannot_delete_latest' => 'No se puede eliminar la última revisión.' ]; diff --git a/resources/lang/es_AR/entities.php b/resources/lang/es_AR/entities.php index 371f1b7aa..91d156e53 100644 --- a/resources/lang/es_AR/entities.php +++ b/resources/lang/es_AR/entities.php @@ -265,4 +265,11 @@ return [ 'comment_updated_success' => 'Comentario actualizado', 'comment_delete_confirm' => '¿Está seguro que quiere borrar este comentario?', 'comment_in_reply_to' => 'En respuesta a :commentId', + + /** + * Revision + */ + 'revision_delete_confirm' => 'Are you sure you want to delete this revision?', + 'revision_delete_success' => 'Revisión eliminada', + 'revision_cannot_delete_latest' => 'No se puede eliminar la última revisión.' ]; diff --git a/resources/lang/fr/entities.php b/resources/lang/fr/entities.php index b20097775..deee70ee4 100644 --- a/resources/lang/fr/entities.php +++ b/resources/lang/fr/entities.php @@ -265,4 +265,11 @@ return [ 'comment_updated_success' => 'Commentaire mis à jour', 'comment_delete_confirm' => 'Etes-vous sûr de vouloir supprimer ce commentaire ?', 'comment_in_reply_to' => 'En réponse à :commentId', + + /** + * Revision + */ + 'revision_delete_confirm' => 'Êtes-vous sûr de vouloir supprimer cette révision?', + 'revision_delete_success' => 'Révision supprimée', + 'revision_cannot_delete_latest' => 'Impossible de supprimer la dernière révision.' ]; \ No newline at end of file diff --git a/resources/lang/it/entities.php b/resources/lang/it/entities.php index 1941ffb1e..ad1733b91 100755 --- a/resources/lang/it/entities.php +++ b/resources/lang/it/entities.php @@ -260,4 +260,11 @@ return [ 'comment_updated_success' => 'Commento aggiornato', 'comment_delete_confirm' => 'Sei sicuro di voler elminare questo commento?', 'comment_in_reply_to' => 'In risposta a :commentId', + + /** + * Revision + */ + 'revision_delete_confirm' => 'Sei sicuro di voler eliminare questa revisione?', + 'revision_delete_success' => 'Revisione cancellata', + 'revision_cannot_delete_latest' => 'Impossibile eliminare l\'ultima revisione.' ]; \ No newline at end of file diff --git a/resources/lang/ja/entities.php b/resources/lang/ja/entities.php index c08c4998b..f177154f4 100644 --- a/resources/lang/ja/entities.php +++ b/resources/lang/ja/entities.php @@ -257,4 +257,11 @@ return [ 'comment_updated_success' => 'コメントを更新しました', 'comment_delete_confirm' => '本当にこのコメントを削除しますか?', 'comment_in_reply_to' => ':commentIdへ返信', + + /** + * Revision + */ + 'revision_delete_confirm' => 'このリビジョンを削除しますか?', + 'revision_delete_success' => 'リビジョンを削除しました', + 'revision_cannot_delete_latest' => '最新のリビジョンを削除できません。' ]; diff --git a/resources/lang/nl/entities.php b/resources/lang/nl/entities.php index a807c84ce..29bb11a37 100644 --- a/resources/lang/nl/entities.php +++ b/resources/lang/nl/entities.php @@ -259,4 +259,11 @@ return [ 'comment_updated_success' => 'Reactie bijgewerkt', 'comment_delete_confirm' => 'Zeker reactie verwijderen?', 'comment_in_reply_to' => 'Antwoord op :commentId', + + /** + * Revision + */ + 'revision_delete_confirm' => 'Weet u zeker dat u deze revisie wilt verwijderen?', + 'revision_delete_success' => 'Revisie verwijderd', + 'revision_cannot_delete_latest' => 'Kan de laatste revisie niet verwijderen.' ]; diff --git a/resources/lang/pl/entities.php b/resources/lang/pl/entities.php index 0407b1396..8b53591f6 100644 --- a/resources/lang/pl/entities.php +++ b/resources/lang/pl/entities.php @@ -257,4 +257,11 @@ return [ 'comment_updated_success' => 'Komentarz zaktualizowany', 'comment_delete_confirm' => 'Czy na pewno chcesz usunąc ten komentarz?', 'comment_in_reply_to' => 'W odpowiedzi na :commentId', + + /** + * Revision + */ + 'revision_delete_confirm' => 'Czy na pewno chcesz usunąć tę wersję?', + 'revision_delete_success' => 'Usunięto wersję', + 'revision_cannot_delete_latest' => 'Nie można usunąć najnowszej wersji.' ]; \ No newline at end of file diff --git a/resources/lang/pt_BR/entities.php b/resources/lang/pt_BR/entities.php index 4dbf9c935..d93b9dff9 100644 --- a/resources/lang/pt_BR/entities.php +++ b/resources/lang/pt_BR/entities.php @@ -258,4 +258,11 @@ return [ 'comment_updated_success' => 'Comentário editado', 'comment_delete_confirm' => 'Você tem certeza de que quer deletar este comentário?', 'comment_in_reply_to' => 'Em resposta à :commentId', + + /** + * Revision + */ + 'revision_delete_confirm' => 'Tem certeza de que deseja excluir esta revisão?', + 'revision_delete_success' => 'Revisão excluída', + 'revision_cannot_delete_latest' => 'Não é possível excluir a revisão mais recente.' ]; \ No newline at end of file diff --git a/resources/lang/ru/entities.php b/resources/lang/ru/entities.php index a0322d622..9c3517beb 100644 --- a/resources/lang/ru/entities.php +++ b/resources/lang/ru/entities.php @@ -258,4 +258,11 @@ return [ 'comment_updated_success' => 'Комментарий обновлён', 'comment_delete_confirm' => 'Вы уверенны, что хотите удалить этот комментарий?', 'comment_in_reply_to' => 'В ответ на :commentId', + + /** + * Revision + */ + 'revision_delete_confirm' => 'Вы действительно хотите удалить эту ревизию?', + 'revision_delete_success' => 'Редактирование удалено', + 'revision_cannot_delete_latest' => 'Не удается удалить последнюю версию.' ]; \ No newline at end of file diff --git a/resources/lang/sk/entities.php b/resources/lang/sk/entities.php index 8f9a57d1f..7fbbaf2e2 100644 --- a/resources/lang/sk/entities.php +++ b/resources/lang/sk/entities.php @@ -232,4 +232,11 @@ return [ 'comments' => 'Komentáre', 'comment_placeholder' => 'Tu zadajte svoje pripomienky', 'comment_save' => 'Uložiť komentár', + + /** + * Revision + */ + 'revision_delete_confirm' => 'Naozaj chcete túto revíziu odstrániť?', + 'revision_delete_success' => 'Revízia bola vymazaná', + 'revision_cannot_delete_latest' => 'Nie je možné vymazať poslednú revíziu.' ]; diff --git a/resources/lang/sv/entities.php b/resources/lang/sv/entities.php index 3a2d1a2c6..8c09bd377 100644 --- a/resources/lang/sv/entities.php +++ b/resources/lang/sv/entities.php @@ -265,4 +265,11 @@ return [ 'comment_updated_success' => 'Kommentaren har uppdaterats', 'comment_delete_confirm' => 'Är du säker på att du vill ta bort den här kommentaren?', 'comment_in_reply_to' => 'Som svar på :commentId', + + /** + * Revision + */ + 'revision_delete_confirm' => 'Är du säker på att du vill radera den här versionen?', + 'revision_delete_success' => 'Revisionen raderad', + 'revision_cannot_delete_latest' => 'Det går inte att ta bort den senaste versionen.' ]; \ No newline at end of file diff --git a/resources/lang/zh_CN/entities.php b/resources/lang/zh_CN/entities.php index eed6b9532..734a47a5a 100644 --- a/resources/lang/zh_CN/entities.php +++ b/resources/lang/zh_CN/entities.php @@ -258,4 +258,11 @@ return [ 'comment_updated_success' => '评论已更新', 'comment_delete_confirm' => '你确定要删除这条评论?', 'comment_in_reply_to' => '回复 :commentId', + + /** + * Revision + */ + 'revision_delete_confirm' => '您确定要删除此修订版吗?', + 'revision_delete_success' => '修订删除', + 'revision_cannot_delete_latest' => '无法删除最新版本。' ]; diff --git a/resources/lang/zh_TW/entities.php b/resources/lang/zh_TW/entities.php index 664917eaa..1c4d526fd 100644 --- a/resources/lang/zh_TW/entities.php +++ b/resources/lang/zh_TW/entities.php @@ -259,4 +259,11 @@ return [ 'comment_updated_success' => '評論已更新', 'comment_delete_confirm' => '你確定要刪除這條評論?', 'comment_in_reply_to' => '回覆 :commentId', + + /** + * Revision + */ + 'revision_delete_confirm' => '您確定要刪除此修訂版嗎?', + 'revision_delete_success' => '修訂刪除', + 'revision_cannot_delete_latest' => '無法刪除最新版本。' ]; diff --git a/resources/views/pages/revisions.blade.php b/resources/views/pages/revisions.blade.php index d07dc6fcc..72017467e 100644 --- a/resources/views/pages/revisions.blade.php +++ b/resources/views/pages/revisions.blade.php @@ -36,16 +36,31 @@