]> BookStack Code Mirror - bookstack/commitdiff
Removed some unused parameters and fixed env test logic
authorDan Brown <redacted>
Fri, 20 Sep 2019 00:18:59 +0000 (01:18 +0100)
committerDan Brown <redacted>
Fri, 20 Sep 2019 00:18:59 +0000 (01:18 +0100)
app/Auth/Permissions/PermissionService.php
app/Entities/Repos/EntityRepo.php
app/Http/Controllers/BookController.php
app/Http/Controllers/BookshelfController.php
app/Http/Controllers/ChapterController.php
tests/SharedTestHelpers.php
tests/Unit/ConfigTest.php

index b4ea17cec534667a19f3d9a1e0cde5c36ea43140..9e1876c90047f9414b1cacd3505aa3fab74af777 100644 (file)
@@ -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);
                     });
-                }
             });
         }
 
index c5fb3501e79fe6b2b265f756b816e3585521cb89..13a335ea01d4c6beb75ac1f12a779a898972e363 100644 (file)
@@ -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;
index b2fb1dcba56d38ceb4e388e0107e2b11ab7f4cf0..a9a24d2ff519a56a888e66450ba8a5e4c4e9b555 100644 (file)
@@ -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);
index b5565eb5705b0c9a7ea44875153a08ee467ad37f..bef96dd01a6e41c62ec67e97d04437baf760ced4 100644 (file)
@@ -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');
index 7b1fb300c5e8c3fb8543e441891d7fa845d3c99b..f728d13137e4505acd1e70b97a5fd73f23011932 100644 (file)
@@ -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());
     }
index 2bff2722321d5a91eb48053e506168d79db1c33a..358bf6ee3b189687dbb4e6bd6e236d1ab5424ee5 100644 (file)
@@ -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;
         }
     }
 
index 7b9f64e6a7fa3062c5c7ad80ac6b61c98a9c3eae..c84305ad88112354a418f6e9c01a58cded82b9eb 100644 (file)
@@ -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');