mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
Added clone of entity permissions on chapter/book promotion
This commit is contained in:
parent
d676e1e824
commit
90ec40691a
@ -121,6 +121,18 @@ class Cloner
|
|||||||
return $inputData;
|
return $inputData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy the permission settings from the source entity to the target entity.
|
||||||
|
*/
|
||||||
|
public function copyEntityPermissions(Entity $sourceEntity, Entity $targetEntity): void
|
||||||
|
{
|
||||||
|
$targetEntity->restricted = $sourceEntity->restricted;
|
||||||
|
$permissions = $sourceEntity->permissions()->get(['role_id', 'action'])->toArray();
|
||||||
|
$targetEntity->permissions()->delete();
|
||||||
|
$targetEntity->permissions()->createMany($permissions);
|
||||||
|
$targetEntity->rebuildPermissions();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an image instance to an UploadedFile instance to mimic
|
* Convert an image instance to an UploadedFile instance to mimic
|
||||||
* a file being uploaded.
|
* a file being uploaded.
|
||||||
|
@ -16,19 +16,13 @@ class HierarchyTransformer
|
|||||||
protected Cloner $cloner;
|
protected Cloner $cloner;
|
||||||
protected TrashCan $trashCan;
|
protected TrashCan $trashCan;
|
||||||
|
|
||||||
// TODO - Test setting book cover image from API
|
|
||||||
// Ensure we can update without resetting image accidentally
|
|
||||||
// Ensure api docs correct.
|
|
||||||
// TODO - As above but for shelves.
|
|
||||||
|
|
||||||
public function transformChapterToBook(Chapter $chapter): Book
|
public function transformChapterToBook(Chapter $chapter): Book
|
||||||
{
|
{
|
||||||
// TODO - Check permissions before call
|
// TODO - Check permissions before call
|
||||||
// Permissions: edit-chapter, delete-chapter, create-book
|
// Permissions: edit-chapter, delete-chapter, create-book
|
||||||
$inputData = $this->cloner->entityToInputData($chapter);
|
$inputData = $this->cloner->entityToInputData($chapter);
|
||||||
$book = $this->bookRepo->create($inputData);
|
$book = $this->bookRepo->create($inputData);
|
||||||
|
$this->cloner->copyEntityPermissions($chapter, $book);
|
||||||
// TODO - Copy permissions
|
|
||||||
|
|
||||||
/** @var Page $page */
|
/** @var Page $page */
|
||||||
foreach ($chapter->pages as $page) {
|
foreach ($chapter->pages as $page) {
|
||||||
@ -48,8 +42,7 @@ class HierarchyTransformer
|
|||||||
// Permissions: edit-book, delete-book, create-shelf
|
// Permissions: edit-book, delete-book, create-shelf
|
||||||
$inputData = $this->cloner->entityToInputData($book);
|
$inputData = $this->cloner->entityToInputData($book);
|
||||||
$shelf = $this->shelfRepo->create($inputData, []);
|
$shelf = $this->shelfRepo->create($inputData, []);
|
||||||
|
$this->cloner->copyEntityPermissions($book, $shelf);
|
||||||
// TODO - Copy permissions?
|
|
||||||
|
|
||||||
$shelfBookSyncData = [];
|
$shelfBookSyncData = [];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user