mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-03-04 16:56:25 +08:00
parent
a988438946
commit
db51cee2d8
@ -324,9 +324,10 @@ class PageController extends Controller
|
|||||||
$page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
|
$page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
|
||||||
$book = $page->book;
|
$book = $page->book;
|
||||||
$this->checkOwnablePermission('page-delete', $page);
|
$this->checkOwnablePermission('page-delete', $page);
|
||||||
|
$this->entityRepo->destroyPage($page);
|
||||||
|
|
||||||
Activity::addMessage('page_delete', $book->id, $page->name);
|
Activity::addMessage('page_delete', $book->id, $page->name);
|
||||||
session()->flash('success', trans('entities.pages_delete_success'));
|
session()->flash('success', trans('entities.pages_delete_success'));
|
||||||
$this->entityRepo->destroyPage($page);
|
|
||||||
return redirect($book->getUrl());
|
return redirect($book->getUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ use BookStack\Book;
|
|||||||
use BookStack\Chapter;
|
use BookStack\Chapter;
|
||||||
use BookStack\Entity;
|
use BookStack\Entity;
|
||||||
use BookStack\Exceptions\NotFoundException;
|
use BookStack\Exceptions\NotFoundException;
|
||||||
|
use BookStack\Exceptions\NotifyException;
|
||||||
use BookStack\Page;
|
use BookStack\Page;
|
||||||
use BookStack\PageRevision;
|
use BookStack\PageRevision;
|
||||||
use BookStack\Services\AttachmentService;
|
use BookStack\Services\AttachmentService;
|
||||||
@ -1073,6 +1074,7 @@ class EntityRepo
|
|||||||
/**
|
/**
|
||||||
* Destroy a given page along with its dependencies.
|
* Destroy a given page along with its dependencies.
|
||||||
* @param Page $page
|
* @param Page $page
|
||||||
|
* @throws NotifyException
|
||||||
*/
|
*/
|
||||||
public function destroyPage(Page $page)
|
public function destroyPage(Page $page)
|
||||||
{
|
{
|
||||||
@ -1084,6 +1086,12 @@ class EntityRepo
|
|||||||
$this->permissionService->deleteJointPermissionsForEntity($page);
|
$this->permissionService->deleteJointPermissionsForEntity($page);
|
||||||
$this->searchService->deleteEntityTerms($page);
|
$this->searchService->deleteEntityTerms($page);
|
||||||
|
|
||||||
|
// Check if set as custom homepage
|
||||||
|
$customHome = setting('app-homepage', '0:');
|
||||||
|
if (intval($page->id) === intval(explode(':', $customHome)[0])) {
|
||||||
|
throw new NotifyException(trans('errors.page_custom_home_deletion'), $page->getUrl());
|
||||||
|
}
|
||||||
|
|
||||||
// Delete Attached Files
|
// Delete Attached Files
|
||||||
$attachmentService = app(AttachmentService::class);
|
$attachmentService = app(AttachmentService::class);
|
||||||
foreach ($page->attachments as $attachment) {
|
foreach ($page->attachments as $attachment) {
|
||||||
|
@ -41,6 +41,7 @@ return [
|
|||||||
|
|
||||||
// Pages
|
// Pages
|
||||||
'page_draft_autosave_fail' => 'Failed to save draft. Ensure you have internet connection before saving this page',
|
'page_draft_autosave_fail' => 'Failed to save draft. Ensure you have internet connection before saving this page',
|
||||||
|
'page_custom_home_deletion' => 'Cannot delete a page while it is set as a homepage',
|
||||||
|
|
||||||
// Entities
|
// Entities
|
||||||
'entity_not_found' => 'Entity not found',
|
'entity_not_found' => 'Entity not found',
|
||||||
|
@ -16,7 +16,8 @@ class HomepageTest extends TestCase
|
|||||||
$homeVisit->assertSee('Recent Activity');
|
$homeVisit->assertSee('Recent Activity');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_custom_homepage() {
|
public function test_custom_homepage()
|
||||||
|
{
|
||||||
$this->asEditor();
|
$this->asEditor();
|
||||||
$name = 'My custom homepage';
|
$name = 'My custom homepage';
|
||||||
$content = 'This is the body content of my custom homepage.';
|
$content = 'This is the body content of my custom homepage.';
|
||||||
@ -30,4 +31,26 @@ class HomepageTest extends TestCase
|
|||||||
$homeVisit->assertSee('Recently Updated Pages');
|
$homeVisit->assertSee('Recently Updated Pages');
|
||||||
$homeVisit->assertSee('Recent Activity');
|
$homeVisit->assertSee('Recent Activity');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_delete_custom_homepage()
|
||||||
|
{
|
||||||
|
$this->asEditor();
|
||||||
|
$name = 'My custom homepage';
|
||||||
|
$content = 'This is the body content of my custom homepage.';
|
||||||
|
$customPage = $this->newPage(['name' => $name, 'html' => $content]);
|
||||||
|
$this->setSettings(['app-homepage' => $customPage->id]);
|
||||||
|
|
||||||
|
$homeVisit = $this->get('/');
|
||||||
|
$homeVisit->assertSee($name);
|
||||||
|
|
||||||
|
$pageDeleteReq = $this->delete($customPage->getUrl());
|
||||||
|
$pageDeleteReq->assertStatus(302);
|
||||||
|
$pageDeleteReq->assertRedirect($customPage->getUrl());
|
||||||
|
$pageDeleteReq->assertSessionHas('error');
|
||||||
|
$pageDeleteReq->assertSessionMissing('success');
|
||||||
|
|
||||||
|
$homeVisit = $this->get('/');
|
||||||
|
$homeVisit->assertSee($name);
|
||||||
|
$homeVisit->assertStatus(200);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user