]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/ChapterController.php
Added OIDC group sync functionality
[bookstack] / app / Http / Controllers / ChapterController.php
index 16f0779cafe7184f4bcd2a58cae72c36fc6cab8f..60eb523800fc369edb694db27e0bcdb065825e15 100644 (file)
@@ -7,10 +7,12 @@ use BookStack\Entities\Models\Book;
 use BookStack\Entities\Repos\ChapterRepo;
 use BookStack\Entities\Tools\BookContents;
 use BookStack\Entities\Tools\Cloner;
+use BookStack\Entities\Tools\HierarchyTransformer;
 use BookStack\Entities\Tools\NextPreviousContentLocator;
 use BookStack\Entities\Tools\PermissionsUpdater;
 use BookStack\Exceptions\MoveOperationException;
 use BookStack\Exceptions\NotFoundException;
+use BookStack\Exceptions\PermissionsException;
 use Illuminate\Http\Request;
 use Illuminate\Validation\ValidationException;
 use Throwable;
@@ -180,6 +182,8 @@ class ChapterController extends Controller
 
         try {
             $newBook = $this->chapterRepo->move($chapter, $entitySelection);
+        } catch (PermissionsException $exception) {
+            $this->showPermissionError();
         } catch (MoveOperationException $exception) {
             $this->showErrorNotification(trans('errors.selected_book_not_found'));
 
@@ -204,7 +208,7 @@ class ChapterController extends Controller
         session()->flashInput(['name' => $chapter->name]);
 
         return view('chapters.copy', [
-            'book' => $chapter->book,
+            'book'    => $chapter->book,
             'chapter' => $chapter,
         ]);
     }
@@ -225,6 +229,7 @@ class ChapterController extends Controller
 
         if (is_null($newParentBook)) {
             $this->showErrorNotification(trans('errors.selected_book_not_found'));
+
             return redirect()->back();
         }
 
@@ -268,4 +273,19 @@ class ChapterController extends Controller
 
         return redirect($chapter->getUrl());
     }
+
+    /**
+     * Convert the chapter to a book.
+     */
+    public function convertToBook(HierarchyTransformer $transformer, string $bookSlug, string $chapterSlug)
+    {
+        $chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug);
+        $this->checkOwnablePermission('chapter-update', $chapter);
+        $this->checkOwnablePermission('chapter-delete', $chapter);
+        $this->checkPermission('book-create-all');
+
+        $book = $transformer->transformChapterToBook($chapter);
+
+        return redirect($book->getUrl());
+    }
 }