]> BookStack Code Mirror - bookstack/commitdiff
Added 'Sort Book' action to chapters 3598/head
authorDan Brown <redacted>
Tue, 26 Jul 2022 11:35:50 +0000 (12:35 +0100)
committerDan Brown <redacted>
Tue, 26 Jul 2022 11:36:17 +0000 (12:36 +0100)
Related to #2335

resources/lang/en/entities.php
resources/views/chapters/show.blade.php
tests/Entity/ChapterTest.php

index 83e3c12d92707fca87bf798414a5b7205199b062..db1e8027b0bcbbad46eae95c540ebe8dd55cb3bc 100644 (file)
@@ -171,6 +171,7 @@ return [
     'chapters_permissions_active' => 'Chapter Permissions Active',
     'chapters_permissions_success' => 'Chapter Permissions Updated',
     'chapters_search_this' => 'Search this chapter',
+    'chapter_sort_book' => 'Sort Book',
 
     // Pages
     'page' => 'Page',
index a7b90ceef5e33567cda5b068c7c8030ea180ba9d..1ae2d68471211b33e494882fc74769dd69f58de0 100644 (file)
                 </a>
             @endif
 
+            @if($chapter->book && userCan('book-update', $chapter->book))
+                <hr class="primary-background"/>
+                <a href="{{ $chapter->book->getUrl('/sort') }}" class="icon-list-item">
+                    <span>@icon('sort')</span>
+                    <span>{{ trans('entities.chapter_sort_book') }}</span>
+                </a>
+            @endif
+
             <hr class="primary-background"/>
 
             @if(signedInUser())
index 5a761b94fdb67b5e1fb2f684e57b88aca761b140..d58b83da9cd66a73b50d403c19cc78dc5cc61817 100644 (file)
@@ -146,4 +146,16 @@ class ChapterTest extends TestCase
         $newChapter2 = Chapter::query()->where('name', '=', 'My copied again chapter')->first();
         $this->assertEquals($chapter->pages()->count(), $newChapter2->pages()->count());
     }
+
+    public function test_sort_book_action_visible_if_permissions_allow()
+    {
+        /** @var Chapter $chapter */
+        $chapter = Chapter::query()->first();
+
+        $resp = $this->actingAs($this->getViewer())->get($chapter->getUrl());
+        $this->withHtml($resp)->assertLinkNotExists($chapter->book->getUrl('sort'));
+
+        $resp = $this->asEditor()->get($chapter->getUrl());
+        $this->withHtml($resp)->assertLinkExists($chapter->book->getUrl('sort'));
+    }
 }