if (strtolower($entityType) === 'page') {
// Prevent drafts being visible to others.
$query = $query->where(function ($query) {
- $query->where('draft', '=', false);
- if ($this->currentUser()) {
- $query->orWhere(function ($query) {
- $query->where('draft', '=', true)->where('created_by', '=', $this->currentUser()->id);
+ $query->where('draft', '=', false)
+ ->orWhere(function ($query) {
+ $query->where('draft', '=', true)
+ ->where('created_by', '=', $this->currentUser()->id);
});
- }
});
}
$entity->permissions()->delete();
if ($request->filled('restrictions')) {
- foreach ($request->get('restrictions') as $roleId => $restrictions) {
- foreach ($restrictions as $action => $value) {
- $entity->permissions()->create([
+ $entityPermissionData = collect($request->get('restrictions'))->flatMap(function($restrictions, $roleId) {
+ return collect($restrictions)->keys()->map(function($action) use ($roleId) {
+ return [
'role_id' => $roleId,
- 'action' => strtolower($action),
- ]);
- }
- }
+ 'action' => strtolower($action),
+ ] ;
+ });
+ });
+
+ $entity->permissions()->createMany($entityPermissionData);
}
$entity->save();
/**
* Update entity details from request input.
- * Used for books and chapters.
- * TODO: Remove type param
+ * Used for shelves, books and chapters.
*/
- public function updateFromInput(string $type, Entity $entityModel, array $input = []): Entity
+ public function updateFromInput(Entity $entityModel, array $input): Entity
{
$entityModel->fill($input);
$entityModel->updated_by = user()->id;
'image' => $this->imageRepo->getImageValidationRules(),
]);
- $book = $this->bookRepo->updateFromInput('book', $book, $request->all());
+ $book = $this->bookRepo->updateFromInput($book, $request->all());
$this->bookUpdateActions($book, $request);
Activity::add($book, 'book_update', $book->id);
'image' => $this->imageRepo->getImageValidationRules(),
]);
- $shelf = $this->entityRepo->updateFromInput('bookshelf', $shelf, $request->all());
+ $shelf = $this->entityRepo->updateFromInput($shelf, $request->all());
$this->shelfUpdateActions($shelf, $request);
Activity::add($shelf, 'bookshelf_update');
use Activity;
use BookStack\Auth\UserRepo;
use BookStack\Entities\Repos\EntityRepo;
-use BookStack\Entities\ExportService;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Views;
$chapter = $this->entityRepo->getEntityBySlug('chapter', $chapterSlug, $bookSlug);
$this->checkOwnablePermission('chapter-update', $chapter);
- $this->entityRepo->updateFromInput('chapter', $chapter, $request->all());
+ $this->entityRepo->updateFromInput($chapter, $request->all());
Activity::add($chapter, 'chapter_update', $chapter->book->id);
return redirect($chapter->getUrl());
}
protected function runWithEnv(string $name, $value, callable $callback)
{
Env::disablePutenv();
- $originalVal = $_ENV[$name] ?? null;
+ $originalVal = $_SERVER[$name] ?? null;
if (is_null($value)) {
- unset($_ENV[$name]);
unset($_SERVER[$name]);
} else {
- $_ENV[$name] = $value;
$_SERVER[$name] = $value;
}
if (is_null($originalVal)) {
unset($_SERVER[$name]);
- unset($_ENV[$name]);
} else {
$_SERVER[$name] = $originalVal;
- $_ENV[$name] = $originalVal;
}
}
public function test_filesystem_attachments_falls_back_to_storage_type_var()
{
- putenv('STORAGE_TYPE=local_secure');
$this->runWithEnv('STORAGE_TYPE', 'local_secure', function() {
$this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', 's3', 'filesystems.attachments', 's3');
$this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', null, 'filesystems.attachments', 'local_secure');