1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2024-11-23 11:22:33 +01:00

Adds code to delete the revision.

Signed-off-by: Abijeet <abijeetpatro@gmail.com>
This commit is contained in:
Abijeet 2018-09-15 15:15:42 +05:30
parent d2a9b312e9
commit 714c7bbd3a
9 changed files with 90 additions and 4 deletions

View File

@ -0,0 +1,14 @@
<?php namespace BookStack\Exceptions;
class BadRequestException extends PrettyException
{
/**
* BadRequestException constructor.
* @param string $message
*/
public function __construct($message = 'Bad request')
{
parent::__construct($message, 400);
}
}

View File

@ -2,6 +2,7 @@
use Activity;
use BookStack\Exceptions\NotFoundException;
use BookStack\Exceptions\BadRequestException;
use BookStack\Repos\EntityRepo;
use BookStack\Repos\UserRepo;
use BookStack\Services\ExportService;
@ -454,6 +455,38 @@ class PageController extends Controller
return redirect($page->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

View File

@ -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.

View File

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

View File

@ -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;
}

View File

@ -41,6 +41,9 @@ table.table {
.text-center {
text-align: center;
}
td.actions {
overflow: visible;
}
}
table.no-style {

View File

@ -36,16 +36,31 @@
<td> @if($revision->createdBy) {{ $revision->createdBy->name }} @else {{ trans('common.deleted_user') }} @endif</td>
<td><small>{{ $revision->created_at->format('jS F, Y H:i:s') }} <br> ({{ $revision->created_at->diffForHumans() }})</small></td>
<td>{{ $revision->summary }}</td>
<td>
<td class="actions">
<a href="{{ $revision->getUrl('changes') }}" target="_blank">{{ trans('entities.pages_revisions_changes') }}</a>
<span class="text-muted">&nbsp;|&nbsp;</span>
@if ($index === 0)
<a target="_blank" href="{{ $page->getUrl() }}"><i>{{ trans('entities.pages_revisions_current') }}</i></a>
@else
<a href="{{ $revision->getUrl() }}" target="_blank">{{ trans('entities.pages_revisions_preview') }}</a>
<span class="text-muted">&nbsp;|&nbsp;</span>
<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>
<ul>
<li class="padded"><small class="text-muted">{{trans('entities.revision_delete_confirm')}}</small></li>
<li>
<form action="{{ $revision->getUrl('/delete/') }}" method="POST">
{!! csrf_field() !!}
<input type="hidden" name="_method" value="DELETE">
<button type="submit" class="text-button neg">@icon('delete'){{ trans('common.delete') }}</button>
</form>
</li>
</ul>
</div>
@endif
</td>
</tr>

View File

@ -19,4 +19,4 @@
color: {{ setting('app-color') }};
fill: {{ setting('app-color') }};
}
</style>
</style>

View File

@ -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