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

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

@ -121,7 +121,7 @@ class Page extends BookChild
*/
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->html = (new PageContent($refreshed))->render();
return $refreshed;

@ -37,7 +37,7 @@ class BookApiController extends ApiController
{
$books = Book::visible();
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)
{
$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);
}

@ -43,7 +43,7 @@ class BookshelfApiController extends ApiController
{
$shelves = Bookshelf::visible();
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)
{
$shelf = Bookshelf::visible()->with([
'tags', 'cover', 'createdBy', 'updatedBy',
'tags', 'cover', 'createdBy', 'updatedBy', 'ownedBy',
'books' => function (BelongsToMany $query) {
$query->visible()->get(['id', 'name', 'slug']);
}

@ -43,7 +43,7 @@ class ChapterApiController extends ApiController
$chapters = Chapter::visible();
return $this->apiListingResponse($chapters, [
'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)
{
$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']);
}])->findOrFail($id);
return response()->json($chapter);

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

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

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

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

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

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

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

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

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

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

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

@ -16,6 +16,10 @@
"id": 1,
"name": "Admin"
},
"owned_by": {
"id": 1,
"name": "Admin"
},
"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)",
"revision_count": 5,

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

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

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

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

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

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

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

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

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

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