From 714c7bbd3a16ab905ac41f7a20831d701532641f Mon Sep 17 00:00:00 2001 From: Abijeet Date: Sat, 15 Sep 2018 15:15:42 +0530 Subject: [PATCH 1/7] Adds code to delete the revision. Signed-off-by: Abijeet --- app/Exceptions/BadRequestException.php | 14 ++++++++ app/Http/Controllers/PageController.php | 33 +++++++++++++++++++ app/PageRevision.php | 12 +++++++ resources/assets/sass/_buttons.scss | 5 +++ resources/assets/sass/_lists.scss | 6 +++- resources/assets/sass/_tables.scss | 3 ++ resources/views/pages/revisions.blade.php | 17 +++++++++- .../views/partials/custom-styles.blade.php | 2 +- routes/web.php | 2 +- 9 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 app/Exceptions/BadRequestException.php 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 @@ @if($revision->createdBy) {{ $revision->createdBy->name }} @else {{ trans('common.deleted_user') }} @endif {{ $revision->created_at->format('jS F, Y H:i:s') }}
({{ $revision->created_at->diffForHumans() }})
{{ $revision->summary }} - + {{ trans('entities.pages_revisions_changes') }}  |  + @if ($index === 0) {{ trans('entities.pages_revisions_current') }} @else {{ trans('entities.pages_revisions_preview') }}  |  {{ trans('entities.pages_revisions_restore') }} +  |  + @endif diff --git a/resources/views/partials/custom-styles.blade.php b/resources/views/partials/custom-styles.blade.php index 272aa3dc1..0b9382f59 100644 --- a/resources/views/partials/custom-styles.blade.php +++ b/resources/views/partials/custom-styles.blade.php @@ -19,4 +19,4 @@ color: {{ setting('app-color') }}; fill: {{ setting('app-color') }}; } - \ No newline at end of file + diff --git a/routes/web.php b/routes/web.php index c4e7469fe..70cb3c130 100644 --- a/routes/web.php +++ b/routes/web.php @@ -61,6 +61,7 @@ Route::group(['middleware' => 'auth'], function () { Route::get('/{bookSlug}/page/{pageSlug}/revisions/{revId}', 'PageController@showRevision'); Route::get('/{bookSlug}/page/{pageSlug}/revisions/{revId}/changes', 'PageController@showRevisionChanges'); Route::get('/{bookSlug}/page/{pageSlug}/revisions/{revId}/restore', 'PageController@restoreRevision'); + Route::delete('/{bookSlug}/page/{pageSlug}/revisions/{revId}/delete', 'PageController@destroyRevision'); // Chapters Route::get('/{bookSlug}/chapter/{chapterSlug}/create-page', 'PageController@create'); @@ -79,7 +80,6 @@ Route::group(['middleware' => 'auth'], function () { Route::put('/{bookSlug}/chapter/{chapterSlug}/permissions', 'ChapterController@restrict'); Route::get('/{bookSlug}/chapter/{chapterSlug}/delete', 'ChapterController@showDelete'); Route::delete('/{bookSlug}/chapter/{chapterSlug}', 'ChapterController@destroy'); - }); // User Profile routes From f0add69b61ca1aef31e028ce63898c02e825e9d7 Mon Sep 17 00:00:00 2001 From: Abijeet Date: Sat, 15 Sep 2018 15:16:04 +0530 Subject: [PATCH 2/7] Adding languages for the revision deletion. --- resources/lang/de/entities.php | 5 +++++ resources/lang/en/entities.php | 6 ++++++ resources/lang/es/entities.php | 5 +++++ resources/lang/es_AR/entities.php | 5 +++++ resources/lang/fr/entities.php | 5 +++++ resources/lang/it/entities.php | 5 +++++ resources/lang/ja/entities.php | 5 +++++ resources/lang/nl/entities.php | 5 +++++ resources/lang/pl/entities.php | 5 +++++ resources/lang/pt_BR/entities.php | 5 +++++ resources/lang/ru/entities.php | 5 +++++ resources/lang/sk/entities.php | 5 +++++ resources/lang/sv/entities.php | 5 +++++ resources/lang/zh_CN/entities.php | 5 +++++ resources/lang/zh_TW/entities.php | 5 +++++ 15 files changed, 76 insertions(+) diff --git a/resources/lang/de/entities.php b/resources/lang/de/entities.php index 96aaa9b0e..304e250b3 100644 --- a/resources/lang/de/entities.php +++ b/resources/lang/de/entities.php @@ -256,4 +256,9 @@ 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?', ]; diff --git a/resources/lang/en/entities.php b/resources/lang/en/entities.php index 93025ffd4..d2d13a007 100644 --- a/resources/lang/en/entities.php +++ b/resources/lang/en/entities.php @@ -183,6 +183,7 @@ return [ 'pages_revisions_current' => 'Current Version', 'pages_revisions_preview' => 'Preview', 'pages_revisions_restore' => 'Restore', + 'pages_revisions_delete' => 'Delete', 'pages_revisions_none' => 'This page has no revisions', 'pages_copy_link' => 'Copy Link', 'pages_edit_content_link' => 'Edit Content', @@ -265,4 +266,9 @@ 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?', ]; \ No newline at end of file diff --git a/resources/lang/es/entities.php b/resources/lang/es/entities.php index 8c5c9f07f..6483ebcd5 100644 --- a/resources/lang/es/entities.php +++ b/resources/lang/es/entities.php @@ -265,4 +265,9 @@ 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?', ]; diff --git a/resources/lang/es_AR/entities.php b/resources/lang/es_AR/entities.php index 371f1b7aa..b401928ce 100644 --- a/resources/lang/es_AR/entities.php +++ b/resources/lang/es_AR/entities.php @@ -265,4 +265,9 @@ 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?', ]; diff --git a/resources/lang/fr/entities.php b/resources/lang/fr/entities.php index b20097775..ceeb3739c 100644 --- a/resources/lang/fr/entities.php +++ b/resources/lang/fr/entities.php @@ -265,4 +265,9 @@ 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?', ]; \ No newline at end of file diff --git a/resources/lang/it/entities.php b/resources/lang/it/entities.php index 1941ffb1e..5858bbca3 100755 --- a/resources/lang/it/entities.php +++ b/resources/lang/it/entities.php @@ -260,4 +260,9 @@ 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?', ]; \ No newline at end of file diff --git a/resources/lang/ja/entities.php b/resources/lang/ja/entities.php index c08c4998b..06ad451ea 100644 --- a/resources/lang/ja/entities.php +++ b/resources/lang/ja/entities.php @@ -257,4 +257,9 @@ return [ 'comment_updated_success' => 'コメントを更新しました', 'comment_delete_confirm' => '本当にこのコメントを削除しますか?', 'comment_in_reply_to' => ':commentIdへ返信', + + /** + * Revision + */ + 'revision_delete_confirm' => 'このリビジョンを削除しますか?', ]; diff --git a/resources/lang/nl/entities.php b/resources/lang/nl/entities.php index a807c84ce..2b8b7002e 100644 --- a/resources/lang/nl/entities.php +++ b/resources/lang/nl/entities.php @@ -259,4 +259,9 @@ 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?', ]; diff --git a/resources/lang/pl/entities.php b/resources/lang/pl/entities.php index 0407b1396..c602146a5 100644 --- a/resources/lang/pl/entities.php +++ b/resources/lang/pl/entities.php @@ -257,4 +257,9 @@ 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ę?', ]; \ No newline at end of file diff --git a/resources/lang/pt_BR/entities.php b/resources/lang/pt_BR/entities.php index 4dbf9c935..a01e24df4 100644 --- a/resources/lang/pt_BR/entities.php +++ b/resources/lang/pt_BR/entities.php @@ -258,4 +258,9 @@ 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?', ]; \ No newline at end of file diff --git a/resources/lang/ru/entities.php b/resources/lang/ru/entities.php index a0322d622..4a245698b 100644 --- a/resources/lang/ru/entities.php +++ b/resources/lang/ru/entities.php @@ -258,4 +258,9 @@ return [ 'comment_updated_success' => 'Комментарий обновлён', 'comment_delete_confirm' => 'Вы уверенны, что хотите удалить этот комментарий?', 'comment_in_reply_to' => 'В ответ на :commentId', + + /** + * Revision + */ + 'revision_delete_confirm' => 'Вы действительно хотите удалить эту ревизию?', ]; \ No newline at end of file diff --git a/resources/lang/sk/entities.php b/resources/lang/sk/entities.php index 8f9a57d1f..979921258 100644 --- a/resources/lang/sk/entities.php +++ b/resources/lang/sk/entities.php @@ -232,4 +232,9 @@ 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ť?', ]; diff --git a/resources/lang/sv/entities.php b/resources/lang/sv/entities.php index 3a2d1a2c6..c675899f7 100644 --- a/resources/lang/sv/entities.php +++ b/resources/lang/sv/entities.php @@ -265,4 +265,9 @@ 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?' ]; \ No newline at end of file diff --git a/resources/lang/zh_CN/entities.php b/resources/lang/zh_CN/entities.php index eed6b9532..5e3b360a6 100644 --- a/resources/lang/zh_CN/entities.php +++ b/resources/lang/zh_CN/entities.php @@ -258,4 +258,9 @@ return [ 'comment_updated_success' => '评论已更新', 'comment_delete_confirm' => '你确定要删除这条评论?', 'comment_in_reply_to' => '回复 :commentId', + + /** + * Revision + */ + 'revision_delete_confirm' => '您确定要删除此修订版吗?' ]; diff --git a/resources/lang/zh_TW/entities.php b/resources/lang/zh_TW/entities.php index 664917eaa..3883dc613 100644 --- a/resources/lang/zh_TW/entities.php +++ b/resources/lang/zh_TW/entities.php @@ -259,4 +259,9 @@ return [ 'comment_updated_success' => '評論已更新', 'comment_delete_confirm' => '你確定要刪除這條評論?', 'comment_in_reply_to' => '回覆 :commentId', + + /** + * Revision + */ + 'revision_delete_confirm' => '您確定要刪除此修訂版嗎?', ]; From 25da4d9a8bb113b1f28fa54d9b8ea5e7eede1681 Mon Sep 17 00:00:00 2001 From: Abijeet Date: Sat, 15 Sep 2018 16:08:20 +0530 Subject: [PATCH 3/7] Added a success message on deletion of revision. Signed-off-by: Abijeet --- app/Http/Controllers/PageController.php | 1 + resources/lang/de/entities.php | 1 + resources/lang/en/entities.php | 1 + resources/lang/es/entities.php | 1 + resources/lang/es_AR/entities.php | 1 + resources/lang/fr/entities.php | 1 + resources/lang/it/entities.php | 1 + resources/lang/ja/entities.php | 1 + resources/lang/nl/entities.php | 1 + resources/lang/pl/entities.php | 1 + resources/lang/pt_BR/entities.php | 1 + resources/lang/ru/entities.php | 1 + resources/lang/sk/entities.php | 1 + resources/lang/sv/entities.php | 3 ++- resources/lang/zh_TW/entities.php | 1 + 15 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php index 5979ceca8..2ca991620 100644 --- a/app/Http/Controllers/PageController.php +++ b/app/Http/Controllers/PageController.php @@ -484,6 +484,7 @@ class PageController extends Controller } $revision->delete(); + session()->flash('success', trans('entities.revision_delete_success')); return view('pages/revisions', ['page' => $page, 'book' => $page->book, 'current' => $page]); } diff --git a/resources/lang/de/entities.php b/resources/lang/de/entities.php index 304e250b3..22b824c51 100644 --- a/resources/lang/de/entities.php +++ b/resources/lang/de/entities.php @@ -261,4 +261,5 @@ return [ * Revision */ 'revision_delete_confirm' => 'Sind Sie sicher, dass Sie diese Revision löschen wollen?', + 'revision_delete_success' => 'Revision gelöscht' ]; diff --git a/resources/lang/en/entities.php b/resources/lang/en/entities.php index d2d13a007..d730740ea 100644 --- a/resources/lang/en/entities.php +++ b/resources/lang/en/entities.php @@ -271,4 +271,5 @@ return [ * Revision */ 'revision_delete_confirm' => 'Are you sure you want to delete this revision?', + 'revision_delete_success' => 'Revision deleted' ]; \ No newline at end of file diff --git a/resources/lang/es/entities.php b/resources/lang/es/entities.php index 6483ebcd5..1c8039272 100644 --- a/resources/lang/es/entities.php +++ b/resources/lang/es/entities.php @@ -270,4 +270,5 @@ return [ * Revision */ 'revision_delete_confirm' => '¿Está seguro de que desea eliminar esta revisión?', + 'revision_delete_success' => 'Revisión eliminada' ]; diff --git a/resources/lang/es_AR/entities.php b/resources/lang/es_AR/entities.php index b401928ce..a7f79dfe6 100644 --- a/resources/lang/es_AR/entities.php +++ b/resources/lang/es_AR/entities.php @@ -270,4 +270,5 @@ return [ * Revision */ 'revision_delete_confirm' => 'Are you sure you want to delete this revision?', + 'revision_delete_success' => 'Revisión eliminada' ]; diff --git a/resources/lang/fr/entities.php b/resources/lang/fr/entities.php index ceeb3739c..9ca181b03 100644 --- a/resources/lang/fr/entities.php +++ b/resources/lang/fr/entities.php @@ -270,4 +270,5 @@ return [ * Revision */ 'revision_delete_confirm' => 'Êtes-vous sûr de vouloir supprimer cette révision?', + 'revision_delete_success' => 'Révision supprimée' ]; \ No newline at end of file diff --git a/resources/lang/it/entities.php b/resources/lang/it/entities.php index 5858bbca3..4a28972e6 100755 --- a/resources/lang/it/entities.php +++ b/resources/lang/it/entities.php @@ -265,4 +265,5 @@ return [ * Revision */ 'revision_delete_confirm' => 'Sei sicuro di voler eliminare questa revisione?', + 'revision_delete_success' => 'Revisione cancellata' ]; \ No newline at end of file diff --git a/resources/lang/ja/entities.php b/resources/lang/ja/entities.php index 06ad451ea..c7df3201e 100644 --- a/resources/lang/ja/entities.php +++ b/resources/lang/ja/entities.php @@ -262,4 +262,5 @@ return [ * Revision */ 'revision_delete_confirm' => 'このリビジョンを削除しますか?', + 'revision_delete_success' => 'リビジョンを削除しました' ]; diff --git a/resources/lang/nl/entities.php b/resources/lang/nl/entities.php index 2b8b7002e..043dfe321 100644 --- a/resources/lang/nl/entities.php +++ b/resources/lang/nl/entities.php @@ -264,4 +264,5 @@ return [ * Revision */ 'revision_delete_confirm' => 'Weet u zeker dat u deze revisie wilt verwijderen?', + 'revision_delete_success' => 'Revisie verwijderd' ]; diff --git a/resources/lang/pl/entities.php b/resources/lang/pl/entities.php index c602146a5..e84054181 100644 --- a/resources/lang/pl/entities.php +++ b/resources/lang/pl/entities.php @@ -262,4 +262,5 @@ return [ * Revision */ 'revision_delete_confirm' => 'Czy na pewno chcesz usunąć tę wersję?', + 'revision_delete_success' => 'Usunięto wersję' ]; \ No newline at end of file diff --git a/resources/lang/pt_BR/entities.php b/resources/lang/pt_BR/entities.php index a01e24df4..9eeb8201d 100644 --- a/resources/lang/pt_BR/entities.php +++ b/resources/lang/pt_BR/entities.php @@ -263,4 +263,5 @@ return [ * Revision */ 'revision_delete_confirm' => 'Tem certeza de que deseja excluir esta revisão?', + 'revision_delete_success' => 'Revisão excluída' ]; \ No newline at end of file diff --git a/resources/lang/ru/entities.php b/resources/lang/ru/entities.php index 4a245698b..ef2caad40 100644 --- a/resources/lang/ru/entities.php +++ b/resources/lang/ru/entities.php @@ -263,4 +263,5 @@ return [ * Revision */ 'revision_delete_confirm' => 'Вы действительно хотите удалить эту ревизию?', + 'revision_delete_success' => 'Редактирование удалено' ]; \ No newline at end of file diff --git a/resources/lang/sk/entities.php b/resources/lang/sk/entities.php index 979921258..4f0744012 100644 --- a/resources/lang/sk/entities.php +++ b/resources/lang/sk/entities.php @@ -237,4 +237,5 @@ return [ * Revision */ 'revision_delete_confirm' => 'Naozaj chcete túto revíziu odstrániť?', + 'revision_delete_success' => 'Revízia bola vymazaná' ]; diff --git a/resources/lang/sv/entities.php b/resources/lang/sv/entities.php index c675899f7..0f515fc50 100644 --- a/resources/lang/sv/entities.php +++ b/resources/lang/sv/entities.php @@ -269,5 +269,6 @@ return [ /** * Revision */ - 'revision_delete_confirm' => 'Är du säker på att du vill radera den här versionen?' + 'revision_delete_confirm' => 'Är du säker på att du vill radera den här versionen?', + 'revision_delete_success' => 'Revisionen raderad' ]; \ No newline at end of file diff --git a/resources/lang/zh_TW/entities.php b/resources/lang/zh_TW/entities.php index 3883dc613..f37d786b6 100644 --- a/resources/lang/zh_TW/entities.php +++ b/resources/lang/zh_TW/entities.php @@ -264,4 +264,5 @@ return [ * Revision */ 'revision_delete_confirm' => '您確定要刪除此修訂版嗎?', + 'revision_delete_success' => '修訂刪除' ]; From 54ca4487faf46b52fe5f0457cd194c0492ce3e47 Mon Sep 17 00:00:00 2001 From: Abijeet Date: Sat, 15 Sep 2018 21:05:51 +0530 Subject: [PATCH 4/7] Adds tests and few fixes. Signed-off-by: Abijeet --- app/Http/Controllers/PageController.php | 4 ++-- resources/lang/de/entities.php | 3 ++- resources/lang/en/entities.php | 3 ++- resources/lang/es/entities.php | 3 ++- resources/lang/es_AR/entities.php | 3 ++- resources/lang/fr/entities.php | 3 ++- resources/lang/it/entities.php | 3 ++- resources/lang/ja/entities.php | 3 ++- resources/lang/nl/entities.php | 3 ++- resources/lang/pl/entities.php | 3 ++- resources/lang/pt_BR/entities.php | 3 ++- resources/lang/ru/entities.php | 3 ++- resources/lang/sk/entities.php | 3 ++- resources/lang/sv/entities.php | 3 ++- resources/lang/zh_CN/entities.php | 4 +++- resources/lang/zh_TW/entities.php | 3 ++- tests/Entity/PageRevisionTest.php | 23 ++++++++++++++++++++++- 17 files changed, 55 insertions(+), 18 deletions(-) diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php index 2ca991620..4cfd4c832 100644 --- a/app/Http/Controllers/PageController.php +++ b/app/Http/Controllers/PageController.php @@ -2,7 +2,6 @@ use Activity; use BookStack\Exceptions\NotFoundException; -use BookStack\Exceptions\BadRequestException; use BookStack\Repos\EntityRepo; use BookStack\Repos\UserRepo; use BookStack\Services\ExportService; @@ -480,7 +479,8 @@ class PageController extends Controller // 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}"); + session()->flash('error', trans('entities.revision_cannot_delete_latest')); + return view('pages/revisions', ['page' => $page, 'book' => $page->book, 'current' => $page]); } $revision->delete(); diff --git a/resources/lang/de/entities.php b/resources/lang/de/entities.php index 22b824c51..7c27be17b 100644 --- a/resources/lang/de/entities.php +++ b/resources/lang/de/entities.php @@ -261,5 +261,6 @@ return [ * Revision */ 'revision_delete_confirm' => 'Sind Sie sicher, dass Sie diese Revision löschen wollen?', - 'revision_delete_success' => 'Revision gelöscht' + '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 d730740ea..72d47bc01 100644 --- a/resources/lang/en/entities.php +++ b/resources/lang/en/entities.php @@ -271,5 +271,6 @@ return [ * Revision */ 'revision_delete_confirm' => 'Are you sure you want to delete this revision?', - 'revision_delete_success' => 'Revision deleted' + '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 1c8039272..a84d72fff 100644 --- a/resources/lang/es/entities.php +++ b/resources/lang/es/entities.php @@ -270,5 +270,6 @@ return [ * Revision */ 'revision_delete_confirm' => '¿Está seguro de que desea eliminar esta revisión?', - 'revision_delete_success' => 'Revisión eliminada' + '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 a7f79dfe6..91d156e53 100644 --- a/resources/lang/es_AR/entities.php +++ b/resources/lang/es_AR/entities.php @@ -270,5 +270,6 @@ return [ * Revision */ 'revision_delete_confirm' => 'Are you sure you want to delete this revision?', - 'revision_delete_success' => 'Revisión eliminada' + '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 9ca181b03..deee70ee4 100644 --- a/resources/lang/fr/entities.php +++ b/resources/lang/fr/entities.php @@ -270,5 +270,6 @@ return [ * Revision */ 'revision_delete_confirm' => 'Êtes-vous sûr de vouloir supprimer cette révision?', - 'revision_delete_success' => 'Révision supprimée' + '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 4a28972e6..ad1733b91 100755 --- a/resources/lang/it/entities.php +++ b/resources/lang/it/entities.php @@ -265,5 +265,6 @@ return [ * Revision */ 'revision_delete_confirm' => 'Sei sicuro di voler eliminare questa revisione?', - 'revision_delete_success' => 'Revisione cancellata' + '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 c7df3201e..f177154f4 100644 --- a/resources/lang/ja/entities.php +++ b/resources/lang/ja/entities.php @@ -262,5 +262,6 @@ return [ * Revision */ 'revision_delete_confirm' => 'このリビジョンを削除しますか?', - 'revision_delete_success' => 'リビジョンを削除しました' + 'revision_delete_success' => 'リビジョンを削除しました', + 'revision_cannot_delete_latest' => '最新のリビジョンを削除できません。' ]; diff --git a/resources/lang/nl/entities.php b/resources/lang/nl/entities.php index 043dfe321..29bb11a37 100644 --- a/resources/lang/nl/entities.php +++ b/resources/lang/nl/entities.php @@ -264,5 +264,6 @@ return [ * Revision */ 'revision_delete_confirm' => 'Weet u zeker dat u deze revisie wilt verwijderen?', - 'revision_delete_success' => 'Revisie verwijderd' + '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 e84054181..8b53591f6 100644 --- a/resources/lang/pl/entities.php +++ b/resources/lang/pl/entities.php @@ -262,5 +262,6 @@ return [ * Revision */ 'revision_delete_confirm' => 'Czy na pewno chcesz usunąć tę wersję?', - 'revision_delete_success' => 'Usunięto 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 9eeb8201d..d93b9dff9 100644 --- a/resources/lang/pt_BR/entities.php +++ b/resources/lang/pt_BR/entities.php @@ -263,5 +263,6 @@ return [ * Revision */ 'revision_delete_confirm' => 'Tem certeza de que deseja excluir esta revisão?', - 'revision_delete_success' => 'Revisão excluída' + '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 ef2caad40..9c3517beb 100644 --- a/resources/lang/ru/entities.php +++ b/resources/lang/ru/entities.php @@ -263,5 +263,6 @@ return [ * Revision */ 'revision_delete_confirm' => 'Вы действительно хотите удалить эту ревизию?', - 'revision_delete_success' => 'Редактирование удалено' + '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 4f0744012..7fbbaf2e2 100644 --- a/resources/lang/sk/entities.php +++ b/resources/lang/sk/entities.php @@ -237,5 +237,6 @@ return [ * Revision */ 'revision_delete_confirm' => 'Naozaj chcete túto revíziu odstrániť?', - 'revision_delete_success' => 'Revízia bola vymazaná' + '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 0f515fc50..8c09bd377 100644 --- a/resources/lang/sv/entities.php +++ b/resources/lang/sv/entities.php @@ -270,5 +270,6 @@ return [ * Revision */ 'revision_delete_confirm' => 'Är du säker på att du vill radera den här versionen?', - 'revision_delete_success' => 'Revisionen raderad' + '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 5e3b360a6..734a47a5a 100644 --- a/resources/lang/zh_CN/entities.php +++ b/resources/lang/zh_CN/entities.php @@ -262,5 +262,7 @@ return [ /** * Revision */ - 'revision_delete_confirm' => '您确定要删除此修订版吗?' + '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 f37d786b6..1c4d526fd 100644 --- a/resources/lang/zh_TW/entities.php +++ b/resources/lang/zh_TW/entities.php @@ -264,5 +264,6 @@ return [ * Revision */ 'revision_delete_confirm' => '您確定要刪除此修訂版嗎?', - 'revision_delete_success' => '修訂刪除' + 'revision_delete_success' => '修訂刪除', + 'revision_cannot_delete_latest' => '無法刪除最新版本。' ]; diff --git a/tests/Entity/PageRevisionTest.php b/tests/Entity/PageRevisionTest.php index beebc7adf..dd2b77255 100644 --- a/tests/Entity/PageRevisionTest.php +++ b/tests/Entity/PageRevisionTest.php @@ -11,7 +11,6 @@ class PageRevisionTest extends TestCase { $page = Page::first(); $startCount = $page->revision_count; - $resp = $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']); $resp->assertStatus(302); @@ -29,4 +28,26 @@ class PageRevisionTest extends TestCase $pageView->assertSee('Revision #' . $page->revision_count); } + public function test_revision_deletion() { + $page = Page::first(); + $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']); + $this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']); + $page = Page::find($page->id); + $beforeRevisionCount = $page->revisions->count(); + + // Delete the first revision + $revision = $page->revisions->get(0); + $resp = $this->asEditor()->delete($revision->getUrl('/delete/')); + $resp->assertStatus(200); + + $page = Page::find($page->id); + $afterRevisionCount = $page->revisions->count(); + + $this->assertTrue($beforeRevisionCount === ($afterRevisionCount + 1)); + + // Try to delete the latest revision + $revision = $page->revisions->get($page->revisions->count() - 1); + $resp = $this->asEditor()->delete($revision->getUrl('/delete/')); + $resp->assertSee('Cannot delete the latest revision'); + } } \ No newline at end of file From 81d3bdc168cdd1b55edabf0dc17a8534903aa585 Mon Sep 17 00:00:00 2001 From: Abijeet Date: Sat, 15 Sep 2018 21:08:00 +0530 Subject: [PATCH 5/7] Removes the BadRequestException class added earlier. Signed-off-by: Abijeet --- app/Exceptions/BadRequestException.php | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 app/Exceptions/BadRequestException.php diff --git a/app/Exceptions/BadRequestException.php b/app/Exceptions/BadRequestException.php deleted file mode 100644 index b0353bad4..000000000 --- a/app/Exceptions/BadRequestException.php +++ /dev/null @@ -1,14 +0,0 @@ - Date: Sun, 16 Sep 2018 01:12:36 +0530 Subject: [PATCH 6/7] Final tweaks after code review and fixing failing test cases. --- app/Http/Controllers/PageController.php | 4 ++-- app/Page.php | 12 ++++++++++++ app/PageRevision.php | 12 ------------ resources/assets/sass/_buttons.scss | 5 ----- resources/lang/en/entities.php | 1 - resources/views/pages/revisions.blade.php | 2 +- tests/Entity/PageRevisionTest.php | 10 +++++++--- 7 files changed, 22 insertions(+), 24 deletions(-) diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php index 4cfd4c832..505fb7e5a 100644 --- a/app/Http/Controllers/PageController.php +++ b/app/Http/Controllers/PageController.php @@ -475,10 +475,10 @@ class PageController extends Controller } // 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)) { + if (intval($currentRevision->id) === intval($revId)) { session()->flash('error', trans('entities.revision_cannot_delete_latest')); return view('pages/revisions', ['page' => $page, 'book' => $page->book, 'current' => $page]); } diff --git a/app/Page.php b/app/Page.php index 9554504b3..db6996c23 100644 --- a/app/Page.php +++ b/app/Page.php @@ -112,4 +112,16 @@ 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() + { + if ($id = PageRevision::where('page_id', '=', $this->id)->max('id')) { + return PageRevision::find($id); + } + return null; + } } diff --git a/app/PageRevision.php b/app/PageRevision.php index 8e5c16bc9..ffcc4f9d2 100644 --- a/app/PageRevision.php +++ b/app/PageRevision.php @@ -48,18 +48,6 @@ 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 7738eb4ba..2c20c3f41 100644 --- a/resources/assets/sass/_buttons.scss +++ b/resources/assets/sass/_buttons.scss @@ -119,11 +119,6 @@ $button-border-radius: 2px; &.neg { color: $negative; } - &.link { - &:hover { - text-decoration: underline; - } - } } .button-group { diff --git a/resources/lang/en/entities.php b/resources/lang/en/entities.php index 72d47bc01..c99887401 100644 --- a/resources/lang/en/entities.php +++ b/resources/lang/en/entities.php @@ -183,7 +183,6 @@ return [ 'pages_revisions_current' => 'Current Version', 'pages_revisions_preview' => 'Preview', 'pages_revisions_restore' => 'Restore', - 'pages_revisions_delete' => 'Delete', 'pages_revisions_none' => 'This page has no revisions', 'pages_copy_link' => 'Copy Link', 'pages_edit_content_link' => 'Edit Content', diff --git a/resources/views/pages/revisions.blade.php b/resources/views/pages/revisions.blade.php index 99be26153..72017467e 100644 --- a/resources/views/pages/revisions.blade.php +++ b/resources/views/pages/revisions.blade.php @@ -49,7 +49,7 @@ {{ trans('entities.pages_revisions_restore') }}  |