Final tweaks after code review and fixing failing test cases.

This commit is contained in:
Abijeet 2018-09-16 01:12:36 +05:30
parent 81d3bdc168
commit 0c8b6b7324
7 changed files with 22 additions and 24 deletions

View File

@ -475,10 +475,10 @@ class PageController extends Controller
} }
// Get the current revision for the page // Get the current revision for the page
$current = $revision->getCurrent(); $currentRevision = $page->getCurrentRevision();
// Check if its the latest revision, cannot delete latest revision. // 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')); session()->flash('error', trans('entities.revision_cannot_delete_latest'));
return view('pages/revisions', ['page' => $page, 'book' => $page->book, 'current' => $page]); return view('pages/revisions', ['page' => $page, 'book' => $page->book, 'current' => $page]);
} }

View File

@ -112,4 +112,16 @@ class Page extends Entity
$htmlQuery = $withContent ? 'html' : "'' as html"; $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"; 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;
}
} }

View File

@ -48,18 +48,6 @@ class PageRevision extends Model
return null; 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. * Allows checking of the exact class, Used to check entity type.
* Included here to align with entities in similar use cases. * Included here to align with entities in similar use cases.

View File

@ -119,11 +119,6 @@ $button-border-radius: 2px;
&.neg { &.neg {
color: $negative; color: $negative;
} }
&.link {
&:hover {
text-decoration: underline;
}
}
} }
.button-group { .button-group {

View File

@ -183,7 +183,6 @@ return [
'pages_revisions_current' => 'Current Version', 'pages_revisions_current' => 'Current Version',
'pages_revisions_preview' => 'Preview', 'pages_revisions_preview' => 'Preview',
'pages_revisions_restore' => 'Restore', 'pages_revisions_restore' => 'Restore',
'pages_revisions_delete' => 'Delete',
'pages_revisions_none' => 'This page has no revisions', 'pages_revisions_none' => 'This page has no revisions',
'pages_copy_link' => 'Copy Link', 'pages_copy_link' => 'Copy Link',
'pages_edit_content_link' => 'Edit Content', 'pages_edit_content_link' => 'Edit Content',

View File

@ -49,7 +49,7 @@
<a href="{{ $revision->getUrl('restore') }}">{{ trans('entities.pages_revisions_restore') }}</a> <a href="{{ $revision->getUrl('restore') }}">{{ trans('entities.pages_revisions_restore') }}</a>
<span class="text-muted">&nbsp;|&nbsp;</span> <span class="text-muted">&nbsp;|&nbsp;</span>
<div dropdown class="dropdown-container"> <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> <ul>
<li class="padded"><small class="text-muted">{{trans('entities.revision_delete_confirm')}}</small></li> <li class="padded"><small class="text-muted">{{trans('entities.revision_delete_confirm')}}</small></li>
<li> <li>

View File

@ -46,8 +46,12 @@ class PageRevisionTest extends TestCase
$this->assertTrue($beforeRevisionCount === ($afterRevisionCount + 1)); $this->assertTrue($beforeRevisionCount === ($afterRevisionCount + 1));
// Try to delete the latest revision // Try to delete the latest revision
$revision = $page->revisions->get($page->revisions->count() - 1); $beforeRevisionCount = $page->revisions->count();
$resp = $this->asEditor()->delete($revision->getUrl('/delete/')); $currentRevision = $page->getCurrentRevision();
$resp->assertSee('Cannot delete the latest revision'); $this->asEditor()->delete($currentRevision->getUrl('/delete/'));
$page = Page::find($page->id);
$afterRevisionCount = $page->revisions->count();
$this->assertTrue($beforeRevisionCount === $afterRevisionCount);
} }
} }