From: Vincent Vanwaelscappel Date: Tue, 12 Dec 2023 07:51:20 +0000 (+0100) Subject: wip #6570 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=7266c5e29b8f3b57281ad8ac7130d854fa2b6ade;p=cubist_cms-back.git wip #6570 @0.5 --- diff --git a/src/app/CubistCrudPanel.php b/src/app/CubistCrudPanel.php index 86439dc..30e9f24 100644 --- a/src/app/CubistCrudPanel.php +++ b/src/app/CubistCrudPanel.php @@ -61,15 +61,17 @@ class CubistCrudPanel extends CrudPanel return true; } - public function hasAccess($operation) + public function hasAccess($operation, $entry = null): bool { // First filter with standard backpack gate - if (!parent::hasAccess($operation)) { + if (!parent::hasAccess($operation, $entry)) { return false; } + $model = $entry ?? $this->entry ?? $this->model; + // Then, apply model rules - if ($this->model instanceof CubistMagicAbstractModel) { + if ($model instanceof CubistMagicAbstractModel) { $funcMap = [ 'show' => 'canList', 'infos' => 'canList', @@ -89,7 +91,7 @@ class CubistCrudPanel extends CrudPanel } else { $func = 'can' . ucfirst($operation); } - $model = $this->entry ?? $this->model; + if (is_callable([$model, $func])) { return $model->$func(backpack_user()); } @@ -103,34 +105,6 @@ class CubistCrudPanel extends CrudPanel return request()->get('embeded', '0') != '0'; } - 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; - } - /** * @param $model CubistMagicAbstractModel */ diff --git a/src/app/Magic/Fields/Checkbox.php b/src/app/Magic/Fields/Checkbox.php index 64b30fc..a147379 100644 --- a/src/app/Magic/Fields/Checkbox.php +++ b/src/app/Magic/Fields/Checkbox.php @@ -6,11 +6,10 @@ namespace Cubist\Backpack\Magic\Fields; class Checkbox extends Field { - protected $_adminType = 'toggle'; + protected $_adminType = 'switch'; protected $_databaseType = 'boolean'; protected $_columnType = 'check'; protected $_cast = 'boolean'; - protected $_viewNamespace = 'toggle-field-for-backpack::fields'; protected $_filterType = 'dropdown'; public function filterDefault($value) diff --git a/src/resources/views/create.blade.php b/src/resources/views/create.blade.php index 9fc72e5..ef4c5e1 100644 --- a/src/resources/views/create.blade.php +++ b/src/resources/views/create.blade.php @@ -14,23 +14,26 @@ @endphp @section('header') -
-

- {!! $crud->getHeading() ?? $crud->entity_name_plural !!} - {!! $crud->getSubheading() ?? trans('backpack::crud.add').' '.$crud->entity_name !!}. - +
+

{!! $crud->getHeading() ?? $crud->entity_name_plural !!}

+

{!! $crud->getSubheading() ?? trans('backpack::crud.add').' '.$crud->entity_name !!}.

@if ($crud->hasAccess('list')) - {{ trans('backpack::crud.back_to_all') }} {{ $crud->entity_name_plural }} +

+ + + {{ trans('backpack::crud.back_to_all') }} {{ $crud->entity_name_plural }} + + +

@endif -

@endsection @section('content') -
+
- + {{-- Default box --}} @include('crud::inc.grouped_errors') @@ -41,13 +44,14 @@ @endif > {!! csrf_field() !!} - + {{-- load the view from the application if it exists, otherwise load the one in the package --}} @if(view()->exists('vendor.backpack.crud.form_content')) @include('vendor.backpack.crud.form_content', [ 'fields' => $crud->fields(), 'action' => 'create' ]) @else @include('crud::form_content', [ 'fields' => $crud->fields(), 'action' => 'create' ]) @endif - + {{-- This makes sure that all field assets are loaded. --}} +
{{ json_encode(Basset::loaded()) }}
@include('crud::inc.form_save_buttons')
diff --git a/src/resources/views/edit.blade.php b/src/resources/views/edit.blade.php index d92d863..12d5d24 100644 --- a/src/resources/views/edit.blade.php +++ b/src/resources/views/edit.blade.php @@ -40,22 +40,19 @@ @endphp @section('header') -
-

- {!! $crud->getHeading() ?? $crud->entity_name_plural !!} - {!! $crud->getSubheading() ?? trans('backpack::crud.edit').' '.$crud->entity_name !!}. - +
+

{!! $crud->getHeading() ?? $crud->entity_name_plural !!}

+

{!! $crud->getSubheading() ?? trans('backpack::crud.edit').' '.$crud->entity_name !!}.

@if ($crud->hasAccess('list')) - {{ trans('backpack::crud.back_to_all') }} - {{ $crud->entity_name_plural }} +

+ {{ trans('backpack::crud.back_to_all') }} {{ $crud->entity_name_plural }} +

@endif -

@endsection @section('content') -
+
{{-- Default box --}} @@ -74,8 +71,7 @@
{{-- Single button --}}
-