mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-06 10:44:33 +08:00
Added per-item recycle-bin delete and restore
This commit is contained in:
@ -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);
|
||||
|
@ -2,36 +2,103 @@
|
||||
|
||||
use BookStack\Entities\Deletion;
|
||||
use BookStack\Entities\Managers\TrashCan;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
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()
|
||||
{
|
||||
// TODO - Check this is enforced.
|
||||
$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()
|
||||
{
|
||||
$this->checkPermission('settings-manage');
|
||||
$this->checkPermission('restrictions-manage-all');
|
||||
|
||||
$deletions = Deletion::query()->with(['deletable', 'deleter'])->paginate(10);
|
||||
|
||||
return view('settings.recycle-bin', [
|
||||
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()
|
||||
{
|
||||
$this->checkPermission('settings-manage');
|
||||
$this->checkPermission('restrictions-manage-all');
|
||||
|
||||
$deleteCount = (new TrashCan())->destroyFromAllDeletions();
|
||||
|
||||
$this->showSuccessNotification(trans('settings.recycle_bin_empty_notification', ['count' => $deleteCount]));
|
||||
return redirect('/settings/recycle-bin');
|
||||
$this->showSuccessNotification(trans('settings.recycle_bin_destroy_notification', ['count' => $deleteCount]));
|
||||
return redirect($this->recycleBinBaseUrl);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user