]> BookStack Code Mirror - bookstack/commitdiff
Final tweaks after code review and fixing failing test cases.
authorAbijeet <redacted>
Sat, 15 Sep 2018 19:42:36 +0000 (01:12 +0530)
committerAbijeet <redacted>
Sat, 15 Sep 2018 19:42:36 +0000 (01:12 +0530)
app/Http/Controllers/PageController.php
app/Page.php
app/PageRevision.php
resources/assets/sass/_buttons.scss
resources/lang/en/entities.php
resources/views/pages/revisions.blade.php
tests/Entity/PageRevisionTest.php

index 4cfd4c8328a7e39b8339a4dee5e3808643b468c2..505fb7e5a1af0bb5663ab7a87b9540d0891708ea 100644 (file)
@@ -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]);
         }
index 9554504b35d2466e4c8741ce41bca05adaa8e966..db6996c23494da1f9f5fdc717ddc2fbe43127ff4 100644 (file)
@@ -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;
+    }
 }
index 8e5c16bc9e17f0ae68ddb7bfe9f20658f7648602..ffcc4f9d25b26ec81eb6fc89db62b4393666e0a6 100644 (file)
@@ -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.
index 7738eb4baf4e907d9f7d42970589209d740c3067..2c20c3f41a50eba38ef7b4a957cde2d6140d4f7d 100644 (file)
@@ -119,11 +119,6 @@ $button-border-radius: 2px;
   &.neg {
     color: $negative;
   }
-  &.link {
-    &:hover {
-      text-decoration: underline;
-    }
-  }
 }
 
 .button-group {
index 72d47bc017b7522e38f16b9c3d288c81c6974116..c998874011d4abc6fe60a9770ca1c16f474c940f 100644 (file)
@@ -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',
index 99be2615322ee5382d77c40ef9d0cc6ab844bceb..72017467ed133b41f945e72f12d8c59ab8151908 100644 (file)
@@ -49,7 +49,7 @@
                                         <a href="{{ $revision->getUrl('restore') }}">{{ trans('entities.pages_revisions_restore') }}</a>
                                         <span class="text-muted">&nbsp;|&nbsp;</span>
                                         <div dropdown class="dropdown-container">
-                                            <button type="button" dropdown-toggle class="text-button link">{{ trans('common.delete') }}</button>
+                                            <a dropdown-toggle>{{ trans('common.delete') }}</a>
                                             <ul>
                                                 <li class="padded"><small class="text-muted">{{trans('entities.revision_delete_confirm')}}</small></li>
                                                 <li>
index dd2b77255467d00cc031f8ad4e4341609580ae89..cd7aa766e8c13f01a7123da2edd2da3853fd8258 100644 (file)
@@ -46,8 +46,12 @@ class PageRevisionTest extends TestCase
         $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');
+        $beforeRevisionCount = $page->revisions->count();
+        $currentRevision = $page->getCurrentRevision();
+        $this->asEditor()->delete($currentRevision->getUrl('/delete/'));
+
+        $page = Page::find($page->id);
+        $afterRevisionCount = $page->revisions->count();
+        $this->assertTrue($beforeRevisionCount === $afterRevisionCount);
     }
 }
\ No newline at end of file