mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-23 13:44:18 +08:00
Updated view-change endpoints to be clearer, separated books and shelf
- Separated books-list and shelf-show view types to be saved separately. During review of #1755
This commit is contained in:
parent
b8c16b15a9
commit
053cbbd5b6
|
@ -103,11 +103,11 @@ class BookshelfController extends Controller
|
||||||
public function show(string $slug)
|
public function show(string $slug)
|
||||||
{
|
{
|
||||||
$shelf = $this->bookshelfRepo->getBySlug($slug);
|
$shelf = $this->bookshelfRepo->getBySlug($slug);
|
||||||
$view = setting()->getForCurrentUser('books_view_type', config('app.views.books'));
|
|
||||||
$this->checkOwnablePermission('book-view', $shelf);
|
$this->checkOwnablePermission('book-view', $shelf);
|
||||||
|
|
||||||
Views::add($shelf);
|
Views::add($shelf);
|
||||||
$this->entityContextManager->setShelfContext($shelf->id);
|
$this->entityContextManager->setShelfContext($shelf->id);
|
||||||
|
$view = setting()->getForCurrentUser('bookshelf_view_type', config('app.views.books'));
|
||||||
|
|
||||||
$this->setPageTitle($shelf->getShortName());
|
$this->setPageTitle($shelf->getShortName());
|
||||||
return view('shelves.show', [
|
return view('shelves.show', [
|
||||||
|
|
|
@ -7,7 +7,6 @@ use BookStack\Auth\UserRepo;
|
||||||
use BookStack\Exceptions\UserUpdateException;
|
use BookStack\Exceptions\UserUpdateException;
|
||||||
use BookStack\Uploads\ImageRepo;
|
use BookStack\Uploads\ImageRepo;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class UserController extends Controller
|
class UserController extends Controller
|
||||||
|
@ -20,10 +19,6 @@ class UserController extends Controller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UserController constructor.
|
* UserController constructor.
|
||||||
* @param User $user
|
|
||||||
* @param UserRepo $userRepo
|
|
||||||
* @param UserInviteService $inviteService
|
|
||||||
* @param ImageRepo $imageRepo
|
|
||||||
*/
|
*/
|
||||||
public function __construct(User $user, UserRepo $userRepo, UserInviteService $inviteService, ImageRepo $imageRepo)
|
public function __construct(User $user, UserRepo $userRepo, UserInviteService $inviteService, ImageRepo $imageRepo)
|
||||||
{
|
{
|
||||||
|
@ -36,8 +31,6 @@ class UserController extends Controller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display a listing of the users.
|
* Display a listing of the users.
|
||||||
* @param Request $request
|
|
||||||
* @return Response
|
|
||||||
*/
|
*/
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
|
@ -55,7 +48,6 @@ class UserController extends Controller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the form for creating a new user.
|
* Show the form for creating a new user.
|
||||||
* @return Response
|
|
||||||
*/
|
*/
|
||||||
public function create()
|
public function create()
|
||||||
{
|
{
|
||||||
|
@ -67,9 +59,8 @@ class UserController extends Controller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store a newly created user in storage.
|
* Store a newly created user in storage.
|
||||||
* @param Request $request
|
|
||||||
* @return Response
|
|
||||||
* @throws UserUpdateException
|
* @throws UserUpdateException
|
||||||
|
* @throws \Illuminate\Validation\ValidationException
|
||||||
*/
|
*/
|
||||||
public function store(Request $request)
|
public function store(Request $request)
|
||||||
{
|
{
|
||||||
|
@ -138,13 +129,11 @@ class UserController extends Controller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the specified user in storage.
|
* Update the specified user in storage.
|
||||||
* @param Request $request
|
|
||||||
* @param int $id
|
|
||||||
* @return Response
|
|
||||||
* @throws UserUpdateException
|
* @throws UserUpdateException
|
||||||
* @throws \BookStack\Exceptions\ImageUploadException
|
* @throws \BookStack\Exceptions\ImageUploadException
|
||||||
|
* @throws \Illuminate\Validation\ValidationException
|
||||||
*/
|
*/
|
||||||
public function update(Request $request, $id)
|
public function update(Request $request, int $id)
|
||||||
{
|
{
|
||||||
$this->preventAccessInDemoMode();
|
$this->preventAccessInDemoMode();
|
||||||
$this->checkPermissionOrCurrentUser('users-manage', $id);
|
$this->checkPermissionOrCurrentUser('users-manage', $id);
|
||||||
|
@ -212,10 +201,8 @@ class UserController extends Controller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the user delete page.
|
* Show the user delete page.
|
||||||
* @param int $id
|
|
||||||
* @return \Illuminate\View\View
|
|
||||||
*/
|
*/
|
||||||
public function delete($id)
|
public function delete(int $id)
|
||||||
{
|
{
|
||||||
$this->checkPermissionOrCurrentUser('users-manage', $id);
|
$this->checkPermissionOrCurrentUser('users-manage', $id);
|
||||||
|
|
||||||
|
@ -226,11 +213,9 @@ class UserController extends Controller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the specified user from storage.
|
* Remove the specified user from storage.
|
||||||
* @param int $id
|
|
||||||
* @return Response
|
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function destroy($id)
|
public function destroy(int $id)
|
||||||
{
|
{
|
||||||
$this->preventAccessInDemoMode();
|
$this->preventAccessInDemoMode();
|
||||||
$this->checkPermissionOrCurrentUser('users-manage', $id);
|
$this->checkPermissionOrCurrentUser('users-manage', $id);
|
||||||
|
@ -255,8 +240,6 @@ class UserController extends Controller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the user profile page
|
* Show the user profile page
|
||||||
* @param $id
|
|
||||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
|
||||||
*/
|
*/
|
||||||
public function showProfilePage($id)
|
public function showProfilePage($id)
|
||||||
{
|
{
|
||||||
|
@ -276,34 +259,32 @@ class UserController extends Controller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the user's preferred book-list display setting.
|
* Update the user's preferred book-list display setting.
|
||||||
* @param Request $request
|
|
||||||
* @param $id
|
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
|
||||||
*/
|
*/
|
||||||
public function switchBookView(Request $request, $id)
|
public function switchBooksView(Request $request, int $id)
|
||||||
{
|
{
|
||||||
return $this->switchViewType($id, $request, 'books');
|
return $this->switchViewType($id, $request, 'books');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the user's preferred shelf-list display setting.
|
* Update the user's preferred shelf-list display setting.
|
||||||
* @param Request $request
|
|
||||||
* @param $id
|
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
|
||||||
*/
|
*/
|
||||||
public function switchShelfView(Request $request, $id)
|
public function switchShelvesView(Request $request, int $id)
|
||||||
{
|
{
|
||||||
return $this->switchViewType($id, $request, 'bookshelves');
|
return $this->switchViewType($id, $request, 'bookshelves');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For a type of list, switch with stored view type for a user.
|
* Update the user's preferred shelf-view book list display setting.
|
||||||
* @param integer $userId
|
|
||||||
* @param Request $request
|
|
||||||
* @param string $listName
|
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
|
||||||
*/
|
*/
|
||||||
protected function switchViewType($userId, Request $request, string $listName)
|
public function switchShelfView(Request $request, int $id)
|
||||||
|
{
|
||||||
|
return $this->switchViewType($id, $request, 'bookshelf');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For a type of list, switch with stored view type for a user.
|
||||||
|
*/
|
||||||
|
protected function switchViewType(int $userId, Request $request, string $listName)
|
||||||
{
|
{
|
||||||
$this->checkPermissionOrCurrentUser('users-manage', $userId);
|
$this->checkPermissionOrCurrentUser('users-manage', $userId);
|
||||||
|
|
||||||
|
@ -321,10 +302,6 @@ class UserController extends Controller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change the stored sort type for a particular view.
|
* Change the stored sort type for a particular view.
|
||||||
* @param Request $request
|
|
||||||
* @param string $id
|
|
||||||
* @param string $type
|
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
|
||||||
*/
|
*/
|
||||||
public function changeSort(Request $request, string $id, string $type)
|
public function changeSort(Request $request, string $id, string $type)
|
||||||
{
|
{
|
||||||
|
@ -337,10 +314,6 @@ class UserController extends Controller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the stored section expansion preference for the given user.
|
* Update the stored section expansion preference for the given user.
|
||||||
* @param Request $request
|
|
||||||
* @param string $id
|
|
||||||
* @param string $key
|
|
||||||
* @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
|
|
||||||
*/
|
*/
|
||||||
public function updateExpansionPreference(Request $request, string $id, string $key)
|
public function updateExpansionPreference(Request $request, string $id, string $key)
|
||||||
{
|
{
|
||||||
|
@ -359,10 +332,6 @@ class UserController extends Controller
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changed the stored preference for a list sort order.
|
* Changed the stored preference for a list sort order.
|
||||||
* @param int $userId
|
|
||||||
* @param Request $request
|
|
||||||
* @param string $listName
|
|
||||||
* @return \Illuminate\Http\RedirectResponse
|
|
||||||
*/
|
*/
|
||||||
protected function changeListSort(int $userId, Request $request, string $listName)
|
protected function changeListSort(int $userId, Request $request, string $listName)
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
</a>
|
</a>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@include('partials.view-toggle', ['view' => $view, 'type' => 'book'])
|
@include('partials.view-toggle', ['view' => $view, 'type' => 'books'])
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<div class="actions mb-xl">
|
<div class="actions mb-xl">
|
||||||
<h5>{{ trans('common.actions') }}</h5>
|
<h5>{{ trans('common.actions') }}</h5>
|
||||||
<div class="icon-list text-primary">
|
<div class="icon-list text-primary">
|
||||||
@include('partials.view-toggle', ['view' => $view, 'type' => 'book'])
|
@include('partials.view-toggle', ['view' => $view, 'type' => 'books'])
|
||||||
@include('components.expand-toggle', ['target' => '.entity-list.compact .entity-item-snippet', 'key' => 'home-details'])
|
@include('components.expand-toggle', ['target' => '.entity-list.compact .entity-item-snippet', 'key' => 'home-details'])
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<div class="actions mb-xl">
|
<div class="actions mb-xl">
|
||||||
<h5>{{ trans('common.actions') }}</h5>
|
<h5>{{ trans('common.actions') }}</h5>
|
||||||
<div class="icon-list text-primary">
|
<div class="icon-list text-primary">
|
||||||
@include('partials.view-toggle', ['view' => $view, 'type' => 'shelf'])
|
@include('partials.view-toggle', ['view' => $view, 'type' => 'shelves'])
|
||||||
@include('components.expand-toggle', ['target' => '.entity-list.compact .entity-item-snippet', 'key' => 'home-details'])
|
@include('components.expand-toggle', ['target' => '.entity-list.compact .entity-item-snippet', 'key' => 'home-details'])
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<span>{{ trans('entities.shelves_new_action') }}</span>
|
<span>{{ trans('entities.shelves_new_action') }}</span>
|
||||||
</a>
|
</a>
|
||||||
@endif
|
@endif
|
||||||
@include('partials.view-toggle', ['view' => $view, 'type' => 'shelf'])
|
@include('partials.view-toggle', ['view' => $view, 'type' => 'shelves'])
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@
|
||||||
</a>
|
</a>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
@include('partials.view-toggle', ['view' => $view, 'type' => 'book'])
|
@include('partials.view-toggle', ['view' => $view, 'type' => 'shelf'])
|
||||||
|
|
||||||
<hr class="primary-background">
|
<hr class="primary-background">
|
||||||
|
|
||||||
|
|
|
@ -178,7 +178,8 @@ Route::group(['middleware' => 'auth'], function () {
|
||||||
Route::get('/users', 'UserController@index');
|
Route::get('/users', 'UserController@index');
|
||||||
Route::get('/users/create', 'UserController@create');
|
Route::get('/users/create', 'UserController@create');
|
||||||
Route::get('/users/{id}/delete', 'UserController@delete');
|
Route::get('/users/{id}/delete', 'UserController@delete');
|
||||||
Route::patch('/users/{id}/switch-book-view', 'UserController@switchBookView');
|
Route::patch('/users/{id}/switch-books-view', 'UserController@switchBooksView');
|
||||||
|
Route::patch('/users/{id}/switch-shelves-view', 'UserController@switchShelvesView');
|
||||||
Route::patch('/users/{id}/switch-shelf-view', 'UserController@switchShelfView');
|
Route::patch('/users/{id}/switch-shelf-view', 'UserController@switchShelfView');
|
||||||
Route::patch('/users/{id}/change-sort/{type}', 'UserController@changeSort');
|
Route::patch('/users/{id}/change-sort/{type}', 'UserController@changeSort');
|
||||||
Route::patch('/users/{id}/update-expansion-preference/{key}', 'UserController@updateExpansionPreference');
|
Route::patch('/users/{id}/update-expansion-preference/{key}', 'UserController@updateExpansionPreference');
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
<?php namespace Test\User;
|
<?php namespace Test\User;
|
||||||
|
|
||||||
|
use Activity;
|
||||||
|
use BookStack\Auth\User;
|
||||||
|
use BookStack\Entities\Bookshelf;
|
||||||
use Tests\BrowserKitTest;
|
use Tests\BrowserKitTest;
|
||||||
|
|
||||||
class UserProfileTest extends BrowserKitTest
|
class UserProfileTest extends BrowserKitTest
|
||||||
|
@ -9,7 +12,7 @@ class UserProfileTest extends BrowserKitTest
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
$this->user = \BookStack\Auth\User::all()->last();
|
$this->user = User::all()->last();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_profile_page_shows_name()
|
public function test_profile_page_shows_name()
|
||||||
|
@ -57,8 +60,8 @@ class UserProfileTest extends BrowserKitTest
|
||||||
$newUser = $this->getNewBlankUser();
|
$newUser = $this->getNewBlankUser();
|
||||||
$this->actingAs($newUser);
|
$this->actingAs($newUser);
|
||||||
$entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
|
$entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
|
||||||
\Activity::add($entities['book'], 'book_update', $entities['book']->id);
|
Activity::add($entities['book'], 'book_update', $entities['book']->id);
|
||||||
\Activity::add($entities['page'], 'page_create', $entities['book']->id);
|
Activity::add($entities['page'], 'page_create', $entities['book']->id);
|
||||||
|
|
||||||
$this->asAdmin()->visit('/user/' . $newUser->id)
|
$this->asAdmin()->visit('/user/' . $newUser->id)
|
||||||
->seeInElement('#recent-user-activity', 'updated book')
|
->seeInElement('#recent-user-activity', 'updated book')
|
||||||
|
@ -71,8 +74,8 @@ class UserProfileTest extends BrowserKitTest
|
||||||
$newUser = $this->getNewBlankUser();
|
$newUser = $this->getNewBlankUser();
|
||||||
$this->actingAs($newUser);
|
$this->actingAs($newUser);
|
||||||
$entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
|
$entities = $this->createEntityChainBelongingToUser($newUser, $newUser);
|
||||||
\Activity::add($entities['book'], 'book_update', $entities['book']->id);
|
Activity::add($entities['book'], 'book_update', $entities['book']->id);
|
||||||
\Activity::add($entities['page'], 'page_create', $entities['book']->id);
|
Activity::add($entities['page'], 'page_create', $entities['book']->id);
|
||||||
|
|
||||||
$this->asAdmin()->visit('/')->clickInElement('#recent-activity', $newUser->name)
|
$this->asAdmin()->visit('/')->clickInElement('#recent-activity', $newUser->name)
|
||||||
->seePageIs('/user/' . $newUser->id)
|
->seePageIs('/user/' . $newUser->id)
|
||||||
|
@ -89,7 +92,7 @@ class UserProfileTest extends BrowserKitTest
|
||||||
|
|
||||||
public function test_guest_profile_cannot_be_deleted()
|
public function test_guest_profile_cannot_be_deleted()
|
||||||
{
|
{
|
||||||
$guestUser = \BookStack\Auth\User::getDefault();
|
$guestUser = User::getDefault();
|
||||||
$this->asAdmin()->visit('/settings/users/' . $guestUser->id . '/delete')
|
$this->asAdmin()->visit('/settings/users/' . $guestUser->id . '/delete')
|
||||||
->see('Delete User')->see('Guest')
|
->see('Delete User')->see('Guest')
|
||||||
->press('Confirm')
|
->press('Confirm')
|
||||||
|
@ -118,4 +121,24 @@ class UserProfileTest extends BrowserKitTest
|
||||||
->pageHasElement('.featured-image-container');
|
->pageHasElement('.featured-image-container');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_shelf_view_type_change()
|
||||||
|
{
|
||||||
|
$editor = $this->getEditor();
|
||||||
|
$shelf = Bookshelf::query()->first();
|
||||||
|
setting()->putUser($editor, 'bookshelf_view_type', 'list');
|
||||||
|
|
||||||
|
$this->actingAs($editor)->visit($shelf->getUrl())
|
||||||
|
->pageNotHasElement('.featured-image-container')
|
||||||
|
->pageHasElement('.content-wrap .entity-list-item')
|
||||||
|
->see('Grid View');
|
||||||
|
|
||||||
|
$req = $this->patch("/settings/users/{$editor->id}/switch-shelf-view", ['view_type' => 'grid']);
|
||||||
|
$req->assertRedirectedTo($shelf->getUrl());
|
||||||
|
|
||||||
|
$this->actingAs($editor)->visit($shelf->getUrl())
|
||||||
|
->pageHasElement('.featured-image-container')
|
||||||
|
->pageNotHasElement('.content-wrap .entity-list-item')
|
||||||
|
->see('List View');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user