mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-27 12:41:58 +00:00
Removed some unused parameters and fixed env test logic
This commit is contained in:
parent
8b550991a4
commit
7cd956b24b
@ -683,12 +683,11 @@ class PermissionService
|
|||||||
if (strtolower($entityType) === 'page') {
|
if (strtolower($entityType) === 'page') {
|
||||||
// Prevent drafts being visible to others.
|
// Prevent drafts being visible to others.
|
||||||
$query = $query->where(function ($query) {
|
$query = $query->where(function ($query) {
|
||||||
$query->where('draft', '=', false);
|
$query->where('draft', '=', false)
|
||||||
if ($this->currentUser()) {
|
->orWhere(function ($query) {
|
||||||
$query->orWhere(function ($query) {
|
$query->where('draft', '=', true)
|
||||||
$query->where('draft', '=', true)->where('created_by', '=', $this->currentUser()->id);
|
->where('created_by', '=', $this->currentUser()->id);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -478,14 +478,16 @@ class EntityRepo
|
|||||||
$entity->permissions()->delete();
|
$entity->permissions()->delete();
|
||||||
|
|
||||||
if ($request->filled('restrictions')) {
|
if ($request->filled('restrictions')) {
|
||||||
foreach ($request->get('restrictions') as $roleId => $restrictions) {
|
$entityPermissionData = collect($request->get('restrictions'))->flatMap(function($restrictions, $roleId) {
|
||||||
foreach ($restrictions as $action => $value) {
|
return collect($restrictions)->keys()->map(function($action) use ($roleId) {
|
||||||
$entity->permissions()->create([
|
return [
|
||||||
'role_id' => $roleId,
|
'role_id' => $roleId,
|
||||||
'action' => strtolower($action),
|
'action' => strtolower($action),
|
||||||
]);
|
] ;
|
||||||
}
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
|
$entity->permissions()->createMany($entityPermissionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
$entity->save();
|
$entity->save();
|
||||||
@ -525,10 +527,9 @@ class EntityRepo
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update entity details from request input.
|
* Update entity details from request input.
|
||||||
* Used for books and chapters.
|
* Used for shelves, books and chapters.
|
||||||
* TODO: Remove type param
|
|
||||||
*/
|
*/
|
||||||
public function updateFromInput(string $type, Entity $entityModel, array $input = []): Entity
|
public function updateFromInput(Entity $entityModel, array $input): Entity
|
||||||
{
|
{
|
||||||
$entityModel->fill($input);
|
$entityModel->fill($input);
|
||||||
$entityModel->updated_by = user()->id;
|
$entityModel->updated_by = user()->id;
|
||||||
|
@ -199,7 +199,7 @@ class BookController extends Controller
|
|||||||
'image' => $this->imageRepo->getImageValidationRules(),
|
'image' => $this->imageRepo->getImageValidationRules(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$book = $this->bookRepo->updateFromInput('book', $book, $request->all());
|
$book = $this->bookRepo->updateFromInput($book, $request->all());
|
||||||
$this->bookUpdateActions($book, $request);
|
$this->bookUpdateActions($book, $request);
|
||||||
|
|
||||||
Activity::add($book, 'book_update', $book->id);
|
Activity::add($book, 'book_update', $book->id);
|
||||||
|
@ -177,7 +177,7 @@ class BookshelfController extends Controller
|
|||||||
'image' => $this->imageRepo->getImageValidationRules(),
|
'image' => $this->imageRepo->getImageValidationRules(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$shelf = $this->entityRepo->updateFromInput('bookshelf', $shelf, $request->all());
|
$shelf = $this->entityRepo->updateFromInput($shelf, $request->all());
|
||||||
$this->shelfUpdateActions($shelf, $request);
|
$this->shelfUpdateActions($shelf, $request);
|
||||||
|
|
||||||
Activity::add($shelf, 'bookshelf_update');
|
Activity::add($shelf, 'bookshelf_update');
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
use Activity;
|
use Activity;
|
||||||
use BookStack\Auth\UserRepo;
|
use BookStack\Auth\UserRepo;
|
||||||
use BookStack\Entities\Repos\EntityRepo;
|
use BookStack\Entities\Repos\EntityRepo;
|
||||||
use BookStack\Entities\ExportService;
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
use Views;
|
use Views;
|
||||||
@ -113,7 +112,7 @@ class ChapterController extends Controller
|
|||||||
$chapter = $this->entityRepo->getEntityBySlug('chapter', $chapterSlug, $bookSlug);
|
$chapter = $this->entityRepo->getEntityBySlug('chapter', $chapterSlug, $bookSlug);
|
||||||
$this->checkOwnablePermission('chapter-update', $chapter);
|
$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);
|
Activity::add($chapter, 'chapter_update', $chapter->book->id);
|
||||||
return redirect($chapter->getUrl());
|
return redirect($chapter->getUrl());
|
||||||
}
|
}
|
||||||
|
@ -215,13 +215,11 @@ trait SharedTestHelpers
|
|||||||
protected function runWithEnv(string $name, $value, callable $callback)
|
protected function runWithEnv(string $name, $value, callable $callback)
|
||||||
{
|
{
|
||||||
Env::disablePutenv();
|
Env::disablePutenv();
|
||||||
$originalVal = $_ENV[$name] ?? null;
|
$originalVal = $_SERVER[$name] ?? null;
|
||||||
|
|
||||||
if (is_null($value)) {
|
if (is_null($value)) {
|
||||||
unset($_ENV[$name]);
|
|
||||||
unset($_SERVER[$name]);
|
unset($_SERVER[$name]);
|
||||||
} else {
|
} else {
|
||||||
$_ENV[$name] = $value;
|
|
||||||
$_SERVER[$name] = $value;
|
$_SERVER[$name] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,10 +228,8 @@ trait SharedTestHelpers
|
|||||||
|
|
||||||
if (is_null($originalVal)) {
|
if (is_null($originalVal)) {
|
||||||
unset($_SERVER[$name]);
|
unset($_SERVER[$name]);
|
||||||
unset($_ENV[$name]);
|
|
||||||
} else {
|
} else {
|
||||||
$_SERVER[$name] = $originalVal;
|
$_SERVER[$name] = $originalVal;
|
||||||
$_ENV[$name] = $originalVal;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ class ConfigTest extends TestCase
|
|||||||
|
|
||||||
public function test_filesystem_attachments_falls_back_to_storage_type_var()
|
public function test_filesystem_attachments_falls_back_to_storage_type_var()
|
||||||
{
|
{
|
||||||
putenv('STORAGE_TYPE=local_secure');
|
|
||||||
$this->runWithEnv('STORAGE_TYPE', 'local_secure', function() {
|
$this->runWithEnv('STORAGE_TYPE', 'local_secure', function() {
|
||||||
$this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', 's3', 'filesystems.attachments', 's3');
|
$this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', 's3', 'filesystems.attachments', 's3');
|
||||||
$this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', null, 'filesystems.attachments', 'local_secure');
|
$this->checkEnvConfigResult('STORAGE_ATTACHMENT_TYPE', null, 'filesystems.attachments', 'local_secure');
|
||||||
|
Loading…
Reference in New Issue
Block a user