]> BookStack Code Mirror - bookstack/commitdiff
Default chapter templates: Updated api docs and tests
authorDan Brown <redacted>
Thu, 1 Feb 2024 12:22:16 +0000 (12:22 +0000)
committerDan Brown <redacted>
Thu, 1 Feb 2024 12:22:16 +0000 (12:22 +0000)
Also applied minor tweaks to some wording and logic.

During review of #4750

app/Api/ListingResponseBuilder.php
app/Entities/Repos/PageRepo.php
database/migrations/2024_01_01_104542_add_default_template_to_chapters.php
dev/api/requests/chapters-create.json
dev/api/requests/chapters-update.json
dev/api/responses/chapters-create.json
dev/api/responses/chapters-read.json
dev/api/responses/chapters-update.json
lang/en/entities.php
tests/Api/ChaptersApiTest.php

index 44117bad9759e5108502485003c66fd3a599e96f..329f5ce1c58fc54e8f11d279e691f673e89aea89 100644 (file)
@@ -61,6 +61,8 @@ class ListingResponseBuilder
             }
         });
 
+        dd($data->first());
+
         return response()->json([
             'data'  => $data,
             'total' => $total,
index d9bda01989205070e87c23f8596957dad6000bcf..85237a75219f62784160f388fa91601bcaa338db 100644 (file)
@@ -136,13 +136,7 @@ class PageRepo
             $page->book_id = $parent->id;
         }
 
-        // check for chapter
-        if ($page->chapter_id) {
-            $defaultTemplate = $page->chapter->defaultTemplate;
-        } else {
-            $defaultTemplate = $page->book->defaultTemplate;
-        }
-
+        $defaultTemplate = $page->chapter->defaultTemplate ?? $page->book->defaultTemplate;
         if ($defaultTemplate && userCan('view', $defaultTemplate)) {
             $page->forceFill([
                 'html'  => $defaultTemplate->html,
index 5e9ea1de31103a7b2628ef9f8d839441759c33cb..b3a103a0173eedb187442b001d13abba90862421 100644 (file)
@@ -1,32 +1,32 @@
-<?php\r
-\r
-use Illuminate\Database\Migrations\Migration;\r
-use Illuminate\Database\Schema\Blueprint;\r
-use Illuminate\Support\Facades\Schema;\r
-\r
-class AddDefaultTemplateToChapters extends Migration\r
-{\r
-    /**\r
-     * Run the migrations.\r
-     *\r
-     * @return void\r
-     */\r
-    public function up()\r
-    {\r
-        Schema::table('chapters', function (Blueprint $table) {\r
-            $table->integer('default_template_id')->nullable()->default(null);\r
-        });\r
-    }\r
-\r
-    /**\r
-     * Reverse the migrations.\r
-     *\r
-     * @return void\r
-     */\r
-    public function down()\r
-    {\r
-        Schema::table('chapters', function (Blueprint $table) {\r
-            $table->dropColumn('default_template_id');\r
-        });\r
-    }\r
-}\r
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddDefaultTemplateToChapters extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('chapters', function (Blueprint $table) {
+            $table->integer('default_template_id')->nullable()->default(null);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('chapters', function (Blueprint $table) {
+            $table->dropColumn('default_template_id');
+        });
+    }
+}
index e9d9033874e91ae33feac193fad1ed8025d128bb..02aee9eeabf3687b6f16ce8c1506c8184b32cbc5 100644 (file)
@@ -3,6 +3,7 @@
   "name": "My fantastic new chapter",
   "description_html": "<p>This is a <strong>great new chapter</strong> that I've created via the API</p>",
   "priority": 15,
+  "default_template_id": 25,
   "tags": [
     {"name": "Category", "value": "Top Content"},
     {"name": "Rating", "value": "Highest"}
index be675772bc6d26ac5a1dfc055cd10d98d414b358..cf9c89eacdcf2da6c698192c0a54fcc06b8a55a6 100644 (file)
@@ -3,6 +3,7 @@
   "name": "My fantastic updated chapter",
   "description_html": "<p>This is an <strong>updated chapter</strong> that I've altered via the API</p>",
   "priority": 16,
+  "default_template_id": 2428,
   "tags": [
     {"name": "Category", "value": "Kinda Good Content"},
     {"name": "Rating", "value": "Medium"}
index 183186b0b4295d1a895254a11cb097dd7c082cd4..1e81a1e6363fc575770836aba0261f5ef3b48fed 100644 (file)
@@ -11,6 +11,7 @@
   "updated_by": 1,
   "owned_by": 1,
   "description_html": "<p>This is a <strong>great new chapter<\/strong> that I've created via the API<\/p>",
+  "default_template_id": 25,
   "tags": [
     {
       "name": "Category",
index 192ffce7cd25cbe16f1a0488d7554431551065fe..01a2f4b9f9811825b0f2e808cc8ec97cb154ace2 100644 (file)
@@ -5,6 +5,7 @@
   "name": "Content Creation",
   "description": "How to create documentation on whatever subject you need to write about.",
   "description_html": "<p>How to create <strong>documentation</strong> on whatever subject you need to write about.</p>",
+  "default_template_id": 25,
   "priority": 3,
   "created_at": "2019-05-05T21:49:56.000000Z",
   "updated_at": "2019-09-28T11:24:23.000000Z",
index 5ac3c64c12fdfa0684b0e9046c93dc483215725c..4d8d0024e6ae5bce265adedf3c48fedd03a43a3a 100644 (file)
@@ -11,6 +11,7 @@
   "updated_by": 1,
   "owned_by": 1,
   "description_html": "<p>This is an <strong>updated chapter<\/strong> that I've altered via the API<\/p>",
+  "default_template_id": 2428,
   "tags": [
     {
       "name": "Category",
index 8860e243e775b33513c915ebafe6742a900abbb7..9e620b24ed1dfcde5d5283b659d78b3fc63e5c10 100644 (file)
@@ -40,7 +40,7 @@ return [
     'export_text' => 'Plain Text File',
     'export_md' => 'Markdown File',
     'default_template' => 'Default Page Template',
-    'default_template_explain' => 'Assign a page template that will be used as the default content for all new pages in this book/chapter. Keep in mind this will only be used if the page creator has view access to those chosen template page.',
+    'default_template_explain' => 'Assign a page template that will be used as the default content for all pages created within this item. Keep in mind this will only be used if the page creator has view access to the chosen template page.',
     'default_template_select' => 'Select a template page',
 
     // Permissions and restrictions
index 81a91887794f693acaa5d6df28df9dfca259b716..fdb80a4973eb761dfbb65437337314da4628ccb3 100644 (file)
@@ -35,6 +35,7 @@ class ChaptersApiTest extends TestCase
     {
         $this->actingAsApiEditor();
         $book = $this->entities->book();
+        $templatePage = $this->entities->templatePage();
         $details = [
             'name'        => 'My API chapter',
             'description' => 'A chapter created via the API',
@@ -46,6 +47,7 @@ class ChaptersApiTest extends TestCase
                 ],
             ],
             'priority' => 15,
+            'default_template_id' => $templatePage->id,
         ];
 
         $resp = $this->postJson($this->baseEndpoint, $details);
@@ -147,6 +149,7 @@ class ChaptersApiTest extends TestCase
                     'name' => $page->name,
                 ],
             ],
+            'default_template_id' => null,
         ]);
         $resp->assertJsonCount($chapter->pages()->count(), 'pages');
     }
@@ -155,6 +158,7 @@ class ChaptersApiTest extends TestCase
     {
         $this->actingAsApiEditor();
         $chapter = $this->entities->chapter();
+        $templatePage = $this->entities->templatePage();
         $details = [
             'name'        => 'My updated API chapter',
             'description' => 'A chapter updated via the API',
@@ -165,6 +169,7 @@ class ChaptersApiTest extends TestCase
                 ],
             ],
             'priority'    => 15,
+            'default_template_id' => $templatePage->id,
         ];
 
         $resp = $this->putJson($this->baseEndpoint . "/{$chapter->id}", $details);