1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Added command to copy shelf permissions

Has options to run for all or to specify a slug for a specific shelf.

Closes #1091
This commit is contained in:
Dan Brown
2019-12-11 21:21:19 +00:00
parent cee4dccc55
commit 02af69ddf2
3 changed files with 139 additions and 3 deletions

View File

@ -139,15 +139,15 @@ class BookshelfRepo
/**
* Copy down the permissions of the given shelf to all child books.
*/
public function copyDownPermissions(Bookshelf $shelf): int
public function copyDownPermissions(Bookshelf $shelf, $checkUserPermissions = true): int
{
$shelfPermissions = $shelf->permissions()->get(['role_id', 'action'])->toArray();
$shelfBooks = $shelf->books()->get();
$shelfBooks = $shelf->books()->get(['id', 'restricted']);
$updatedBookCount = 0;
/** @var Book $book */
foreach ($shelfBooks as $book) {
if (!userCan('restrictions-manage', $book)) {
if ($checkUserPermissions && !userCan('restrictions-manage', $book)) {
continue;
}
$book->permissions()->delete();