mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
Fixed page editor back button sometimes going nowhere
Updated the back button to be a proper link instead of a reference to the last viewed URL since it could break if the last page was the current one (On validation for example). Includes test to cover. Also applied some styleCI changes. Fixes #2834
This commit is contained in:
parent
88e6f93abf
commit
b546098b36
@ -13,8 +13,8 @@ class SearchApiController extends ApiController
|
|||||||
|
|
||||||
protected $rules = [
|
protected $rules = [
|
||||||
'all' => [
|
'all' => [
|
||||||
'query' => ['required'],
|
'query' => ['required'],
|
||||||
'page' => ['integer', 'min:1'],
|
'page' => ['integer', 'min:1'],
|
||||||
'count' => ['integer', 'min:1', 'max:100'],
|
'count' => ['integer', 'min:1', 'max:100'],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
@ -58,10 +58,8 @@ class SearchApiController extends ApiController
|
|||||||
}
|
}
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'data' => $results['results'],
|
'data' => $results['results'],
|
||||||
'total' => $results['total'],
|
'total' => $results['total'],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ use BookStack\Uploads\Attachment;
|
|||||||
use BookStack\Uploads\AttachmentService;
|
use BookStack\Uploads\AttachmentService;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||||
use Illuminate\Foundation\Http\Middleware\ValidatePostSize;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\MessageBag;
|
use Illuminate\Support\MessageBag;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
@ -20,7 +20,8 @@
|
|||||||
<div class="grid third no-break v-center">
|
<div class="grid third no-break v-center">
|
||||||
|
|
||||||
<div class="action-buttons text-left px-m py-xs">
|
<div class="action-buttons text-left px-m py-xs">
|
||||||
<a href="{{ back()->getTargetUrl() }}" class="text-button text-primary">@icon('back')<span class="hide-under-l">{{ trans('common.back') }}</span></a>
|
<a href="{{ $page->draft ? $page->getParent()->getUrl() : $page->getUrl() }}"
|
||||||
|
class="text-button text-primary">@icon('back')<span class="hide-under-l">{{ trans('common.back') }}</span></a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="text-center px-m py-xs">
|
<div class="text-center px-m py-xs">
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace Tests\Entity;
|
namespace Tests\Entity;
|
||||||
|
|
||||||
use BookStack\Entities\Models\Book;
|
use BookStack\Entities\Models\Book;
|
||||||
|
use BookStack\Entities\Models\Chapter;
|
||||||
use BookStack\Entities\Models\Page;
|
use BookStack\Entities\Models\Page;
|
||||||
use Tests\TestCase;
|
use Tests\TestCase;
|
||||||
|
|
||||||
@ -74,4 +75,31 @@ class PageEditorTest extends TestCase
|
|||||||
'draft' => false,
|
'draft' => false,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_back_link_in_editor_has_correct_url()
|
||||||
|
{
|
||||||
|
/** @var Book $book */
|
||||||
|
$book = Book::query()->whereHas('pages')->whereHas('chapters')->firstOrFail();
|
||||||
|
$this->asEditor()->get($book->getUrl('/create-page'));
|
||||||
|
/** @var Chapter $chapter */
|
||||||
|
$chapter = $book->chapters()->firstOrFail();
|
||||||
|
/** @var Page $draft */
|
||||||
|
$draft = $book->pages()->where('draft', '=', true)->firstOrFail();
|
||||||
|
|
||||||
|
// Book draft goes back to book
|
||||||
|
$resp = $this->get($book->getUrl("/draft/{$draft->id}"));
|
||||||
|
$resp->assertElementContains('a[href="' . $book->getUrl() . '"]', 'Back');
|
||||||
|
|
||||||
|
// Chapter draft goes back to chapter
|
||||||
|
$draft->chapter_id = $chapter->id;
|
||||||
|
$draft->save();
|
||||||
|
$resp = $this->get($book->getUrl("/draft/{$draft->id}"));
|
||||||
|
$resp->assertElementContains('a[href="' . $chapter->getUrl() . '"]', 'Back');
|
||||||
|
|
||||||
|
// Saved page goes back to page
|
||||||
|
$this->post($book->getUrl("/draft/{$draft->id}"), ['name' => 'Updated', 'html' => 'Updated']);
|
||||||
|
$draft->refresh();
|
||||||
|
$resp = $this->get($draft->getUrl('/edit'));
|
||||||
|
$resp->assertElementContains('a[href="' . $draft->getUrl() . '"]', 'Back');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user