diff --git a/src/stubs/view-forms.stub b/src/stubs/view-forms.stub index f0f1eff..f3aebb5 100644 --- a/src/stubs/view-forms.stub +++ b/src/stubs/view-forms.stub @@ -1,4 +1,4 @@ -@if (Request::get('action') == 'create') +@if (Request::get('action') == 'create' && auth()->user()->can('create', new fullMstr)) {!! Form::open(['route' => 'masters.store']) !!} {!! FormField::text('name', ['required' => true, 'label' => trans('master.name')]) !!} {!! FormField::textarea('description', ['label' => trans('master.description')]) !!} @@ -6,7 +6,7 @@ {{ link_to_route('masters.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }} {!! Form::close() !!} @endif -@if (Request::get('action') == 'edit' && $editableMaster) +@if (Request::get('action') == 'edit' && $editableMaster && auth()->user()->can('update', $editableMaster)) {!! Form::model($editableMaster, ['route' => ['masters.update', $editableMaster->id],'method' => 'patch']) !!} {!! FormField::text('name', ['required' => true, 'label' => trans('master.name')]) !!} {!! FormField::textarea('description', ['label' => trans('master.description')]) !!} @@ -20,7 +20,7 @@ {{ link_to_route('masters.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }} {!! Form::close() !!} @endif -@if (Request::get('action') == 'delete' && $editableMaster) +@if (Request::get('action') == 'delete' && $editableMaster && auth()->user()->can('delete', $editableMaster))

{{ trans('master.delete') }}

diff --git a/src/stubs/view-index.stub b/src/stubs/view-index.stub index ff31c1a..eb020d0 100644 --- a/src/stubs/view-index.stub +++ b/src/stubs/view-index.stub @@ -5,7 +5,9 @@ @section('content')

+ @can('create', new fullMstr) {{ link_to_route('masters.index', trans('master.create'), ['action' => 'create'], ['class' => 'btn btn-success']) }} + @endcan
{{ trans('master.list') }} {{ trans('app.total') }} : {{ $mstrCollections->total() }} {{ trans('master.master') }} @@ -36,18 +38,22 @@ {{ $singleMstr->name }} {{ $singleMstr->description }} + @can('update', $singleMstr) {!! link_to_route( 'masters.index', trans('app.edit'), ['action' => 'edit', 'id' => $singleMstr->id] + Request::only('page', 'q'), ['id' => 'edit-singleMstr-' . $singleMstr->id] ) !!} | + @endcan + @can('delete', $singleMstr) {!! link_to_route( 'masters.index', trans('app.delete'), ['action' => 'delete', 'id' => $singleMstr->id] + Request::only('page', 'q'), ['id' => 'del-singleMstr-' . $singleMstr->id] ) !!} + @endcan @endforeach diff --git a/tests/Generators/ViewsGeneratorTest.php b/tests/Generators/ViewsGeneratorTest.php index 6fd5609..e0391f5 100644 --- a/tests/Generators/ViewsGeneratorTest.php +++ b/tests/Generators/ViewsGeneratorTest.php @@ -21,7 +21,9 @@ class ViewsGeneratorTest extends TestCase @section('content')

+ @can('create', new {$this->full_model_name}) {{ link_to_route('{$this->table_name}.index', trans('{$this->lang_name}.create'), ['action' => 'create'], ['class' => 'btn btn-success']) }} + @endcan
{{ trans('{$this->lang_name}.list') }} {{ trans('app.total') }} : {{ \${$this->collection_model_var_name}->total() }} {{ trans('{$this->lang_name}.{$this->lang_name}') }} @@ -52,18 +54,22 @@ class ViewsGeneratorTest extends TestCase {{ \${$this->single_model_var_name}->name }} {{ \${$this->single_model_var_name}->description }} + @can('update', \${$this->single_model_var_name}) {!! link_to_route( '{$this->table_name}.index', trans('app.edit'), ['action' => 'edit', 'id' => \${$this->single_model_var_name}->id] + Request::only('page', 'q'), ['id' => 'edit-{$this->single_model_var_name}-' . \${$this->single_model_var_name}->id] ) !!} | + @endcan + @can('delete', \${$this->single_model_var_name}) {!! link_to_route( '{$this->table_name}.index', trans('app.delete'), ['action' => 'delete', 'id' => \${$this->single_model_var_name}->id] + Request::only('page', 'q'), ['id' => 'del-{$this->single_model_var_name}-' . \${$this->single_model_var_name}->id] ) !!} + @endcan @endforeach @@ -90,7 +96,7 @@ class ViewsGeneratorTest extends TestCase $formViewPath = resource_path("views/{$this->table_name}/forms.blade.php"); $this->assertFileExists($formViewPath); - $formViewContent = "@if (Request::get('action') == 'create') + $formViewContent = "@if (Request::get('action') == 'create' && auth()->user()->can('create', new {$this->full_model_name})) {!! Form::open(['route' => '{$this->table_name}.store']) !!} {!! FormField::text('name', ['required' => true, 'label' => trans('{$this->lang_name}.name')]) !!} {!! FormField::textarea('description', ['label' => trans('{$this->lang_name}.description')]) !!} @@ -98,7 +104,7 @@ class ViewsGeneratorTest extends TestCase {{ link_to_route('{$this->table_name}.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }} {!! Form::close() !!} @endif -@if (Request::get('action') == 'edit' && \$editable{$this->model_name}) +@if (Request::get('action') == 'edit' && \$editable{$this->model_name} && auth()->user()->can('update', \$editable{$this->model_name})) {!! Form::model(\$editable{$this->model_name}, ['route' => ['{$this->table_name}.update', \$editable{$this->model_name}->id],'method' => 'patch']) !!} {!! FormField::text('name', ['required' => true, 'label' => trans('{$this->lang_name}.name')]) !!} {!! FormField::textarea('description', ['label' => trans('{$this->lang_name}.description')]) !!} @@ -112,7 +118,7 @@ class ViewsGeneratorTest extends TestCase {{ link_to_route('{$this->table_name}.index', trans('app.cancel'), [], ['class' => 'btn btn-default']) }} {!! Form::close() !!} @endif -@if (Request::get('action') == 'delete' && \$editable{$this->model_name}) +@if (Request::get('action') == 'delete' && \$editable{$this->model_name} && auth()->user()->can('delete', \$editable{$this->model_name}))

{{ trans('{$this->lang_name}.delete') }}