mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-05-04 18:08:46 +03:00
Permissions: Cleanup after review of enum implementation PR
This commit is contained in:
@@ -342,7 +342,7 @@ class PageController extends Controller
|
||||
|
||||
$this->showSuccessNotification(trans('entities.pages_delete_draft_success'));
|
||||
|
||||
if ($chapter && userCan(\BookStack\Permissions\Permission::View, $chapter)) {
|
||||
if ($chapter && userCan(Permission::ChapterView, $chapter)) {
|
||||
return redirect($chapter->getUrl());
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use BookStack\Entities\Tools\TrashCan;
|
||||
use BookStack\Exceptions\MoveOperationException;
|
||||
use BookStack\Exceptions\PermissionsException;
|
||||
use BookStack\Facades\Activity;
|
||||
use BookStack\Permissions\Permission;
|
||||
use BookStack\Util\DatabaseTransaction;
|
||||
use Exception;
|
||||
|
||||
@@ -87,7 +88,7 @@ class ChapterRepo
|
||||
throw new MoveOperationException('Book to move chapter into not found');
|
||||
}
|
||||
|
||||
if (!userCan(\BookStack\Permissions\Permission::ChapterCreate, $parent)) {
|
||||
if (!userCan(Permission::ChapterCreate, $parent)) {
|
||||
throw new PermissionsException('User does not have permission to create a chapter within the chosen book');
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ use BookStack\Entities\Tools\TrashCan;
|
||||
use BookStack\Exceptions\MoveOperationException;
|
||||
use BookStack\Exceptions\PermissionsException;
|
||||
use BookStack\Facades\Activity;
|
||||
use BookStack\Permissions\Permission;
|
||||
use BookStack\References\ReferenceStore;
|
||||
use BookStack\References\ReferenceUpdater;
|
||||
use BookStack\Util\DatabaseTransaction;
|
||||
@@ -55,7 +56,7 @@ class PageRepo
|
||||
}
|
||||
|
||||
$defaultTemplate = $page->chapter->defaultTemplate ?? $page->book->defaultTemplate;
|
||||
if ($defaultTemplate && userCan(\BookStack\Permissions\Permission::View, $defaultTemplate)) {
|
||||
if ($defaultTemplate && userCan(Permission::PageView, $defaultTemplate)) {
|
||||
$page->forceFill([
|
||||
'html' => $defaultTemplate->html,
|
||||
'markdown' => $defaultTemplate->markdown,
|
||||
@@ -142,7 +143,7 @@ class PageRepo
|
||||
|
||||
protected function updateTemplateStatusAndContentFromInput(Page $page, array $input): void
|
||||
{
|
||||
if (isset($input['template']) && userCan(\BookStack\Permissions\Permission::TemplatesManage)) {
|
||||
if (isset($input['template']) && userCan(Permission::TemplatesManage)) {
|
||||
$page->template = ($input['template'] === 'true');
|
||||
}
|
||||
|
||||
@@ -165,7 +166,7 @@ class PageRepo
|
||||
$pageContent->setNewHTML($input['html'], user());
|
||||
}
|
||||
|
||||
if (($newEditor !== $currentEditor || empty($page->editor)) && userCan(\BookStack\Permissions\Permission::EditorChange)) {
|
||||
if (($newEditor !== $currentEditor || empty($page->editor)) && userCan(Permission::EditorChange)) {
|
||||
$page->editor = $newEditor->value;
|
||||
} elseif (empty($page->editor)) {
|
||||
$page->editor = $defaultEditor->value;
|
||||
@@ -271,7 +272,7 @@ class PageRepo
|
||||
throw new MoveOperationException('Book or chapter to move page into not found');
|
||||
}
|
||||
|
||||
if (!userCan(\BookStack\Permissions\Permission::PageCreate, $parent)) {
|
||||
if (!userCan(Permission::PageCreate, $parent)) {
|
||||
throw new PermissionsException('User does not have permission to create a page within the new parent');
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ use BookStack\Entities\Models\Page;
|
||||
use BookStack\Entities\Repos\BookRepo;
|
||||
use BookStack\Entities\Repos\ChapterRepo;
|
||||
use BookStack\Entities\Repos\PageRepo;
|
||||
use BookStack\Permissions\Permission;
|
||||
use BookStack\Uploads\Image;
|
||||
use BookStack\Uploads\ImageService;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
@@ -49,7 +50,7 @@ class Cloner
|
||||
|
||||
$copyChapter = $this->chapterRepo->create($chapterDetails, $parent);
|
||||
|
||||
if (userCan(\BookStack\Permissions\Permission::PageCreate, $copyChapter)) {
|
||||
if (userCan(Permission::PageCreate, $copyChapter)) {
|
||||
/** @var Page $page */
|
||||
foreach ($original->getVisiblePages() as $page) {
|
||||
$this->clonePage($page, $copyChapter, $page->name);
|
||||
@@ -61,7 +62,7 @@ class Cloner
|
||||
|
||||
/**
|
||||
* Clone the given book.
|
||||
* Clones all child chapters & pages.
|
||||
* Clones all child chapters and pages.
|
||||
*/
|
||||
public function cloneBook(Book $original, string $newName): Book
|
||||
{
|
||||
@@ -74,11 +75,11 @@ class Cloner
|
||||
// Clone contents
|
||||
$directChildren = $original->getDirectVisibleChildren();
|
||||
foreach ($directChildren as $child) {
|
||||
if ($child instanceof Chapter && userCan(\BookStack\Permissions\Permission::ChapterCreate, $copyBook)) {
|
||||
if ($child instanceof Chapter && userCan(Permission::ChapterCreate, $copyBook)) {
|
||||
$this->cloneChapter($child, $copyBook, $child->name);
|
||||
}
|
||||
|
||||
if ($child instanceof Page && !$child->draft && userCan(\BookStack\Permissions\Permission::PageCreate, $copyBook)) {
|
||||
if ($child instanceof Page && !$child->draft && userCan(Permission::PageCreate, $copyBook)) {
|
||||
$this->clonePage($child, $copyBook, $child->name);
|
||||
}
|
||||
}
|
||||
@@ -86,7 +87,7 @@ class Cloner
|
||||
// Clone bookshelf relationships
|
||||
/** @var Bookshelf $shelf */
|
||||
foreach ($original->shelves as $shelf) {
|
||||
if (userCan(\BookStack\Permissions\Permission::BookshelfUpdate, $shelf)) {
|
||||
if (userCan(Permission::BookshelfUpdate, $shelf)) {
|
||||
$shelf->appendBook($copyBook);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ use BookStack\Entities\Models\Page;
|
||||
use BookStack\Entities\Queries\EntityQueries;
|
||||
use BookStack\Entities\Tools\Markdown\HtmlToMarkdown;
|
||||
use BookStack\Entities\Tools\Markdown\MarkdownToHtml;
|
||||
use BookStack\Permissions\Permission;
|
||||
|
||||
class PageEditorData
|
||||
{
|
||||
@@ -98,9 +99,9 @@ class PageEditorData
|
||||
{
|
||||
$editorType = PageEditorType::forPage($page) ?: PageEditorType::getSystemDefault();
|
||||
|
||||
// Use requested editor if valid and if we have permission
|
||||
// Use the requested editor if valid and if we have permission
|
||||
$requestedType = PageEditorType::fromRequestValue($this->requestedEditor);
|
||||
if ($requestedType && userCan(\BookStack\Permissions\Permission::EditorChange)) {
|
||||
if ($requestedType && userCan(Permission::EditorChange)) {
|
||||
$editorType = $requestedType;
|
||||
}
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ class PermissionsUpdater
|
||||
|
||||
/** @var Book $book */
|
||||
foreach ($shelfBooks as $book) {
|
||||
if ($checkUserPermissions && !userCan(\BookStack\Permissions\Permission::RestrictionsManage, $book)) {
|
||||
if ($checkUserPermissions && !userCan(Permission::RestrictionsManage, $book)) {
|
||||
continue;
|
||||
}
|
||||
$book->permissions()->delete();
|
||||
|
||||
Reference in New Issue
Block a user