mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-04-17 00:39:06 +08: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') {
|
||||
// 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);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -478,14 +478,16 @@ class EntityRepo
|
||||
$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();
|
||||
@ -525,10 +527,9 @@ class EntityRepo
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
@ -199,7 +199,7 @@ class BookController extends Controller
|
||||
'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);
|
||||
|
@ -177,7 +177,7 @@ class BookshelfController extends Controller
|
||||
'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');
|
||||
|
@ -3,7 +3,6 @@
|
||||
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;
|
||||
@ -113,7 +112,7 @@ class ChapterController extends Controller
|
||||
$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());
|
||||
}
|
||||
|
@ -215,13 +215,11 @@ trait SharedTestHelpers
|
||||
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;
|
||||
}
|
||||
|
||||
@ -230,10 +228,8 @@ trait SharedTestHelpers
|
||||
|
||||
if (is_null($originalVal)) {
|
||||
unset($_SERVER[$name]);
|
||||
unset($_ENV[$name]);
|
||||
} else {
|
||||
$_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()
|
||||
{
|
||||
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');
|
||||
|
Loading…
x
Reference in New Issue
Block a user