1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Merge pull request #2283 from BookStackApp/recycle_bin

Recycle Bin Implementation
This commit is contained in:
Dan Brown
2020-11-07 15:10:17 +00:00
committed by GitHub
48 changed files with 1226 additions and 185 deletions

View File

@ -23,7 +23,12 @@ class AuditLogController extends Controller
];
$query = Activity::query()
->with(['entity', 'user'])
->with([
'entity' => function ($query) {
$query->withTrashed();
},
'user'
])
->orderBy($listDetails['sort'], $listDetails['order']);
if ($listDetails['event']) {

View File

@ -181,14 +181,13 @@ class BookController extends Controller
/**
* Remove the specified book from the system.
* @throws Throwable
* @throws NotifyException
*/
public function destroy(string $bookSlug)
{
$book = $this->bookRepo->getBySlug($bookSlug);
$this->checkOwnablePermission('book-delete', $book);
Activity::addMessage('book_delete', $book->name);
Activity::add($book, 'book_delete', $book->id);
$this->bookRepo->destroy($book);
return redirect('/books');

View File

@ -182,7 +182,7 @@ class BookshelfController extends Controller
$shelf = $this->bookshelfRepo->getBySlug($slug);
$this->checkOwnablePermission('bookshelf-delete', $shelf);
Activity::addMessage('bookshelf_delete', $shelf->name);
Activity::add($shelf, 'bookshelf_delete');
$this->bookshelfRepo->destroy($shelf);
return redirect('/shelves');

View File

@ -128,7 +128,7 @@ class ChapterController extends Controller
$chapter = $this->chapterRepo->getBySlug($bookSlug, $chapterSlug);
$this->checkOwnablePermission('chapter-delete', $chapter);
Activity::addMessage('chapter_delete', $chapter->name, $chapter->book->id);
Activity::add($chapter, 'chapter_delete', $chapter->book->id);
$this->chapterRepo->destroy($chapter);
return redirect($chapter->book->getUrl());

View File

@ -14,7 +14,6 @@ class HomeController extends Controller
/**
* Display the homepage.
* @return Response
*/
public function index()
{
@ -22,14 +21,17 @@ class HomeController extends Controller
$draftPages = [];
if ($this->isSignedIn()) {
$draftPages = Page::visible()->where('draft', '=', true)
$draftPages = Page::visible()
->where('draft', '=', true)
->where('created_by', '=', user()->id)
->orderBy('updated_at', 'desc')->take(6)->get();
->orderBy('updated_at', 'desc')
->take(6)
->get();
}
$recentFactor = count($draftPages) > 0 ? 0.5 : 1;
$recents = $this->isSignedIn() ?
Views::getUserRecentlyViewed(12*$recentFactor, 0)
Views::getUserRecentlyViewed(12*$recentFactor, 1)
: Book::visible()->orderBy('created_at', 'desc')->take(12 * $recentFactor)->get();
$recentlyUpdatedPages = Page::visible()->where('draft', false)
->orderBy('updated_at', 'desc')->take(12)->get();

View File

@ -2,6 +2,7 @@
namespace BookStack\Http\Controllers;
use BookStack\Entities\Managers\TrashCan;
use BookStack\Notifications\TestEmail;
use BookStack\Uploads\ImageService;
use Illuminate\Http\Request;
@ -19,7 +20,13 @@ class MaintenanceController extends Controller
// Get application version
$version = trim(file_get_contents(base_path('version')));
return view('settings.maintenance', ['version' => $version]);
// Recycle bin details
$recycleStats = (new TrashCan())->getTrashedCounts();
return view('settings.maintenance', [
'version' => $version,
'recycleStats' => $recycleStats,
]);
}
/**

View File

@ -78,7 +78,7 @@ class PageController extends Controller
public function editDraft(string $bookSlug, int $pageId)
{
$draft = $this->pageRepo->getById($pageId);
$this->checkOwnablePermission('page-create', $draft->parent());
$this->checkOwnablePermission('page-create', $draft->getParent());
$this->setPageTitle(trans('entities.pages_edit_draft'));
$draftsEnabled = $this->isSignedIn();
@ -104,7 +104,7 @@ class PageController extends Controller
'name' => 'required|string|max:255'
]);
$draftPage = $this->pageRepo->getById($pageId);
$this->checkOwnablePermission('page-create', $draftPage->parent());
$this->checkOwnablePermission('page-create', $draftPage->getParent());
$page = $this->pageRepo->publishDraft($draftPage, $request->all());
Activity::add($page, 'page_create', $draftPage->book->id);
@ -308,9 +308,8 @@ class PageController extends Controller
$book = $page->book;
$parent = $page->chapter ?? $book;
$this->pageRepo->destroy($page);
Activity::addMessage('page_delete', $page->name, $book->id);
Activity::add($page, 'page_delete', $page->book_id);
$this->showSuccessNotification(trans('entities.pages_delete_success'));
return redirect($parent->getUrl());
}

View File

@ -0,0 +1,103 @@
<?php namespace BookStack\Http\Controllers;
use BookStack\Entities\Deletion;
use BookStack\Entities\Managers\TrashCan;
class RecycleBinController extends Controller
{
protected $recycleBinBaseUrl = '/settings/recycle-bin';
/**
* On each request to a method of this controller check permissions
* using a middleware closure.
*/
public function __construct()
{
$this->middleware(function ($request, $next) {
$this->checkPermission('settings-manage');
$this->checkPermission('restrictions-manage-all');
return $next($request);
});
parent::__construct();
}
/**
* Show the top-level listing for the recycle bin.
*/
public function index()
{
$deletions = Deletion::query()->with(['deletable', 'deleter'])->paginate(10);
return view('settings.recycle-bin.index', [
'deletions' => $deletions,
]);
}
/**
* Show the page to confirm a restore of the deletion of the given id.
*/
public function showRestore(string $id)
{
/** @var Deletion $deletion */
$deletion = Deletion::query()->findOrFail($id);
return view('settings.recycle-bin.restore', [
'deletion' => $deletion,
]);
}
/**
* Restore the element attached to the given deletion.
* @throws \Exception
*/
public function restore(string $id)
{
/** @var Deletion $deletion */
$deletion = Deletion::query()->findOrFail($id);
$restoreCount = (new TrashCan())->restoreFromDeletion($deletion);
$this->showSuccessNotification(trans('settings.recycle_bin_restore_notification', ['count' => $restoreCount]));
return redirect($this->recycleBinBaseUrl);
}
/**
* Show the page to confirm a Permanent deletion of the element attached to the deletion of the given id.
*/
public function showDestroy(string $id)
{
/** @var Deletion $deletion */
$deletion = Deletion::query()->findOrFail($id);
return view('settings.recycle-bin.destroy', [
'deletion' => $deletion,
]);
}
/**
* Permanently delete the content associated with the given deletion.
* @throws \Exception
*/
public function destroy(string $id)
{
/** @var Deletion $deletion */
$deletion = Deletion::query()->findOrFail($id);
$deleteCount = (new TrashCan())->destroyFromDeletion($deletion);
$this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount]));
return redirect($this->recycleBinBaseUrl);
}
/**
* Empty out the recycle bin.
* @throws \Exception
*/
public function empty()
{
$deleteCount = (new TrashCan())->empty();
$this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount]));
return redirect($this->recycleBinBaseUrl);
}
}