mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-02-20 23:09:56 +08:00
Final tweaks after code review and fixing failing test cases.
This commit is contained in:
parent
81d3bdc168
commit
0c8b6b7324
@ -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]);
|
||||
}
|
||||
|
12
app/Page.php
12
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;
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -119,11 +119,6 @@ $button-border-radius: 2px;
|
||||
&.neg {
|
||||
color: $negative;
|
||||
}
|
||||
&.link {
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.button-group {
|
||||
|
@ -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',
|
||||
|
@ -49,7 +49,7 @@
|
||||
<a href="{{ $revision->getUrl('restore') }}">{{ trans('entities.pages_revisions_restore') }}</a>
|
||||
<span class="text-muted"> | </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>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user