Updated create routes to prevent slug clashes

Fixes #758
This commit is contained in:
Dan Brown 2018-03-25 11:34:42 +01:00
parent df1a3a0715
commit 1a9f676416
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
11 changed files with 51 additions and 55 deletions

View File

@ -5,7 +5,7 @@
<div class="breadcrumbs">
<a href="{{ baseUrl('/books') }}" class="text-button">@icon('book'){{ trans('entities.books') }}</a>
<span class="sep">&raquo;</span>
<a href="{{ baseUrl('/books/create') }}" class="text-button">@icon('add'){{ trans('entities.books_create') }}</a>
<a href="{{ baseUrl('/create-book') }}" class="text-button">@icon('add'){{ trans('entities.books_create') }}</a>
</div>
</div>
@stop

View File

@ -18,7 +18,7 @@
<div class="col-xs-6 faded">
<div class="action-buttons">
@if($currentUser->can('book-create-all'))
<a href="{{ baseUrl("/books/create") }}" class="text-pos text-button">@icon('add'){{ trans('entities.books_create') }}</a>
<a href="{{ baseUrl("/create-book") }}" class="text-pos text-button">@icon('add'){{ trans('entities.books_create') }}</a>
@endif
</div>
</div>
@ -78,7 +78,7 @@
@else
<p class="text-muted">{{ trans('entities.books_empty') }}</p>
@if(userCan('books-create-all'))
<a href="{{ baseUrl("/books/create") }}" class="text-pos">@icon('edit'){{ trans('entities.create_one_now') }}</a>
<a href="{{ baseUrl("/create-book") }}" class="text-pos">@icon('edit'){{ trans('entities.create_one_now') }}</a>
@endif
@endif
</div>

View File

@ -15,10 +15,10 @@
</ul>
</span>
@if(userCan('page-create', $book))
<a href="{{ $book->getUrl('/page/create') }}" class="text-pos text-button">@icon('add'){{ trans('entities.pages_new') }}</a>
<a href="{{ $book->getUrl('/create-page') }}" class="text-pos text-button">@icon('add'){{ trans('entities.pages_new') }}</a>
@endif
@if(userCan('chapter-create', $book))
<a href="{{ $book->getUrl('/chapter/create') }}" class="text-pos text-button">@icon('add'){{ trans('entities.chapters_new') }}</a>
<a href="{{ $book->getUrl('/create-chapter') }}" class="text-pos text-button">@icon('add'){{ trans('entities.chapters_new') }}</a>
@endif
@if(userCan('book-update', $book) || userCan('restrictions-manage', $book) || userCan('book-delete', $book))
<div dropdown class="dropdown-container">
@ -111,13 +111,13 @@
<div class="well">
<p class="text-muted italic">{{ trans('entities.books_empty_contents') }}</p>
@if(userCan('page-create', $book))
<a href="{{ $book->getUrl('/page/create') }}" class="button outline page">@icon('page'){{ trans('entities.books_empty_create_page') }}</a>
<a href="{{ $book->getUrl('/create-page') }}" class="button outline page">@icon('page'){{ trans('entities.books_empty_create_page') }}</a>
@endif
@if(userCan('page-create', $book) && userCan('chapter-create', $book))
&nbsp;&nbsp;<em class="text-muted">-{{ trans('entities.books_empty_or') }}-</em>&nbsp;&nbsp;&nbsp;
@endif
@if(userCan('chapter-create', $book))
<a href="{{ $book->getUrl('/chapter/create') }}" class="button outline chapter">@icon('chapter'){{ trans('entities.books_empty_add_chapter') }}</a>
<a href="{{ $book->getUrl('/create-chapter') }}" class="button outline chapter">@icon('chapter'){{ trans('entities.books_empty_add_chapter') }}</a>
@endif
</div>
@endif

View File

@ -3,9 +3,9 @@
@section('toolbar')
<div class="col-sm-12 faded">
<div class="breadcrumbs">
<a href="{{$book->getUrl()}}" class="text-book text-button">@icon('book'){{ $book->getShortName() }}</a>
<a href="{{ $book->getUrl() }}" class="text-book text-button">@icon('book'){{ $book->getShortName() }}</a>
<span class="sep">&raquo;</span>
<a href="{{ baseUrl('/books/chapter/create') }}" class="text-button">@icon('add'){{ trans('entities.chapters_create') }}</a>
<a href="{{ $book->getUrl('/create-chapter')}}" class="text-button">@icon('add'){{ trans('entities.chapters_create') }}</a>
</div>
</div>
@stop
@ -16,7 +16,7 @@
<div class="card">
<h3>@icon('add') {{ trans('entities.chapters_create') }}</h3>
<div class="body">
<form action="{{ $book->getUrl('/chapter/create') }}" method="POST">
<form action="{{ $book->getUrl('/create-chapter') }}" method="POST">
@include('chapters/form')
</form>
</div>

View File

@ -12,6 +12,6 @@
</div>
<div class="form-group text-right">
<a href="{{ back()->getTargetUrl() }}" class="button outline">{{ trans('common.cancel') }}</a>
<a href="{{ isset($chapter) ? $chapter->getUrl() : $book->getUrl() }}" class="button outline">{{ trans('common.cancel') }}</a>
<button type="submit" class="button pos">{{ trans('entities.chapters_save') }}</button>
</div>

View File

@ -4,7 +4,7 @@
<div class="container small" ng-non-bindable>
<h1>{{ trans('entities.pages_new') }}</h1>
<form action="{{ $parent->getUrl('/page/create/guest') }}" method="POST">
<form action="{{ $parent->getUrl('/create-guest-page') }}" method="POST">
{!! csrf_field() !!}

View File

@ -14,11 +14,11 @@ Route::group(['middleware' => 'auth'], function () {
Route::get('/recently-updated', 'PageController@showRecentlyUpdated');
});
Route::get('/create-book', 'BookController@create');
Route::group(['prefix' => 'books'], function () {
// Books
Route::get('/', 'BookController@index');
Route::get('/create', 'BookController@create');
Route::post('/', 'BookController@store');
Route::get('/{slug}/edit', 'BookController@edit');
Route::put('/{slug}', 'BookController@update');
@ -35,8 +35,8 @@ Route::group(['middleware' => 'auth'], function () {
Route::get('/{bookSlug}/export/plaintext', 'BookController@exportPlainText');
// Pages
Route::get('/{bookSlug}/page/create', 'PageController@create');
Route::post('/{bookSlug}/page/create/guest', 'PageController@createAsGuest');
Route::get('/{bookSlug}/create-page', 'PageController@create');
Route::post('/{bookSlug}/create-guest-page', 'PageController@createAsGuest');
Route::get('/{bookSlug}/draft/{pageId}', 'PageController@editDraft');
Route::post('/{bookSlug}/draft/{pageId}', 'PageController@store');
Route::get('/{bookSlug}/page/{pageSlug}', 'PageController@show');
@ -62,9 +62,9 @@ Route::group(['middleware' => 'auth'], function () {
// Chapters
Route::get('/{bookSlug}/chapter/{chapterSlug}/create-page', 'PageController@create');
Route::post('/{bookSlug}/chapter/{chapterSlug}/page/create/guest', 'PageController@createAsGuest');
Route::get('/{bookSlug}/chapter/create', 'ChapterController@create');
Route::post('/{bookSlug}/chapter/create', 'ChapterController@store');
Route::post('/{bookSlug}/chapter/{chapterSlug}/create-guest-page', 'PageController@createAsGuest');
Route::get('/{bookSlug}/create-chapter', 'ChapterController@create');
Route::post('/{bookSlug}/create-chapter', 'ChapterController@store');
Route::get('/{bookSlug}/chapter/{chapterSlug}', 'ChapterController@show');
Route::put('/{bookSlug}/chapter/{chapterSlug}', 'ChapterController@update');
Route::get('/{bookSlug}/chapter/{chapterSlug}/move', 'ChapterController@showMove');

View File

@ -139,7 +139,7 @@ class EntityTest extends BrowserKitTest
// Navigate to chapter create page
->visit($book->getUrl())
->click('New Chapter')
->seePageIs($book->getUrl() . '/chapter/create')
->seePageIs($book->getUrl() . '/create-chapter')
// Fill out form
->type($chapter->name, '#name')
->type($chapter->description, '#description')
@ -161,7 +161,7 @@ class EntityTest extends BrowserKitTest
->visit('/books')
// Choose to create a book
->click('Create New Book')
->seePageIs('/books/create')
->seePageIs('/create-book')
// Fill out form & save
->type($book->name, '#name')
->type($book->description, '#description')
@ -172,7 +172,7 @@ class EntityTest extends BrowserKitTest
// Ensure duplicate names are given different slugs
$this->asAdmin()
->visit('/books/create')
->visit('/create-book')
->type($book->name, '#name')
->type($book->description, '#description')
->press('Save Book');

View File

@ -70,7 +70,7 @@ class PageDraftTest extends BrowserKitTest
$book = \BookStack\Book::first();
$this->asAdmin()->visit('/')
->dontSeeInElement('#recent-drafts', 'New Page')
->visit($book->getUrl() . '/page/create')
->visit($book->getUrl() . '/create-page')
->visit('/')
->seeInElement('#recent-drafts', 'New Page');
}
@ -82,7 +82,7 @@ class PageDraftTest extends BrowserKitTest
$newUser = $this->getEditor();
$this->actingAs($newUser)->visit('/')
->visit($book->getUrl() . '/page/create')
->visit($book->getUrl() . '/create-page')
->visit($chapter->getUrl() . '/create-page')
->visit($book->getUrl())
->seeInElement('.page-list', 'New Page');

View File

@ -109,21 +109,21 @@ class RestrictionsTest extends BrowserKitTest
$this->setEntityRestrictions($book, ['view', 'delete', 'update']);
$this->forceVisit($bookUrl . '/chapter/create')
$this->forceVisit($bookUrl . '/create-chapter')
->see('You do not have permission')->seePageIs('/');
$this->forceVisit($bookUrl . '/page/create')
$this->forceVisit($bookUrl . '/create-page')
->see('You do not have permission')->seePageIs('/');
$this->visit($bookUrl)->dontSeeInElement('.action-buttons', 'New Page')
->dontSeeInElement('.action-buttons', 'New Chapter');
$this->setEntityRestrictions($book, ['view', 'create']);
$this->visit($bookUrl . '/chapter/create')
$this->visit($bookUrl . '/create-chapter')
->type('test chapter', 'name')
->type('test description for chapter', 'description')
->press('Save Chapter')
->seePageIs($bookUrl . '/chapter/test-chapter');
$this->visit($bookUrl . '/page/create')
$this->visit($bookUrl . '/create-page')
->type('test page', 'name')
->type('test content', 'html')
->press('Save Page')
@ -454,21 +454,21 @@ class RestrictionsTest extends BrowserKitTest
$this->setEntityRestrictions($book, ['view', 'delete', 'update']);
$this->forceVisit($bookUrl . '/chapter/create')
$this->forceVisit($bookUrl . '/create-chapter')
->see('You do not have permission')->seePageIs('/');
$this->forceVisit($bookUrl . '/page/create')
$this->forceVisit($bookUrl . '/create-page')
->see('You do not have permission')->seePageIs('/');
$this->visit($bookUrl)->dontSeeInElement('.action-buttons', 'New Page')
->dontSeeInElement('.action-buttons', 'New Chapter');
$this->setEntityRestrictions($book, ['view', 'create']);
$this->visit($bookUrl . '/chapter/create')
$this->visit($bookUrl . '/create-chapter')
->type('test chapter', 'name')
->type('test description for chapter', 'description')
->press('Save Chapter')
->seePageIs($bookUrl . '/chapter/test-chapter');
$this->visit($bookUrl . '/page/create')
$this->visit($bookUrl . '/create-page')
->type('test page', 'name')
->type('test content', 'html')
->press('Save Page')

View File

@ -214,12 +214,12 @@ class RolesTest extends BrowserKitTest
public function test_books_create_all_permissions()
{
$this->checkAccessPermission('book-create-all', [
'/books/create'
'/create-book'
], [
'/books' => 'Create New Book'
]);
$this->visit('/books/create')
$this->visit('/create-book')
->type('test book', 'name')
->type('book desc', 'description')
->press('Save Book')
@ -293,40 +293,38 @@ class RolesTest extends BrowserKitTest
{
$book = \BookStack\Book::take(1)->get()->first();
$ownBook = $this->createEntityChainBelongingToUser($this->user)['book'];
$baseUrl = $ownBook->getUrl() . '/chapter';
$this->checkAccessPermission('chapter-create-own', [
$baseUrl . '/create'
$ownBook->getUrl('/create-chapter')
], [
$ownBook->getUrl() => 'New Chapter'
]);
$this->visit($baseUrl . '/create')
$this->visit($ownBook->getUrl('/create-chapter'))
->type('test chapter', 'name')
->type('chapter desc', 'description')
->press('Save Chapter')
->seePageIs($baseUrl . '/test-chapter');
->seePageIs($ownBook->getUrl('/chapter/test-chapter'));
$this->visit($book->getUrl())
->dontSeeInElement('.action-buttons', 'New Chapter')
->visit($book->getUrl() . '/chapter/create')
->visit($book->getUrl('/create-chapter'))
->seePageIs('/');
}
public function test_chapter_create_all_permissions()
{
$book = \BookStack\Book::take(1)->get()->first();
$baseUrl = $book->getUrl() . '/chapter';
$this->checkAccessPermission('chapter-create-all', [
$baseUrl . '/create'
$book->getUrl('/create-chapter')
], [
$book->getUrl() => 'New Chapter'
]);
$this->visit($baseUrl . '/create')
$this->visit($book->getUrl('/create-chapter'))
->type('test chapter', 'name')
->type('chapter desc', 'description')
->press('Save Chapter')
->seePageIs($baseUrl . '/test-chapter');
->seePageIs($book->getUrl('/chapter/test-chapter'));
}
public function test_chapter_edit_own_permission()
@ -403,10 +401,8 @@ class RolesTest extends BrowserKitTest
$ownBook = $entities['book'];
$ownChapter = $entities['chapter'];
$baseUrl = $ownBook->getUrl() . '/page';
$createUrl = $baseUrl . '/create';
$createUrlChapter = $ownChapter->getUrl() . '/create-page';
$createUrl = $ownBook->getUrl('/create-page');
$createUrlChapter = $ownChapter->getUrl('/create-page');
$accessUrls = [$createUrl, $createUrlChapter];
foreach ($accessUrls as $url) {
@ -427,15 +423,15 @@ class RolesTest extends BrowserKitTest
$this->seePageIs($expectedUrl);
}
$this->visit($baseUrl . '/create')
$this->visit($createUrl)
->type('test page', 'name')
->type('page desc', 'html')
->press('Save Page')
->seePageIs($baseUrl . '/test-page');
->seePageIs($ownBook->getUrl('/page/test-page'));
$this->visit($book->getUrl())
->dontSeeInElement('.action-buttons', 'New Page')
->visit($book->getUrl() . '/page/create')
->visit($book->getUrl() . '/create-page')
->seePageIs('/');
$this->visit($chapter->getUrl())
->dontSeeInElement('.action-buttons', 'New Page')
@ -448,9 +444,9 @@ class RolesTest extends BrowserKitTest
$book = \BookStack\Book::take(1)->get()->first();
$chapter = \BookStack\Chapter::take(1)->get()->first();
$baseUrl = $book->getUrl() . '/page';
$createUrl = $baseUrl . '/create';
$createUrl = $book->getUrl('/create-page');
$createUrlChapter = $chapter->getUrl() . '/create-page';
$createUrlChapter = $chapter->getUrl('/create-page');
$accessUrls = [$createUrl, $createUrlChapter];
foreach ($accessUrls as $url) {
@ -471,17 +467,17 @@ class RolesTest extends BrowserKitTest
$this->seePageIs($expectedUrl);
}
$this->visit($baseUrl . '/create')
$this->visit($createUrl)
->type('test page', 'name')
->type('page desc', 'html')
->press('Save Page')
->seePageIs($baseUrl . '/test-page');
->seePageIs($book->getUrl('/page/test-page'));
$this->visit($chapter->getUrl() . '/create-page')
$this->visit($chapter->getUrl('/create-page'))
->type('new test page', 'name')
->type('page desc', 'html')
->press('Save Page')
->seePageIs($baseUrl . '/new-test-page');
->seePageIs($book->getUrl('/page/new-test-page'));
}
public function test_page_edit_own_permission()