1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2024-10-30 07:32:39 +01:00

Merge branch 'v0.31.x'

This commit is contained in:
Dan Brown 2021-02-06 14:22:19 +00:00
commit 9a05223e7d
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
6 changed files with 86 additions and 36 deletions

View File

@ -177,17 +177,13 @@ class PageRepo
// Hold the old details to compare later
$oldHtml = $page->html;
$oldName = $page->name;
$oldMarkdown = $page->markdown;
$this->updateTemplateStatusAndContentFromInput($page, $input);
$this->baseRepo->update($page, $input);
// Update with new details
$page->revision_count++;
if (setting('app-editor') !== 'markdown') {
$page->markdown = '';
}
$page->save();
// Remove all update drafts for this user & page.
@ -195,7 +191,10 @@ class PageRepo
// Save a revision after updating
$summary = $input['summary'] ?? null;
if ($oldHtml !== $input['html'] || $oldName !== $input['name'] || $summary !== null) {
$htmlChanged = isset($input['html']) && $input['html'] !== $oldHtml;
$nameChanged = isset($input['name']) && $input['name'] !== $oldName;
$markdownChanged = isset($input['markdown']) && $input['markdown'] !== $oldMarkdown;
if ($htmlChanged || $nameChanged || $markdownChanged || $summary !== null) {
$this->savePageRevision($page, $summary);
}
@ -224,10 +223,6 @@ class PageRepo
{
$revision = new PageRevision($page->getAttributes());
if (setting('app-editor') !== 'markdown') {
$revision->markdown = '';
}
$revision->page_id = $page->id;
$revision->slug = $page->slug;
$revision->book_slug = $page->book->slug;
@ -290,7 +285,13 @@ class PageRepo
$page->fill($revision->toArray());
$content = new PageContent($page);
$content->setNewHTML($revision->html);
if (!empty($revision->markdown)) {
$content->setNewMarkdown($revision->markdown);
} else {
$content->setNewHTML($revision->html);
}
$page->updated_by = user()->id;
$page->refreshSlug();
$page->save();

View File

@ -273,11 +273,11 @@ class TrashCan
$count++;
};
if ($entity->isA('chapter') || $entity->isA('book')) {
if ($entity instanceof Chapter || $entity instanceof Book) {
$entity->pages()->withTrashed()->withCount('deletions')->get()->each($restoreAction);
}
if ($entity->isA('book')) {
if ($entity instanceof Book) {
$entity->chapters()->withTrashed()->withCount('deletions')->get()->each($restoreAction);
}
@ -286,19 +286,20 @@ class TrashCan
/**
* Destroy the given entity.
* @throws Exception
*/
protected function destroyEntity(Entity $entity): int
{
if ($entity->isA('page')) {
if ($entity instanceof Page) {
return $this->destroyPage($entity);
}
if ($entity->isA('chapter')) {
if ($entity instanceof Chapter) {
return $this->destroyChapter($entity);
}
if ($entity->isA('book')) {
if ($entity instanceof Book) {
return $this->destroyBook($entity);
}
if ($entity->isA('bookshelf')) {
if ($entity instanceof Bookshelf) {
return $this->destroyShelf($entity);
}
}

View File

@ -18,7 +18,7 @@
"facade/ignition": "^1.16.4",
"fideloper/proxy": "^4.4.1",
"intervention/image": "^2.5.1",
"laravel/framework": "^6.20.12",
"laravel/framework": "^6.20.16",
"laravel/socialite": "^5.1",
"league/commonmark": "^1.5",
"league/flysystem-aws-s3-v3": "^1.0.29",

36
composer.lock generated
View File

@ -4,20 +4,20 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "df6e5d5d5debaaeab590da55c7d50ec2",
"content-hash": "d73b8bdf23e32f109f052ac18e20458f",
"packages": [
{
"name": "aws/aws-sdk-php",
"version": "3.172.3",
"version": "3.173.0",
"source": {
"type": "git",
"url": "https://github.com/aws/aws-sdk-php.git",
"reference": "14fd73f12fc70d5f48e034f5dfc33136136adb61"
"reference": "ab3ee1cba4219d5262ecac8f011f267e9b7f3af9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/14fd73f12fc70d5f48e034f5dfc33136136adb61",
"reference": "14fd73f12fc70d5f48e034f5dfc33136136adb61",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/ab3ee1cba4219d5262ecac8f011f267e9b7f3af9",
"reference": "ab3ee1cba4219d5262ecac8f011f267e9b7f3af9",
"shasum": ""
},
"require": {
@ -92,9 +92,9 @@
"support": {
"forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
"issues": "https://github.com/aws/aws-sdk-php/issues",
"source": "https://github.com/aws/aws-sdk-php/tree/3.172.3"
"source": "https://github.com/aws/aws-sdk-php/tree/3.173.0"
},
"time": "2021-01-28T19:14:55+00:00"
"time": "2021-02-02T20:01:31+00:00"
},
{
"name": "barryvdh/laravel-dompdf",
@ -1712,16 +1712,16 @@
},
{
"name": "laravel/framework",
"version": "v6.20.15",
"version": "v6.20.16",
"source": {
"type": "git",
"url": "https://github.com/laravel/framework.git",
"reference": "b42c2d845cdd827ac5a53cacf16af4a0b5dd8be1"
"reference": "806082fb559fe595cb17cd6aa8571f03ed287814"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/framework/zipball/b42c2d845cdd827ac5a53cacf16af4a0b5dd8be1",
"reference": "b42c2d845cdd827ac5a53cacf16af4a0b5dd8be1",
"url": "https://api.github.com/repos/laravel/framework/zipball/806082fb559fe595cb17cd6aa8571f03ed287814",
"reference": "806082fb559fe595cb17cd6aa8571f03ed287814",
"shasum": ""
},
"require": {
@ -1861,7 +1861,7 @@
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
"time": "2021-01-26T14:39:47+00:00"
"time": "2021-02-02T13:50:12+00:00"
},
{
"name": "laravel/socialite",
@ -3798,16 +3798,16 @@
},
{
"name": "socialiteproviders/okta",
"version": "4.1.0",
"version": "4.1.1",
"source": {
"type": "git",
"url": "https://github.com/SocialiteProviders/Okta.git",
"reference": "60f88b8e8c88508889c61346af83290131b72fe7"
"reference": "e3ef9f23c7d2f86b3b16a174b82333cf4e2459e8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/SocialiteProviders/Okta/zipball/60f88b8e8c88508889c61346af83290131b72fe7",
"reference": "60f88b8e8c88508889c61346af83290131b72fe7",
"url": "https://api.github.com/repos/SocialiteProviders/Okta/zipball/e3ef9f23c7d2f86b3b16a174b82333cf4e2459e8",
"reference": "e3ef9f23c7d2f86b3b16a174b82333cf4e2459e8",
"shasum": ""
},
"require": {
@ -3833,9 +3833,9 @@
],
"description": "Okta OAuth2 Provider for Laravel Socialite",
"support": {
"source": "https://github.com/SocialiteProviders/Okta/tree/4.1.0"
"source": "https://github.com/SocialiteProviders/Okta/tree/4.1.1"
},
"time": "2020-12-01T23:10:59+00:00"
"time": "2021-01-12T23:51:01+00:00"
},
{
"name": "socialiteproviders/slack",

View File

@ -66,6 +66,36 @@ class PageRevisionTest extends TestCase
$pageView->assertSee('def456');
}
public function test_page_revision_restore_with_markdown_retains_markdown_content()
{
$this->asEditor();
$pageRepo = app(PageRepo::class);
$page = Page::first();
$pageRepo->update($page, ['name' => 'updated page abc123', 'markdown' => '## New Content def456', 'summary' => 'initial page revision testing']);
$pageRepo->update($page, ['name' => 'updated page again', 'markdown' => '## New Content Updated', 'summary' => 'page revision testing']);
$page = Page::find($page->id);
$pageView = $this->get($page->getUrl());
$pageView->assertDontSee('abc123');
$pageView->assertDontSee('def456');
$revToRestore = $page->revisions()->where('name', 'like', '%abc123')->first();
$restoreReq = $this->put($page->getUrl() . '/revisions/' . $revToRestore->id . '/restore');
$page = Page::find($page->id);
$restoreReq->assertStatus(302);
$restoreReq->assertRedirect($page->getUrl());
$pageView = $this->get($page->getUrl());
$this->assertDatabaseHas('pages', [
'id' => $page->id,
'markdown' => '## New Content def456',
]);
$pageView->assertSee('abc123');
$pageView->assertSee('def456');
}
public function test_page_revision_restore_sets_new_revision_with_summary()
{
$this->asEditor();

View File

@ -1,7 +1,10 @@
<?php namespace Tests;
use BookStack\Entities\Models\Book;
use BookStack\Entities\Models\Bookshelf;
use BookStack\Entities\Models\Chapter;
use BookStack\Entities\Models\Deletion;
use BookStack\Entities\Models\Entity;
use BookStack\Entities\Models\Page;
use DB;
use Illuminate\Support\Carbon;
@ -129,6 +132,21 @@ class RecycleBinTest extends TestCase
$redirectReq->assertNotificationContains('Deleted '.$itemCount.' total items from the recycle bin');
}
public function test_permanent_delete_for_each_type()
{
/** @var Entity $entity */
foreach ([new Bookshelf, new Book, new Chapter, new Page] as $entity) {
$entity = $entity->newQuery()->first();
$this->asEditor()->delete($entity->getUrl());
$deletion = Deletion::query()->orderBy('id', 'desc')->firstOrFail();
$deleteReq = $this->asAdmin()->delete("/settings/recycle-bin/{$deletion->id}");
$deleteReq->assertRedirect('/settings/recycle-bin');
$this->assertDatabaseMissing('deletions', ['id' => $deletion->id]);
$this->assertDatabaseMissing($entity->getTable(), ['id' => $entity->id]);
}
}
public function test_permanent_entity_delete_updates_existing_activity_with_entity_name()
{
$page = Page::query()->firstOrFail();