From bd1da3f9e1cda15c61135723179275e0f4ab943d Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 30 Nov 2020 19:47:35 +0100 Subject: [PATCH] wip #3753 @0.25 --- src/app/CubistCrudPanel.php | 44 +++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/app/CubistCrudPanel.php b/src/app/CubistCrudPanel.php index 03d5f8f..be64232 100644 --- a/src/app/CubistCrudPanel.php +++ b/src/app/CubistCrudPanel.php @@ -2,8 +2,10 @@ namespace Cubist\Backpack\app; +use Backpack\CRUD\app\Exceptions\AccessDeniedException; use Backpack\CRUD\app\Library\CrudPanel\CrudPanel; use Cubist\Backpack\app\Magic\Models\CubistMagicAbstractModel; +use Illuminate\Support\Facades\Gate; /** * @property CubistMagicAbstractModel $model @@ -59,4 +61,46 @@ class CubistCrudPanel extends CrudPanel $this->_seenFieldTypes[$type] = true; return true; } + + public function hasAccess($operation) + { + // First filter with standard backpack gate + if (!parent::hasAccess($operation)) { + return false; + } + + + return true; + } + + public function hasAccessOrFail($operation) + { + if (!$this->hasAccess($operation)) { + throw new AccessDeniedException(trans('backpack::crud.unauthorized_access', ['access' => $operation])); + } + + return true; + } + + public function hasAccessToAll($operation_array) + { + foreach ((array)$operation_array as $key => $operation) { + if (!$this->hasAccess($operation)) { + return false; + } + } + + return true; + } + + public function hasAccessToAny($operation_array) + { + foreach ((array)$operation_array as $key => $operation) { + if ($this->hasAccess($operation) == true) { + return true; + } + } + + return false; + } } -- 2.39.5