mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-03-24 23:35:15 +08:00
Added bookshelf permission control UI and copy-down ability
This commit is contained in:
parent
0b6f83837b
commit
6eead437d8
app
resources
routes
@ -189,37 +189,56 @@ class BookshelfController extends Controller
|
|||||||
$this->entityRepo->destroyBookshelf($bookshelf);
|
$this->entityRepo->destroyBookshelf($bookshelf);
|
||||||
return redirect('/shelves');
|
return redirect('/shelves');
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// /**
|
/**
|
||||||
// * Show the Restrictions view.
|
* Show the Restrictions view.
|
||||||
// * @param $bookSlug
|
* @param $slug
|
||||||
// * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||||
// */
|
* @throws \BookStack\Exceptions\NotFoundException
|
||||||
// public function showRestrict($bookSlug)
|
*/
|
||||||
// {
|
public function showRestrict(string $slug)
|
||||||
// $book = $this->entityRepo->getBySlug('book', $bookSlug);
|
{
|
||||||
// $this->checkOwnablePermission('restrictions-manage', $book);
|
$bookshelf = $this->entityRepo->getBySlug('bookshelf', $slug);
|
||||||
// $roles = $this->userRepo->getRestrictableRoles();
|
$this->checkOwnablePermission('restrictions-manage', $bookshelf);
|
||||||
// return view('books/restrictions', [
|
|
||||||
// 'book' => $book,
|
$roles = $this->userRepo->getRestrictableRoles();
|
||||||
// 'roles' => $roles
|
return view('shelves.restrictions', [
|
||||||
// ]);
|
'shelf' => $bookshelf,
|
||||||
// }
|
'roles' => $roles
|
||||||
//
|
]);
|
||||||
// /**
|
}
|
||||||
// * Set the restrictions for this book.
|
|
||||||
// * @param $bookSlug
|
/**
|
||||||
// * @param $bookSlug
|
* Set the restrictions for this bookshelf.
|
||||||
// * @param Request $request
|
* @param $slug
|
||||||
// * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
* @param Request $request
|
||||||
// */
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||||
// public function restrict($bookSlug, Request $request)
|
* @throws \BookStack\Exceptions\NotFoundException
|
||||||
// {
|
*/
|
||||||
// $book = $this->entityRepo->getBySlug('book', $bookSlug);
|
public function restrict(string $slug, Request $request)
|
||||||
// $this->checkOwnablePermission('restrictions-manage', $book);
|
{
|
||||||
// $this->entityRepo->updateEntityPermissionsFromRequest($request, $book);
|
$bookshelf = $this->entityRepo->getBySlug('bookshelf', $slug);
|
||||||
// session()->flash('success', trans('entities.books_permissions_updated'));
|
$this->checkOwnablePermission('restrictions-manage', $bookshelf);
|
||||||
// return redirect($book->getUrl());
|
|
||||||
// }
|
$this->entityRepo->updateEntityPermissionsFromRequest($request, $bookshelf);
|
||||||
|
session()->flash('success', trans('entities.shelves_permissions_updated'));
|
||||||
|
return redirect($bookshelf->getUrl());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy the permissions of a bookshelf to the child books.
|
||||||
|
* @param string $slug
|
||||||
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||||
|
* @throws \BookStack\Exceptions\NotFoundException
|
||||||
|
*/
|
||||||
|
public function copyPermissions(string $slug)
|
||||||
|
{
|
||||||
|
$bookshelf = $this->entityRepo->getBySlug('bookshelf', $slug);
|
||||||
|
$this->checkOwnablePermission('restrictions-manage', $bookshelf);
|
||||||
|
|
||||||
|
$updateCount = $this->entityRepo->copyBookshelfPermissions($bookshelf);
|
||||||
|
session()->flash('success', trans('entities.shelves_copy_permission_success', ['count' => $updateCount]));
|
||||||
|
return redirect($bookshelf->getUrl());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1282,4 +1282,29 @@ class EntityRepo
|
|||||||
$this->permissionService->deleteJointPermissionsForEntity($entity);
|
$this->permissionService->deleteJointPermissionsForEntity($entity);
|
||||||
$this->searchService->deleteEntityTerms($entity);
|
$this->searchService->deleteEntityTerms($entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy the permissions of a bookshelf to all child books.
|
||||||
|
* Returns the number of books that had permissions updated.
|
||||||
|
* @param Bookshelf $bookshelf
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function copyBookshelfPermissions(Bookshelf $bookshelf)
|
||||||
|
{
|
||||||
|
$shelfPermissions = $bookshelf->permissions()->get(['role_id', 'action'])->toArray();
|
||||||
|
$shelfBooks = $bookshelf->books()->get();
|
||||||
|
$updatedBookCount = 0;
|
||||||
|
|
||||||
|
foreach ($shelfBooks as $book) {
|
||||||
|
if (!userCan('restrictions-manage', $book)) continue;
|
||||||
|
$book->permissions()->delete();
|
||||||
|
$book->restricted = $bookshelf->restricted;
|
||||||
|
$book->permissions()->createMany($shelfPermissions);
|
||||||
|
$book->save();
|
||||||
|
$this->permissionService->buildJointPermissionsForEntity($book);
|
||||||
|
$updatedBookCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $updatedBookCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ return [
|
|||||||
* Shelves
|
* Shelves
|
||||||
*/
|
*/
|
||||||
'shelves' => 'Shelves',
|
'shelves' => 'Shelves',
|
||||||
'shelves_long' => 'BookShelves',
|
'shelves_long' => 'Bookshelves',
|
||||||
'shelves_empty' => 'No shelves have been created',
|
'shelves_empty' => 'No shelves have been created',
|
||||||
'shelves_create' => 'Create New Shelf',
|
'shelves_create' => 'Create New Shelf',
|
||||||
'shelves_popular' => 'Popular Shelves',
|
'shelves_popular' => 'Popular Shelves',
|
||||||
@ -87,6 +87,13 @@ return [
|
|||||||
'shelves_delete_named' => 'Delete Bookshelf :name',
|
'shelves_delete_named' => 'Delete Bookshelf :name',
|
||||||
'shelves_delete_explain' => "This will delete the bookshelf with the name ':name'. Contained books will not be deleted.",
|
'shelves_delete_explain' => "This will delete the bookshelf with the name ':name'. Contained books will not be deleted.",
|
||||||
'shelves_delete_confirmation' => 'Are you sure you want to delete this bookshelf?',
|
'shelves_delete_confirmation' => 'Are you sure you want to delete this bookshelf?',
|
||||||
|
'shelves_permissions' => 'Bookshelf Permissions',
|
||||||
|
'shelves_permissions_updated' => 'Bookshelf Permissions Updated',
|
||||||
|
'shelves_permissions_active' => 'Bookshelf Permissions Active',
|
||||||
|
'shelves_copy_permissions_to_books' => 'Copy Permissions to Books',
|
||||||
|
'shelves_copy_permissions' => 'Copy Permissions',
|
||||||
|
'shelves_copy_permissions_explain' => 'This will apply the current permission settings of this bookshelf to all books contained within. Before activating, ensure any changes to the permissions of this bookshelf have been saved.',
|
||||||
|
'shelves_copy_permission_success' => 'Bookshelf permissions copied to :count books',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Books
|
* Books
|
||||||
|
@ -2,18 +2,31 @@
|
|||||||
|
|
||||||
@section('toolbar')
|
@section('toolbar')
|
||||||
<div class="col-sm-12 faded">
|
<div class="col-sm-12 faded">
|
||||||
@include('books._breadcrumbs', ['book' => $book])
|
@include('shelves._breadcrumbs', ['shelf' => $shelf])
|
||||||
</div>
|
</div>
|
||||||
@stop
|
@stop
|
||||||
|
|
||||||
@section('body')
|
@section('body')
|
||||||
|
|
||||||
<div class="container">
|
<div class="container small">
|
||||||
<p> </p>
|
<p> </p>
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h3>@icon('lock') {{ trans('entities.books_permissions') }}</h3>
|
<h3>@icon('lock') {{ trans('entities.shelves_permissions') }}</h3>
|
||||||
<div class="body">
|
<div class="body">
|
||||||
@include('form/restriction-form', ['model' => $book])
|
@include('form/restriction-form', ['model' => $shelf])
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p> </p>
|
||||||
|
|
||||||
|
<div class="card">
|
||||||
|
<h3>@icon('copy') {{ trans('entities.shelves_copy_permissions_to_books') }}</h3>
|
||||||
|
<div class="body">
|
||||||
|
<p>{{ trans('entities.shelves_copy_permissions_explain') }}</p>
|
||||||
|
<form action="{{ $shelf->getUrl('/copy-permissions') }}" method="post" class="text-right">
|
||||||
|
{{ csrf_field() }}
|
||||||
|
<button class="button">{{ trans('entities.shelves_copy_permissions') }}</button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -24,6 +24,9 @@ Route::group(['middleware' => 'auth'], function () {
|
|||||||
Route::get('/{slug}', 'BookshelfController@show');
|
Route::get('/{slug}', 'BookshelfController@show');
|
||||||
Route::put('/{slug}', 'BookshelfController@update');
|
Route::put('/{slug}', 'BookshelfController@update');
|
||||||
Route::delete('/{slug}', 'BookshelfController@destroy');
|
Route::delete('/{slug}', 'BookshelfController@destroy');
|
||||||
|
Route::get('/{slug}/permissions', 'BookshelfController@showRestrict');
|
||||||
|
Route::put('/{slug}/permissions', 'BookshelfController@restrict');
|
||||||
|
Route::post('/{slug}/copy-permissions', 'BookshelfController@copyPermissions');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::get('/create-book', 'BookController@create');
|
Route::get('/create-book', 'BookController@create');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user