namespace Tests\Helpers;
-use BookStack\Auth\Role;
use BookStack\Auth\User;
use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Bookshelf;
return $pageRepo->publishDraft($draftPage, $input);
}
- /**
- * Regenerate the permission for an entity.
- * Centralised to manage clearing of cached elements between requests.
- */
- public function regenPermissions(Entity $entity): void
- {
- $entity->rebuildPermissions();
- $entity->load('jointPermissions');
- }
-
- /**
- * Set the given entity as having restricted permissions, and apply the given
- * permissions for the given roles.
- * @param string[] $actions
- * @param Role[] $roles
- */
- public function setPermissions(Entity $entity, array $actions = [], array $roles = []): void
- {
- $entity->restricted = true;
- $entity->permissions()->delete();
-
- $permissions = [];
- foreach ($actions as $action) {
- foreach ($roles as $role) {
- $permissions[] = [
- 'role_id' => $role->id,
- 'action' => strtolower($action),
- ];
- }
- }
-
- $entity->permissions()->createMany($permissions);
- $entity->save();
- $entity->load('permissions');
- $this->regenPermissions($entity);
- }
-
/**
* @param Entity|Entity[] $entities
*/