Skip to content

NOW MANAGED ON CODEBERG

Final tweaks after code review and fixing failing test cases.

Abijeet0c8b6b732418
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 @@
<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>
diff --git a/tests/Entity/PageRevisionTest.php b/tests/Entity/PageRevisionTest.php
index dd2b77255..cd7aa766e 100644
--- a/tests/Entity/PageRevisionTest.php
+++ b/tests/Entity/PageRevisionTest.php
@@ -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