]> _ Git - cubist_cms-back.git/commitdiff
wip #3466 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 5 Mar 2020 16:42:20 +0000 (17:42 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 5 Mar 2020 16:42:20 +0000 (17:42 +0100)
src/app/Magic/Controllers/CubistMagicController.php
src/app/Magic/Fields/Field.php
src/app/Magic/Fields/Model.php
src/app/Magic/Fields/User.php
src/app/helpers.php
src/resources/views/fields/authhidden.blade.php [new file with mode: 0644]

index e4fa39b8556fdfbfe05c986bdc0a14855a718da2..264a7e403df94487b079f78feb8a9928954c9a97 100644 (file)
@@ -120,6 +120,10 @@ class CubistMagicController extends CubistCrudController
         if (is_array($field)) {
             $field = Field::getInstance($field);
         }
+        if (!$field->getAttribute('fillable', true)) {
+           $field->setAttribute('type','hidden');
+           $field->setAttribute('type','hidden');
+        }
         /** @var $field Field */
         if ($field->isDisplayColumn()) {
             $this->crud->addColumn($field->getColumnData());
index cc5c373c9d55124a6e5bd39d15ed6ce36f6fdddf..cdcc59f765b5f8266a40d1d940a398dded2d828e 100644 (file)
@@ -4,6 +4,7 @@
 namespace Cubist\Backpack\app\Magic\Fields;
 
 use Cubist\Backpack\app\Magic\CubistMagicAttribute;
+use Cubist\Backpack\CubistBackpackServiceProvider;
 use Doctrine\DBAL\Schema\Table;
 use Exception;
 use Illuminate\Support\Str;
@@ -31,6 +32,9 @@ class Field implements \ArrayAccess
     protected $_translatable = false;
     protected $_migrateTranslatable = false;
 
+    protected $_can = null;
+    protected $_auth = true;
+
     /**
      * @var CubistMagicAbstractModel
      */
@@ -104,6 +108,7 @@ class Field implements \ArrayAccess
             'column_type' => $this->_columnType, 'column_move_after' => $this->_columnMoveAfter,
             'default' => '', 'cast' => $this->_cast, 'column_view_namespace' => $this->_columnViewNamespace, 'searchLogic' => $this->_searchLogic,
             'allow_null' => true,
+            'can' => $this->_can, 'auth' => $this->_auth,
             'fake' => false, 'store_in' => 'extras', 'attributes' => []];
     }
 
@@ -210,6 +215,14 @@ class Field implements \ArrayAccess
             $wrapperAttributes['data-when'] = json_encode($this->getAttribute('when'));
             $this->setAttribute('wrapperAttributes', $wrapperAttributes);
         }
+
+        if (null !== $this->getAttribute('can', null)) {
+            if (!can($this->getAttribute('can'))) {
+                $this->setAttribute('auth', false);
+                $this->setAttribute('type', 'authhidden');
+                $this->setAttribute('view_namespace', CubistBackpackServiceProvider::NAMESPACE . '::fields');
+            }
+        }
     }
 
     /**
index 6bf73f081c6bc98d1c78d3b6642b2018cfc0fc1e..e7829959f53ccda87170428e78237c95ba0c365c 100644 (file)
@@ -29,8 +29,8 @@ class Model extends Field
         /** @var \Illuminate\Database\Eloquent\Model $inst */
         $inst = new $modelClass();
 
-        $attr=$this->getAttribute('attribute');
-        return $modelClass::orderBy($attr)->get()->pluck($attr, $inst->getKey())->toArray();
+        $attr = $this->getAttribute('attribute');
+        return $modelClass::orderBy($attr)->get()->pluck($attr, $inst->getKeyName())->toArray();
     }
 
     public function getDatabaseType()
index af342c32d4151b3a510c7c8d4c3598b4a864840c..360d0bc9769ecc487396d4cdb3dc5fcce0ec71c2 100644 (file)
@@ -5,17 +5,16 @@ namespace Cubist\Backpack\app\Magic\Fields;
 class User extends SelectFromModel
 {
     protected $_optionsmodel = '\App\User';
-    protected $_allows_null = true;
+    protected $_allows_null = false;
 
     public function getDefaultAttributes()
     {
-        $default=['optionsmodel' => $this->_optionsmodel];
-
-        $auth=auth();
-        if($auth){
-            $user=$auth->user();
-            if($user){
-                $default['value']=$user->id;
+        $default = ['optionsmodel' => $this->_optionsmodel, 'attribute' => 'name'];
+        $auth = auth();
+        if ($auth) {
+            $user = $auth->user();
+            if ($user) {
+                $default['value'] = $user->id;
             }
         }
         return array_merge(parent::getDefaultAttributes(), $default);
index 1b072ca8881220c3d1f5d31aeddd0c1aecc05a87..40ed2a169bbf2a8715abfae803e086339e470c37 100644 (file)
@@ -32,3 +32,10 @@ if (!function_exists('protected_path')) {
         return base_path('protected/' . $path);
     }
 }
+
+if (!function_exists('can')) {
+    function can($permission, $model = null)
+    {
+        return auth()->user()->can($permission, $model = null);
+    }
+}
diff --git a/src/resources/views/fields/authhidden.blade.php b/src/resources/views/fields/authhidden.blade.php
new file mode 100644 (file)
index 0000000..e69de29