diff --git a/app/Actions/ActivityLogger.php b/app/Actions/ActivityLogger.php index 0d1391b43..eea5409fb 100644 --- a/app/Actions/ActivityLogger.php +++ b/app/Actions/ActivityLogger.php @@ -2,7 +2,6 @@ namespace BookStack\Actions; -use BookStack\Auth\Permissions\PermissionService; use BookStack\Entities\Models\Entity; use BookStack\Interfaces\Loggable; use Illuminate\Database\Eloquent\Builder; @@ -10,13 +9,6 @@ use Illuminate\Support\Facades\Log; class ActivityLogger { - protected $permissionService; - - public function __construct(PermissionService $permissionService) - { - $this->permissionService = $permissionService; - } - /** * Add a generic activity event to the database. * diff --git a/app/Actions/ActivityQueries.php b/app/Actions/ActivityQueries.php index f900fbb05..0b8cd3b5e 100644 --- a/app/Actions/ActivityQueries.php +++ b/app/Actions/ActivityQueries.php @@ -2,7 +2,7 @@ namespace BookStack\Actions; -use BookStack\Auth\Permissions\PermissionService; +use BookStack\Auth\Permissions\PermissionApplicator; use BookStack\Auth\User; use BookStack\Entities\Models\Book; use BookStack\Entities\Models\Chapter; @@ -13,11 +13,11 @@ use Illuminate\Database\Eloquent\Relations\Relation; class ActivityQueries { - protected $permissionService; + protected PermissionApplicator $permissions; - public function __construct(PermissionService $permissionService) + public function __construct(PermissionApplicator $permissions) { - $this->permissionService = $permissionService; + $this->permissions = $permissions; } /** @@ -25,7 +25,7 @@ class ActivityQueries */ public function latest(int $count = 20, int $page = 0): array { - $activityList = $this->permissionService + $activityList = $this->permissions ->filterRestrictedEntityRelations(Activity::query(), 'activities', 'entity_id', 'entity_type') ->orderBy('created_at', 'desc') ->with(['user', 'entity']) @@ -78,7 +78,7 @@ class ActivityQueries */ public function userActivity(User $user, int $count = 20, int $page = 0): array { - $activityList = $this->permissionService + $activityList = $this->permissions ->filterRestrictedEntityRelations(Activity::query(), 'activities', 'entity_id', 'entity_type') ->orderBy('created_at', 'desc') ->where('user_id', '=', $user->id) diff --git a/app/Actions/TagRepo.php b/app/Actions/TagRepo.php index 8cf107601..c5807108e 100644 --- a/app/Actions/TagRepo.php +++ b/app/Actions/TagRepo.php @@ -2,7 +2,7 @@ namespace BookStack\Actions; -use BookStack\Auth\Permissions\PermissionService; +use BookStack\Auth\Permissions\PermissionApplicator; use BookStack\Entities\Models\Entity; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Collection; @@ -10,12 +10,11 @@ use Illuminate\Support\Facades\DB; class TagRepo { - protected $tag; - protected $permissionService; + protected PermissionApplicator $permissions; - public function __construct(PermissionService $ps) + public function __construct(PermissionApplicator $permissions) { - $this->permissionService = $ps; + $this->permissions = $permissions; } /** @@ -51,7 +50,7 @@ class TagRepo }); } - return $this->permissionService->filterRestrictedEntityRelations($query, 'tags', 'entity_id', 'entity_type'); + return $this->permissions->filterRestrictedEntityRelations($query, 'tags', 'entity_id', 'entity_type'); } /** @@ -70,7 +69,7 @@ class TagRepo $query = $query->orderBy('count', 'desc')->take(50); } - $query = $this->permissionService->filterRestrictedEntityRelations($query, 'tags', 'entity_id', 'entity_type'); + $query = $this->permissions->filterRestrictedEntityRelations($query, 'tags', 'entity_id', 'entity_type'); return $query->get(['name'])->pluck('name'); } @@ -96,7 +95,7 @@ class TagRepo $query = $query->where('name', '=', $tagName); } - $query = $this->permissionService->filterRestrictedEntityRelations($query, 'tags', 'entity_id', 'entity_type'); + $query = $this->permissions->filterRestrictedEntityRelations($query, 'tags', 'entity_id', 'entity_type'); return $query->get(['value'])->pluck('value'); } diff --git a/app/Auth/Permissions/JointPermissionBuilder.php b/app/Auth/Permissions/JointPermissionBuilder.php index c87560fe0..fbf77741a 100644 --- a/app/Auth/Permissions/JointPermissionBuilder.php +++ b/app/Auth/Permissions/JointPermissionBuilder.php @@ -20,6 +20,82 @@ class JointPermissionBuilder */ protected $entityCache; + /** + * Re-generate all entity permission from scratch. + */ + public function rebuildForAll() + { + JointPermission::query()->truncate(); + $this->readyEntityCache(); + + // Get all roles (Should be the most limited dimension) + $roles = Role::query()->with('permissions')->get()->all(); + + // Chunk through all books + $this->bookFetchQuery()->chunk(5, function (EloquentCollection $books) use ($roles) { + $this->buildJointPermissionsForBooks($books, $roles); + }); + + // Chunk through all bookshelves + Bookshelf::query()->withTrashed()->select(['id', 'restricted', 'owned_by']) + ->chunk(50, function (EloquentCollection $shelves) use ($roles) { + $this->createManyJointPermissions($shelves->all(), $roles); + }); + } + + /** + * Rebuild the entity jointPermissions for a particular entity. + * + * @throws Throwable + */ + public function rebuildForEntity(Entity $entity) + { + $entities = [$entity]; + if ($entity instanceof Book) { + $books = $this->bookFetchQuery()->where('id', '=', $entity->id)->get(); + $this->buildJointPermissionsForBooks($books, Role::query()->with('permissions')->get()->all(), true); + + return; + } + + /** @var BookChild $entity */ + if ($entity->book) { + $entities[] = $entity->book; + } + + if ($entity instanceof Page && $entity->chapter_id) { + $entities[] = $entity->chapter; + } + + if ($entity instanceof Chapter) { + foreach ($entity->pages as $page) { + $entities[] = $page; + } + } + + $this->buildJointPermissionsForEntities($entities); + } + + /** + * Build the entity jointPermissions for a particular role. + */ + public function rebuildForRole(Role $role) + { + $roles = [$role]; + $role->jointPermissions()->delete(); + + // Chunk through all books + $this->bookFetchQuery()->chunk(20, function ($books) use ($roles) { + $this->buildJointPermissionsForBooks($books, $roles); + }); + + // Chunk through all bookshelves + Bookshelf::query()->select(['id', 'restricted', 'owned_by']) + ->chunk(50, function ($shelves) use ($roles) { + $this->createManyJointPermissions($shelves->all(), $roles); + }); + } + /** * Prepare the local entity cache and ensure it's empty. * @@ -66,29 +142,6 @@ class JointPermissionBuilder ->find($chapterId); } - /** - * Re-generate all entity permission from scratch. - */ - public function buildJointPermissions() - { - JointPermission::query()->truncate(); - $this->readyEntityCache(); - - // Get all roles (Should be the most limited dimension) - $roles = Role::query()->with('permissions')->get()->all(); - - // Chunk through all books - $this->bookFetchQuery()->chunk(5, function (EloquentCollection $books) use ($roles) { - $this->buildJointPermissionsForBooks($books, $roles); - }); - - // Chunk through all bookshelves - Bookshelf::query()->withTrashed()->select(['id', 'restricted', 'owned_by']) - ->chunk(50, function (EloquentCollection $shelves) use ($roles) { - $this->buildJointPermissionsForShelves($shelves, $roles); - }); - } - /** * Get a query for fetching a book with it's children. */ @@ -105,18 +158,6 @@ class JointPermissionBuilder ]); } - /** - * Build joint permissions for the given shelf and role combinations. - * - * @throws Throwable - */ - protected function buildJointPermissionsForShelves(EloquentCollection $shelves, array $roles, bool $deleteOld = false) - { - if ($deleteOld) { - $this->deleteManyJointPermissionsForEntities($shelves->all()); - } - $this->createManyJointPermissions($shelves->all(), $roles); - } /** * Build joint permissions for the given book and role combinations. @@ -144,39 +185,6 @@ class JointPermissionBuilder $this->createManyJointPermissions($entities->all(), $roles); } - /** - * Rebuild the entity jointPermissions for a particular entity. - * - * @throws Throwable - */ - public function buildJointPermissionsForEntity(Entity $entity) - { - $entities = [$entity]; - if ($entity instanceof Book) { - $books = $this->bookFetchQuery()->where('id', '=', $entity->id)->get(); - $this->buildJointPermissionsForBooks($books, Role::query()->with('permissions')->get()->all(), true); - - return; - } - - /** @var BookChild $entity */ - if ($entity->book) { - $entities[] = $entity->book; - } - - if ($entity instanceof Page && $entity->chapter_id) { - $entities[] = $entity->chapter; - } - - if ($entity instanceof Chapter) { - foreach ($entity->pages as $page) { - $entities[] = $page; - } - } - - $this->buildJointPermissionsForEntities($entities); - } - /** * Rebuild the entity jointPermissions for a collection of entities. * @@ -189,26 +197,6 @@ class JointPermissionBuilder $this->createManyJointPermissions($entities, $roles); } - /** - * Build the entity jointPermissions for a particular role. - */ - public function buildJointPermissionForRole(Role $role) - { - $roles = [$role]; - $role->jointPermissions()->delete(); - - // Chunk through all books - $this->bookFetchQuery()->chunk(20, function ($books) use ($roles) { - $this->buildJointPermissionsForBooks($books, $roles); - }); - - // Chunk through all bookshelves - Bookshelf::query()->select(['id', 'restricted', 'owned_by']) - ->chunk(50, function ($shelves) use ($roles) { - $this->buildJointPermissionsForShelves($shelves, $roles); - }); - } - /** * Delete all the entity jointPermissions for a list of entities. * diff --git a/app/Auth/Permissions/PermissionService.php b/app/Auth/Permissions/PermissionApplicator.php similarity index 99% rename from app/Auth/Permissions/PermissionService.php rename to app/Auth/Permissions/PermissionApplicator.php index bcd4a3675..3dc529e32 100644 --- a/app/Auth/Permissions/PermissionService.php +++ b/app/Auth/Permissions/PermissionApplicator.php @@ -12,10 +12,10 @@ use BookStack\Traits\HasOwner; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Query\Builder as QueryBuilder; -class PermissionService +class PermissionApplicator { /** - * @var ?array + * @var ?array */ protected $userRoles = null; @@ -24,7 +24,6 @@ class PermissionService */ protected $currentUserModel = null; - /** * Get the roles for the current logged in user. */ diff --git a/app/Auth/Permissions/PermissionsRepo.php b/app/Auth/Permissions/PermissionsRepo.php index 0527875ae..2c2bedb72 100644 --- a/app/Auth/Permissions/PermissionsRepo.php +++ b/app/Auth/Permissions/PermissionsRepo.php @@ -27,7 +27,7 @@ class PermissionsRepo */ public function getAllRoles(): Collection { - return Role::query()->all(); + return Role::query()->get(); } /** @@ -57,7 +57,7 @@ class PermissionsRepo $permissions = isset($roleData['permissions']) ? array_keys($roleData['permissions']) : []; $this->assignRolePermissions($role, $permissions); - $this->permissionBuilder->buildJointPermissionForRole($role); + $this->permissionBuilder->rebuildForRole($role); Activity::add(ActivityType::ROLE_CREATE, $role); @@ -88,7 +88,7 @@ class PermissionsRepo $role->fill($roleData); $role->mfa_enforced = ($roleData['mfa_enforced'] ?? 'false') === 'true'; $role->save(); - $this->permissionBuilder->buildJointPermissionForRole($role); + $this->permissionBuilder->rebuildForRole($role); Activity::add(ActivityType::ROLE_UPDATE, $role); } @@ -102,7 +102,7 @@ class PermissionsRepo $permissionNameArray = array_values($permissionNameArray); if ($permissionNameArray) { - $permissions = EntityPermission::query() + $permissions = RolePermission::query() ->whereIn('name', $permissionNameArray) ->pluck('id') ->toArray(); diff --git a/app/Config/app.php b/app/Config/app.php index 2b1de6f45..5f516f4ad 100644 --- a/app/Config/app.php +++ b/app/Config/app.php @@ -202,7 +202,6 @@ return [ // Custom BookStack 'Activity' => BookStack\Facades\Activity::class, - 'Permissions' => BookStack\Facades\Permissions::class, 'Theme' => BookStack\Facades\Theme::class, ], diff --git a/app/Console/Commands/RegeneratePermissions.php b/app/Console/Commands/RegeneratePermissions.php index 558ae9fea..3396a445f 100644 --- a/app/Console/Commands/RegeneratePermissions.php +++ b/app/Console/Commands/RegeneratePermissions.php @@ -42,11 +42,11 @@ class RegeneratePermissions extends Command { $connection = DB::getDefaultConnection(); - if ($this->hasOption('database')) { + if ($this->option('database')) { DB::setDefaultConnection($this->option('database')); } - $this->permissionBuilder->buildJointPermissions(); + $this->permissionBuilder->rebuildForAll(); DB::setDefaultConnection($connection); $this->comment('Permissions regenerated'); diff --git a/app/Entities/Models/Entity.php b/app/Entities/Models/Entity.php index 7ad78f1d1..84d31d82d 100644 --- a/app/Entities/Models/Entity.php +++ b/app/Entities/Models/Entity.php @@ -9,9 +9,10 @@ use BookStack\Actions\Tag; use BookStack\Actions\View; use BookStack\Auth\Permissions\EntityPermission; use BookStack\Auth\Permissions\JointPermission; +use BookStack\Auth\Permissions\JointPermissionBuilder; +use BookStack\Auth\Permissions\PermissionApplicator; use BookStack\Entities\Tools\SearchIndex; use BookStack\Entities\Tools\SlugGenerator; -use BookStack\Facades\Permissions; use BookStack\Interfaces\Deletable; use BookStack\Interfaces\Favouritable; use BookStack\Interfaces\Loggable; @@ -76,7 +77,7 @@ abstract class Entity extends Model implements Sluggable, Favouritable, Viewable */ public function scopeHasPermission(Builder $query, string $permission) { - return Permissions::restrictEntityQuery($query, $permission); + return app()->make(PermissionApplicator::class)->restrictEntityQuery($query, $permission); } /** @@ -284,8 +285,7 @@ abstract class Entity extends Model implements Sluggable, Favouritable, Viewable */ public function rebuildPermissions() { - /** @noinspection PhpUnhandledExceptionInspection */ - Permissions::buildJointPermissionsForEntity(clone $this); + app()->make(JointPermissionBuilder::class)->rebuildForEntity(clone $this); } /** @@ -293,7 +293,7 @@ abstract class Entity extends Model implements Sluggable, Favouritable, Viewable */ public function indexForSearch() { - app(SearchIndex::class)->indexEntity(clone $this); + app()->make(SearchIndex::class)->indexEntity(clone $this); } /** @@ -301,7 +301,7 @@ abstract class Entity extends Model implements Sluggable, Favouritable, Viewable */ public function refreshSlug(): string { - $this->slug = app(SlugGenerator::class)->generate($this); + $this->slug = app()->make(SlugGenerator::class)->generate($this); return $this->slug; } diff --git a/app/Entities/Models/Page.php b/app/Entities/Models/Page.php index ed69bcf8b..a2690b2a0 100644 --- a/app/Entities/Models/Page.php +++ b/app/Entities/Models/Page.php @@ -2,8 +2,8 @@ namespace BookStack\Entities\Models; +use BookStack\Auth\Permissions\PermissionApplicator; use BookStack\Entities\Tools\PageContent; -use BookStack\Facades\Permissions; use BookStack\Uploads\Attachment; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; @@ -51,7 +51,7 @@ class Page extends BookChild */ public function scopeVisible(Builder $query): Builder { - $query = Permissions::enforceDraftVisibilityOnQuery($query); + $query = app()->make(PermissionApplicator::class)->enforceDraftVisibilityOnQuery($query); return parent::scopeVisible($query); } diff --git a/app/Entities/Queries/EntityQuery.php b/app/Entities/Queries/EntityQuery.php index 76ab16ffc..5ab882ca8 100644 --- a/app/Entities/Queries/EntityQuery.php +++ b/app/Entities/Queries/EntityQuery.php @@ -2,14 +2,14 @@ namespace BookStack\Entities\Queries; -use BookStack\Auth\Permissions\PermissionService; +use BookStack\Auth\Permissions\PermissionApplicator; use BookStack\Entities\EntityProvider; abstract class EntityQuery { - protected function permissionService(): PermissionService + protected function permissionService(): PermissionApplicator { - return app()->make(PermissionService::class); + return app()->make(PermissionApplicator::class); } protected function entityProvider(): EntityProvider diff --git a/app/Entities/Tools/SearchRunner.php b/app/Entities/Tools/SearchRunner.php index a591914f3..5d94379c9 100644 --- a/app/Entities/Tools/SearchRunner.php +++ b/app/Entities/Tools/SearchRunner.php @@ -2,7 +2,7 @@ namespace BookStack\Entities\Tools; -use BookStack\Auth\Permissions\PermissionService; +use BookStack\Auth\Permissions\PermissionApplicator; use BookStack\Auth\User; use BookStack\Entities\EntityProvider; use BookStack\Entities\Models\BookChild; @@ -21,20 +21,14 @@ use SplObjectStorage; class SearchRunner { - /** - * @var EntityProvider - */ - protected $entityProvider; - /** - * @var PermissionService - */ - protected $permissionService; + protected EntityProvider $entityProvider; + protected PermissionApplicator $permissions; /** * Acceptable operators to be used in a query. * - * @var array + * @var string[] */ protected $queryOperators = ['<=', '>=', '=', '<', '>', 'like', '!=']; @@ -46,10 +40,10 @@ class SearchRunner */ protected $termAdjustmentCache; - public function __construct(EntityProvider $entityProvider, PermissionService $permissionService) + public function __construct(EntityProvider $entityProvider, PermissionApplicator $permissions) { $this->entityProvider = $entityProvider; - $this->permissionService = $permissionService; + $this->permissions = $permissions; $this->termAdjustmentCache = new SplObjectStorage(); } @@ -199,7 +193,7 @@ class SearchRunner } } - return $this->permissionService->enforceEntityRestrictions($entityModelInstance, $entityQuery, $action); + return $this->permissions->enforceEntityRestrictions($entityModelInstance, $entityQuery, $action); } /** diff --git a/app/Facades/Permissions.php b/app/Facades/Permissions.php deleted file mode 100644 index 74cbe46fe..000000000 --- a/app/Facades/Permissions.php +++ /dev/null @@ -1,18 +0,0 @@ -app->make(ActivityLogger::class); }); - $this->app->singleton('images', function () { - return $this->app->make(ImageService::class); - }); - - $this->app->singleton('permissions', function () { - return $this->app->make(PermissionService::class); - }); - $this->app->singleton('theme', function () { return $this->app->make(ThemeService::class); }); diff --git a/app/Uploads/Attachment.php b/app/Uploads/Attachment.php index 5e637246a..d9e0ce7e1 100644 --- a/app/Uploads/Attachment.php +++ b/app/Uploads/Attachment.php @@ -2,7 +2,7 @@ namespace BookStack\Uploads; -use BookStack\Auth\Permissions\PermissionService; +use BookStack\Auth\Permissions\PermissionApplicator; use BookStack\Auth\User; use BookStack\Entities\Models\Entity; use BookStack\Entities\Models\Page; @@ -89,9 +89,9 @@ class Attachment extends Model */ public function scopeVisible(): Builder { - $permissionService = app()->make(PermissionService::class); + $permissions = app()->make(PermissionApplicator::class); - return $permissionService->filterRelatedEntity( + return $permissions->filterRelatedEntity( Page::class, self::query(), 'attachments', diff --git a/app/Uploads/ImageRepo.php b/app/Uploads/ImageRepo.php index bfe4b5977..13d3344dd 100644 --- a/app/Uploads/ImageRepo.php +++ b/app/Uploads/ImageRepo.php @@ -2,7 +2,7 @@ namespace BookStack\Uploads; -use BookStack\Auth\Permissions\PermissionService; +use BookStack\Auth\Permissions\PermissionApplicator; use BookStack\Entities\Models\Page; use BookStack\Exceptions\ImageUploadException; use Exception; @@ -11,16 +11,16 @@ use Symfony\Component\HttpFoundation\File\UploadedFile; class ImageRepo { - protected $imageService; - protected $restrictionService; + protected ImageService $imageService; + protected PermissionApplicator $permissions; /** * ImageRepo constructor. */ - public function __construct(ImageService $imageService, PermissionService $permissionService) + public function __construct(ImageService $imageService, PermissionApplicator $permissions) { $this->imageService = $imageService; - $this->restrictionService = $permissionService; + $this->permissions = $permissions; } /** @@ -74,7 +74,7 @@ class ImageRepo } // Filter by page access - $imageQuery = $this->restrictionService->filterRelatedEntity(Page::class, $imageQuery, 'images', 'uploaded_to'); + $imageQuery = $this->permissions->filterRelatedEntity(Page::class, $imageQuery, 'images', 'uploaded_to'); if ($whereClause !== null) { $imageQuery = $imageQuery->where($whereClause); diff --git a/app/helpers.php b/app/helpers.php index 9edc22c40..cfdf55445 100644 --- a/app/helpers.php +++ b/app/helpers.php @@ -1,6 +1,6 @@ checkOwnableUserAccess($ownable, $permission); + return $permissions->checkOwnableUserAccess($ownable, $permission); } /** @@ -76,9 +76,9 @@ function userCan(string $permission, Model $ownable = null): bool */ function userCanOnAny(string $permission, string $entityClass = null): bool { - $permissionService = app(PermissionService::class); + $permissions = app(PermissionApplicator::class); - return $permissionService->checkUserHasPermissionOnAnything($permission, $entityClass); + return $permissions->checkUserHasPermissionOnAnything($permission, $entityClass); } /** diff --git a/database/seeders/DummyContentSeeder.php b/database/seeders/DummyContentSeeder.php index cb9987df7..e97069e7f 100644 --- a/database/seeders/DummyContentSeeder.php +++ b/database/seeders/DummyContentSeeder.php @@ -69,7 +69,7 @@ class DummyContentSeeder extends Seeder ]); $token->save(); - app(JointPermissionBuilder::class)->buildJointPermissions(); + app(JointPermissionBuilder::class)->rebuildForAll(); app(SearchIndex::class)->indexAllEntities(); } } diff --git a/database/seeders/LargeContentSeeder.php b/database/seeders/LargeContentSeeder.php index 041b3161a..b2d8a4d1b 100644 --- a/database/seeders/LargeContentSeeder.php +++ b/database/seeders/LargeContentSeeder.php @@ -35,7 +35,7 @@ class LargeContentSeeder extends Seeder $largeBook->chapters()->saveMany($chapters); $all = array_merge([$largeBook], array_values($pages->all()), array_values($chapters->all())); - app()->make(JointPermissionBuilder::class)->buildJointPermissionsForEntity($largeBook); + app()->make(JointPermissionBuilder::class)->rebuildForEntity($largeBook); app()->make(SearchIndex::class)->indexEntities($all); } } diff --git a/tests/Commands/RegeneratePermissionsCommandTest.php b/tests/Commands/RegeneratePermissionsCommandTest.php index 2090c991b..d514e5f9d 100644 --- a/tests/Commands/RegeneratePermissionsCommandTest.php +++ b/tests/Commands/RegeneratePermissionsCommandTest.php @@ -4,6 +4,7 @@ namespace Tests\Commands; use BookStack\Auth\Permissions\JointPermission; use BookStack\Entities\Models\Page; +use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\DB; use Tests\TestCase; @@ -11,13 +12,13 @@ class RegeneratePermissionsCommandTest extends TestCase { public function test_regen_permissions_command() { - \DB::rollBack(); + DB::rollBack(); JointPermission::query()->truncate(); $page = Page::first(); $this->assertDatabaseMissing('joint_permissions', ['entity_id' => $page->id]); - $exitCode = \Artisan::call('bookstack:regenerate-permissions'); + $exitCode = Artisan::call('bookstack:regenerate-permissions'); $this->assertTrue($exitCode === 0, 'Command executed successfully'); DB::beginTransaction(); diff --git a/tests/PublicActionTest.php b/tests/PublicActionTest.php index 745fa7660..2841f4ef4 100644 --- a/tests/PublicActionTest.php +++ b/tests/PublicActionTest.php @@ -89,7 +89,7 @@ class PublicActionTest extends TestCase foreach (RolePermission::all() as $perm) { $publicRole->attachPermission($perm); } - $this->app->make(JointPermissionBuilder::class)->buildJointPermissionForRole($publicRole); + $this->app->make(JointPermissionBuilder::class)->rebuildForRole($publicRole); /** @var Chapter $chapter */ $chapter = Chapter::query()->first(); diff --git a/tests/SharedTestHelpers.php b/tests/SharedTestHelpers.php index 2d05b0520..99bc92494 100644 --- a/tests/SharedTestHelpers.php +++ b/tests/SharedTestHelpers.php @@ -3,7 +3,7 @@ namespace Tests; use BookStack\Auth\Permissions\JointPermissionBuilder; -use BookStack\Auth\Permissions\PermissionService; +use BookStack\Auth\Permissions\PermissionApplicator; use BookStack\Auth\Permissions\PermissionsRepo; use BookStack\Auth\Permissions\RolePermission; use BookStack\Auth\Role; @@ -177,7 +177,7 @@ trait SharedTestHelpers $entity->save(); $entity->load('permissions'); - $this->app->make(JointPermissionBuilder::class)->buildJointPermissionsForEntity($entity); + $this->app->make(JointPermissionBuilder::class)->rebuildForEntity($entity); $entity->load('jointPermissions'); } @@ -209,7 +209,7 @@ trait SharedTestHelpers /** @var Role $role */ foreach ($roles as $role) { $role->detachPermission($permission); - $permissionBuilder->buildJointPermissionForRole($role); + $permissionBuilder->rebuildForRole($role); } $user->clearPermissionCache(); @@ -243,7 +243,7 @@ trait SharedTestHelpers $chapter = Chapter::factory()->create(array_merge(['book_id' => $book->id], $userAttrs)); $page = Page::factory()->create(array_merge(['book_id' => $book->id, 'chapter_id' => $chapter->id], $userAttrs)); - $this->app->make(JointPermissionBuilder::class)->buildJointPermissionsForEntity($book); + $this->app->make(JointPermissionBuilder::class)->rebuildForEntity($book); return compact('book', 'chapter', 'page'); }