]> BookStack Code Mirror - bookstack/commitdiff
Adds test cases and fixes an issue with the permission checking. 635/head
authorAbijeet <redacted>
Tue, 26 Dec 2017 10:16:20 +0000 (15:46 +0530)
committerAbijeet <redacted>
Tue, 26 Dec 2017 10:16:20 +0000 (15:46 +0530)
Signed-off-by: Abijeet <redacted>
app/Http/Controllers/UserController.php
tests/Entity/EntityTest.php
tests/UserProfileTest.php

index 5c10133a2cbe1aa6c4a2cf3e6cfd86777bfb0c01..397bb2922b6f558a5a2ede8e12c3f6275ccdc1bc 100644 (file)
@@ -251,7 +251,9 @@ class UserController extends Controller
     }
 
     public function switchBookView($id, Request $request) {
-        $this->checkPermission('users-manage');
+        $this->checkPermissionOr('users-manage', function () use ($id) {
+            return $this->currentUser->id == $id;
+        });
         $viewType = $request->get('book_view_type');
 
         if (!in_array($viewType, ['grid', 'list'])) {
index a43f65b5efd568c58d1ce6a8e9c9343276d1be07..5492534177b9795eb36532c038aaa81e2ca2cb2f 100644 (file)
@@ -82,6 +82,27 @@ class EntityTest extends BrowserKitTest
             ->see($firstChapter->name);
     }
 
+    public function test_toggle_book_view()
+    {
+        $editor = $this->getEditor();
+        setting()->putUser($editor, 'books_view_type', 'grid');
+
+        $this->actingAs($editor)
+            ->visit('/books')
+            ->pageHasElement('.featured-image-container')
+            ->submitForm('Toggle Book View')
+            // Check redirection.
+            ->seePageIs('/books')
+            ->pageNotHasElement('.featured-image-container');
+
+        $this->actingAs($editor)
+            ->visit('/books')
+            ->submitForm('Toggle Book View')
+            ->seePageIs('/books')
+            ->pageHasElement('.featured-image-container');
+
+    }
+
     public function pageCreation($chapter)
     {
         $page = factory(Page::class)->make([
@@ -155,7 +176,7 @@ class EntityTest extends BrowserKitTest
             ->type($book->name, '#name')
             ->type($book->description, '#description')
             ->press('Save Book');
-        
+
         $expectedPattern = '/\/books\/my-first-book-[0-9a-zA-Z]{3}/';
         $this->assertRegExp($expectedPattern, $this->currentUri, "Did not land on expected page [$expectedPattern].\n");
 
index 0c66363f0b34a0e8c241108d8675b7a29ca67105..3262117d5009e0bfd5bb8f9aa2b71886fbf4bf6e 100644 (file)
@@ -103,7 +103,7 @@ class UserProfileTest extends BrowserKitTest
         $this->actingAs($editor)
             ->visit('/books')
             ->pageNotHasElement('.featured-image-container')
-            ->pageHasElement('.entity-list-item');
+            ->pageHasElement('.content .entity-list-item');
     }
 
     public function test_books_view_is_grid()