fix in progress for get routes performing actions more than redirect

This commit is contained in:
Prashant Singh 2019-04-08 04:51:02 +05:30
parent 82e56334c2
commit 747f214739
8 changed files with 36 additions and 17 deletions

View File

@ -128,12 +128,14 @@ class AttributeDataGrid extends DataGrid
{
$this->addAction([
'type' => 'Edit',
'method' => strtoupper('get'), // use get request for only redirect purposes
'route' => 'admin.catalog.attributes.edit',
'icon' => 'icon pencil-lg-icon'
]);
$this->addAction([
'type' => 'Delete',
'method' => strtoupper('delete'), //upper case string
'route' => 'admin.catalog.attributes.delete',
'icon' => 'icon trash-icon'
]);
@ -148,4 +150,4 @@ class AttributeDataGrid extends DataGrid
'method' => 'DELETE'
]);
}
}
}

View File

@ -278,7 +278,7 @@ Route::group(['middleware' => ['web']], function () {
'redirect' => 'admin.catalog.attributes.index'
])->name('admin.catalog.attributes.update');
Route::get('/attributes/delete/{id}', 'Webkul\Attribute\Http\Controllers\AttributeController@destroy')->name('admin.catalog.attributes.delete');
Route::post('/attributes/delete/{id}', 'Webkul\Attribute\Http\Controllers\AttributeController@destroy')->name('admin.catalog.attributes.delete');
Route::post('/attributes/massdelete', 'Webkul\Attribute\Http\Controllers\AttributeController@massDestroy')->name('admin.catalog.attributes.massdelete');

View File

@ -95,6 +95,7 @@ class AdminServiceProvider extends ServiceProvider
}
$tree->items = core()->sortItems($tree->items);
$view->with('menu', $tree);
});

View File

@ -3,6 +3,7 @@
@if (request()->route()->getName() != 'admin.configuration.index')
<?php $keys = explode('.', $menu->currentKey); ?>
@if(isset($keys) && strlen($keys[0]))
@foreach (array_get($menu->items, current($keys) . '.children') as $item)
<li class="{{ $menu->getActive($item) }}">
<a href="{{ $item['url'] }}">
@ -14,6 +15,7 @@
</a>
</li>
@endforeach
@endif
@else
@foreach ($config->items as $key => $item)
<li class="{{ $item['key'] == request()->route('slug') ? 'active' : '' }}">
@ -32,4 +34,4 @@
{{-- <div class="close-nav-aside">
<i class="icon angle-left-icon close-icon"></i>
</div> --}}
</div>
</div>

View File

@ -129,6 +129,8 @@ class AttributeController extends Controller
*/
public function destroy($id)
{
dd(request()->all());
$attribute = $this->attribute->findOrFail($id);
if(!$attribute->is_user_defined) {
@ -187,4 +189,4 @@ class AttributeController extends Controller
return redirect()->back();
}
}
}
}

View File

@ -42,8 +42,14 @@
<td class="actions" style="width: 100px;" data-value=" {{ __('ui::app.datagrid.actions') }}">
<div>
@foreach ($actions as $action)
<a href="{{ route($action['route'], $record->{$index}) }}">
<span class="{{ $action['icon'] }}" @if(strtolower($action['type']) == "delete") onclick="return confirm('{{ __('ui::app.datagrid.click_on_action') }}')" @endif></span>
<a
@if($action['method'] != 'GET')
v-on:click="doAction($event)"
@endif
data-method="{{ $action['method'] }}"
data-action="{{ route($action['route'], $record->{$index}) }}"
data-token="{{ csrf_token() }}">
<span class="{{ $action['icon'] }}"></span>
</a>
@endforeach
</div>
@ -56,4 +62,4 @@
<td colspan="10" style="text-align: center;">{{ $norecords }}</td>
</tr>
@endif
</tbody>
</tbody>

View File

@ -615,18 +615,11 @@
label = 'cannotfindthislabel';
// for(colIndex in this.columns) {
// if (this.columns[colIndex].alias == this.columnOrAlias) {
// label = this.columns[colIndex].label;
// }
// }
obj.column = col;
obj.cond = cond;
obj.val = val;
if(col == "sort") {
// console.log('sort', obj.cond);
label = '';
for(colIndex in this.columns) {
@ -707,6 +700,14 @@
}
},
doAction(e) {
var element = e.currentTarget;
axios.post(element.getAttribute('data-action'), { '_method': element.getAttribute('data-method'), '_token': data-token }).then(response => (this.info = response));
e.preventDefault();
},
removeMassActions() {
this.dataIds = [];
@ -718,4 +719,4 @@
});
</script>
@endpush
</div>
</div>

View File

@ -29,6 +29,11 @@ class Bouncer
public function checkIfAuthorized($request)
{
$routeCollection = Route::getRoutes();
// dd($routeCollection->get()[0]);
//find the current route's aside parent and compare with role of current user
if (! $role = auth()->guard('admin')->user()->role)
abort(401, 'This action is unauthorized.');
@ -36,10 +41,10 @@ class Bouncer
return;
} else {
$acl = app('acl');
// dd($acl);
if ($acl && isset($acl->roles[Route::currentRouteName()])) {
bouncer()->allow($acl->roles[Route::currentRouteName()]);
}
}
}
}
}