Made fixes/updates during pre-release review

- Fixed page editor default focus not working as expected due to
  misnamed attribute.
- Added owned_by to relevant areas of the API including the docs.
- Made book relation on page accessible even if deleted since it could cause an issue on views, such as audit trail, when the relation is accessed when the book is deleted.
This commit is contained in:
Dan Brown 2021-01-03 22:29:58 +00:00
parent 8bb6394b47
commit 14ea6c9de3
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
27 changed files with 71 additions and 18 deletions

View File

@ -31,11 +31,10 @@ abstract class BookChild extends Entity
/** /**
* Get the book this page sits in. * Get the book this page sits in.
* @return BelongsTo
*/ */
public function book(): BelongsTo public function book(): BelongsTo
{ {
return $this->belongsTo(Book::class); return $this->belongsTo(Book::class)->withTrashed();
} }
/** /**

View File

@ -121,7 +121,7 @@ class Page extends BookChild
*/ */
public function forJsonDisplay(): Page public function forJsonDisplay(): Page
{ {
$refreshed = $this->refresh()->unsetRelations()->load(['tags', 'createdBy', 'updatedBy']); $refreshed = $this->refresh()->unsetRelations()->load(['tags', 'createdBy', 'updatedBy', 'ownedBy']);
$refreshed->setHidden(array_diff($refreshed->getHidden(), ['html', 'markdown'])); $refreshed->setHidden(array_diff($refreshed->getHidden(), ['html', 'markdown']));
$refreshed->html = (new PageContent($refreshed))->render(); $refreshed->html = (new PageContent($refreshed))->render();
return $refreshed; return $refreshed;

View File

@ -37,7 +37,7 @@ class BookApiController extends ApiController
{ {
$books = Book::visible(); $books = Book::visible();
return $this->apiListingResponse($books, [ return $this->apiListingResponse($books, [
'id', 'name', 'slug', 'description', 'created_at', 'updated_at', 'created_by', 'updated_by', 'image_id', 'id', 'name', 'slug', 'description', 'created_at', 'updated_at', 'created_by', 'updated_by', 'owned_by', 'image_id',
]); ]);
} }
@ -59,7 +59,7 @@ class BookApiController extends ApiController
*/ */
public function read(string $id) public function read(string $id)
{ {
$book = Book::visible()->with(['tags', 'cover', 'createdBy', 'updatedBy'])->findOrFail($id); $book = Book::visible()->with(['tags', 'cover', 'createdBy', 'updatedBy', 'ownedBy'])->findOrFail($id);
return response()->json($book); return response()->json($book);
} }

View File

@ -43,7 +43,7 @@ class BookshelfApiController extends ApiController
{ {
$shelves = Bookshelf::visible(); $shelves = Bookshelf::visible();
return $this->apiListingResponse($shelves, [ return $this->apiListingResponse($shelves, [
'id', 'name', 'slug', 'description', 'created_at', 'updated_at', 'created_by', 'updated_by', 'image_id', 'id', 'name', 'slug', 'description', 'created_at', 'updated_at', 'created_by', 'updated_by', 'owned_by', 'image_id',
]); ]);
} }
@ -70,7 +70,7 @@ class BookshelfApiController extends ApiController
public function read(string $id) public function read(string $id)
{ {
$shelf = Bookshelf::visible()->with([ $shelf = Bookshelf::visible()->with([
'tags', 'cover', 'createdBy', 'updatedBy', 'tags', 'cover', 'createdBy', 'updatedBy', 'ownedBy',
'books' => function (BelongsToMany $query) { 'books' => function (BelongsToMany $query) {
$query->visible()->get(['id', 'name', 'slug']); $query->visible()->get(['id', 'name', 'slug']);
} }

View File

@ -43,7 +43,7 @@ class ChapterApiController extends ApiController
$chapters = Chapter::visible(); $chapters = Chapter::visible();
return $this->apiListingResponse($chapters, [ return $this->apiListingResponse($chapters, [
'id', 'book_id', 'name', 'slug', 'description', 'priority', 'id', 'book_id', 'name', 'slug', 'description', 'priority',
'created_at', 'updated_at', 'created_by', 'updated_by', 'created_at', 'updated_at', 'created_by', 'updated_by', 'owned_by',
]); ]);
} }
@ -67,7 +67,7 @@ class ChapterApiController extends ApiController
*/ */
public function read(string $id) public function read(string $id)
{ {
$chapter = Chapter::visible()->with(['tags', 'createdBy', 'updatedBy', 'pages' => function (HasMany $query) { $chapter = Chapter::visible()->with(['tags', 'createdBy', 'updatedBy', 'ownedBy', 'pages' => function (HasMany $query) {
$query->visible()->get(['id', 'name', 'slug']); $query->visible()->get(['id', 'name', 'slug']);
}])->findOrFail($id); }])->findOrFail($id);
return response()->json($chapter); return response()->json($chapter);

View File

@ -47,7 +47,8 @@ class PageApiController extends ApiController
return $this->apiListingResponse($pages, [ return $this->apiListingResponse($pages, [
'id', 'book_id', 'chapter_id', 'name', 'slug', 'priority', 'id', 'book_id', 'chapter_id', 'name', 'slug', 'priority',
'draft', 'template', 'draft', 'template',
'created_at', 'updated_at', 'created_by', 'updated_by', 'created_at', 'updated_at',
'created_by', 'updated_by', 'owned_by',
]); ]);
} }

View File

@ -3,6 +3,7 @@
"description": "This is a book created via the API", "description": "This is a book created via the API",
"created_by": 1, "created_by": 1,
"updated_by": 1, "updated_by": 1,
"owned_by": 1,
"slug": "my-new-book", "slug": "my-new-book",
"updated_at": "2020-01-12 14:05:11", "updated_at": "2020-01-12 14:05:11",
"created_at": "2020-01-12 14:05:11", "created_at": "2020-01-12 14:05:11",

View File

@ -9,6 +9,7 @@
"updated_at": "2019-12-11 20:57:31", "updated_at": "2019-12-11 20:57:31",
"created_by": 1, "created_by": 1,
"updated_by": 1, "updated_by": 1,
"owned_by": 1,
"image_id": 3 "image_id": 3
}, },
{ {
@ -20,6 +21,7 @@
"updated_at": "2019-12-11 20:57:23", "updated_at": "2019-12-11 20:57:23",
"created_by": 4, "created_by": 4,
"updated_by": 3, "updated_by": 3,
"owned_by": 3,
"image_id": 34 "image_id": 34
} }
], ],

View File

@ -13,6 +13,10 @@
"id": 1, "id": 1,
"name": "Admin" "name": "Admin"
}, },
"owned_by": {
"id": 1,
"name": "Admin"
},
"tags": [ "tags": [
{ {
"id": 13, "id": 13,

View File

@ -7,5 +7,6 @@
"updated_at": "2020-01-12 14:16:10", "updated_at": "2020-01-12 14:16:10",
"created_by": 1, "created_by": 1,
"updated_by": 1, "updated_by": 1,
"owned_by": 1,
"image_id": 452 "image_id": 452
} }

View File

@ -5,6 +5,7 @@
"description": "This is a great new chapter that I've created via the API", "description": "This is a great new chapter that I've created via the API",
"created_by": 1, "created_by": 1,
"updated_by": 1, "updated_by": 1,
"owned_by": 1,
"slug": "my-fantastic-new-chapter", "slug": "my-fantastic-new-chapter",
"updated_at": "2020-05-22 22:59:55", "updated_at": "2020-05-22 22:59:55",
"created_at": "2020-05-22 22:59:55", "created_at": "2020-05-22 22:59:55",

View File

@ -10,7 +10,8 @@
"created_at": "2019-05-05 21:49:56", "created_at": "2019-05-05 21:49:56",
"updated_at": "2019-09-28 11:24:23", "updated_at": "2019-09-28 11:24:23",
"created_by": 1, "created_by": 1,
"updated_by": 1 "updated_by": 1,
"owned_by": 1
}, },
{ {
"id": 2, "id": 2,
@ -22,7 +23,8 @@
"created_at": "2019-05-05 21:58:07", "created_at": "2019-05-05 21:58:07",
"updated_at": "2019-10-17 15:05:34", "updated_at": "2019-10-17 15:05:34",
"created_by": 3, "created_by": 3,
"updated_by": 3 "updated_by": 3,
"owned_by": 3
} }
], ],
"total": 40 "total": 40

View File

@ -15,6 +15,10 @@
"id": 1, "id": 1,
"name": "Admin" "name": "Admin"
}, },
"owned_by": {
"id": 1,
"name": "Admin"
},
"tags": [ "tags": [
{ {
"name": "Category", "name": "Category",

View File

@ -9,6 +9,7 @@
"updated_at": "2020-05-22 23:07:20", "updated_at": "2020-05-22 23:07:20",
"created_by": 1, "created_by": 1,
"updated_by": 1, "updated_by": 1,
"owned_by": 1,
"book": { "book": {
"id": 1, "id": 1,
"name": "BookStack User Guide", "name": "BookStack User Guide",

View File

@ -16,6 +16,10 @@
"id": 1, "id": 1,
"name": "Admin" "name": "Admin"
}, },
"owned_by": {
"id": 1,
"name": "Admin"
},
"draft": false, "draft": false,
"markdown": "", "markdown": "",
"revision_count": 1, "revision_count": 1,

View File

@ -12,7 +12,8 @@
"created_at": "2019-05-05 21:49:58", "created_at": "2019-05-05 21:49:58",
"updated_at": "2020-07-04 15:50:58", "updated_at": "2020-07-04 15:50:58",
"created_by": 1, "created_by": 1,
"updated_by": 1 "updated_by": 1,
"owned_by": 1
}, },
{ {
"id": 2, "id": 2,
@ -26,7 +27,8 @@
"created_at": "2019-05-05 21:53:30", "created_at": "2019-05-05 21:53:30",
"updated_at": "2019-06-06 12:03:04", "updated_at": "2019-06-06 12:03:04",
"created_by": 1, "created_by": 1,
"updated_by": 1 "updated_by": 1,
"owned_by": 1
}, },
{ {
"id": 3, "id": 3,
@ -40,7 +42,8 @@
"created_at": "2019-05-05 21:53:49", "created_at": "2019-05-05 21:53:49",
"updated_at": "2019-12-18 21:56:52", "updated_at": "2019-12-18 21:56:52",
"created_by": 1, "created_by": 1,
"updated_by": 1 "updated_by": 1,
"owned_by": 1
} }
], ],
"total": 322 "total": 322

View File

@ -16,6 +16,10 @@
"id": 1, "id": 1,
"name": "Admin" "name": "Admin"
}, },
"owned_by": {
"id": 1,
"name": "Admin"
},
"draft": false, "draft": false,
"markdown": "# How this is built\r\n\r\nThis page is written in markdown. BookStack stores the page data in HTML.\r\n\r\nHere's a cute picture of my cat:\r\n\r\n[![yXSrubes.jpg](http://example.com/uploads/images/gallery/2020-04/scaled-1680-/yXSrubes.jpg)](http://example.com/uploads/images/gallery/2020-04/yXSrubes.jpg)", "markdown": "# How this is built\r\n\r\nThis page is written in markdown. BookStack stores the page data in HTML.\r\n\r\nHere's a cute picture of my cat:\r\n\r\n[![yXSrubes.jpg](http://example.com/uploads/images/gallery/2020-04/scaled-1680-/yXSrubes.jpg)](http://example.com/uploads/images/gallery/2020-04/yXSrubes.jpg)",
"revision_count": 5, "revision_count": 5,

View File

@ -16,6 +16,10 @@
"id": 1, "id": 1,
"name": "Admin" "name": "Admin"
}, },
"owned_by": {
"id": 1,
"name": "Admin"
},
"draft": false, "draft": false,
"markdown": "", "markdown": "",
"revision_count": 5, "revision_count": 5,

View File

@ -3,6 +3,7 @@
"description": "This is my shelf with some books", "description": "This is my shelf with some books",
"created_by": 1, "created_by": 1,
"updated_by": 1, "updated_by": 1,
"owned_by": 1,
"slug": "my-shelf", "slug": "my-shelf",
"updated_at": "2020-04-10 13:24:09", "updated_at": "2020-04-10 13:24:09",
"created_at": "2020-04-10 13:24:09", "created_at": "2020-04-10 13:24:09",

View File

@ -9,6 +9,7 @@
"updated_at": "2020-04-10 13:00:45", "updated_at": "2020-04-10 13:00:45",
"created_by": 4, "created_by": 4,
"updated_by": 1, "updated_by": 1,
"owned_by": 1,
"image_id": 31 "image_id": 31
}, },
{ {
@ -20,6 +21,7 @@
"updated_at": "2020-04-10 13:00:58", "updated_at": "2020-04-10 13:00:58",
"created_by": 4, "created_by": 4,
"updated_by": 1, "updated_by": 1,
"owned_by": 1,
"image_id": 28 "image_id": 28
}, },
{ {
@ -31,6 +33,7 @@
"updated_at": "2020-04-10 13:00:53", "updated_at": "2020-04-10 13:00:53",
"created_by": 4, "created_by": 4,
"updated_by": 1, "updated_by": 1,
"owned_by": 4,
"image_id": 30 "image_id": 30
} }
], ],

View File

@ -11,6 +11,10 @@
"id": 1, "id": 1,
"name": "Admin" "name": "Admin"
}, },
"owned_by": {
"id": 1,
"name": "Admin"
},
"created_at": "2020-04-10 13:24:09", "created_at": "2020-04-10 13:24:09",
"updated_at": "2020-04-10 13:31:04", "updated_at": "2020-04-10 13:31:04",
"tags": [ "tags": [

View File

@ -5,6 +5,7 @@
"description": "This is my update shelf with some books", "description": "This is my update shelf with some books",
"created_by": 1, "created_by": 1,
"updated_by": 1, "updated_by": 1,
"owned_by": 1,
"image_id": 501, "image_id": 501,
"created_at": "2020-04-10 13:24:09", "created_at": "2020-04-10 13:24:09",
"updated_at": "2020-04-10 13:48:22" "updated_at": "2020-04-10 13:48:22"

View File

@ -12,7 +12,7 @@ class PageEditor {
this.editorType = this.$opts.editorType; this.editorType = this.$opts.editorType;
this.pageId = Number(this.$opts.pageId); this.pageId = Number(this.$opts.pageId);
this.isNewDraft = this.$opts.pageNewDraft === 'true'; this.isNewDraft = this.$opts.pageNewDraft === 'true';
this.hasDefaultTitle = this.$opts.isDefaultTitle || false; this.hasDefaultTitle = this.$opts.hasDefaultTitle || false;
// Elements // Elements
this.container = this.$el; this.container = this.$el;
@ -74,6 +74,7 @@ class PageEditor {
} }
setInitialFocus() { setInitialFocus() {
console.log({'HAS': this.hasDefaultTitle});
if (this.hasDefaultTitle) { if (this.hasDefaultTitle) {
return this.titleElem.select(); return this.titleElem.select();
} }

View File

@ -75,7 +75,10 @@ class BooksApiTest extends TestCase
], ],
'updated_by' => [ 'updated_by' => [
'name' => $book->createdBy->name, 'name' => $book->createdBy->name,
] ],
'owned_by' => [
'name' => $book->ownedBy->name
],
]); ]);
} }

View File

@ -106,6 +106,9 @@ class ChaptersApiTest extends TestCase
'updated_by' => [ 'updated_by' => [
'name' => $chapter->createdBy->name, 'name' => $chapter->createdBy->name,
], ],
'owned_by' => [
'name' => $chapter->ownedBy->name
],
'pages' => [ 'pages' => [
[ [
'id' => $page->id, 'id' => $page->id,

View File

@ -136,6 +136,9 @@ class PagesApiTest extends TestCase
'updated_by' => [ 'updated_by' => [
'name' => $page->createdBy->name, 'name' => $page->createdBy->name,
], ],
'owned_by' => [
'name' => $page->ownedBy->name
],
]); ]);
} }

View File

@ -85,7 +85,10 @@ class ShelvesApiTest extends TestCase
], ],
'updated_by' => [ 'updated_by' => [
'name' => $shelf->createdBy->name, 'name' => $shelf->createdBy->name,
] ],
'owned_by' => [
'name' => $shelf->ownedBy->name
],
]); ]);
} }