]> _ Git - cubist_cms-back.git/commitdiff
wip #3753 @0.25
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 30 Nov 2020 18:47:35 +0000 (19:47 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 30 Nov 2020 18:47:35 +0000 (19:47 +0100)
src/app/CubistCrudPanel.php

index 03d5f8f4636a0beb7aca291308fc9345b03403bd..be642327beba52d259b6feee5bf57b143cb6c7bd 100644 (file)
@@ -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;
+    }
 }