Improved - disallow delete if not elgible in UI

This commit is contained in:
snipe 2017-12-12 07:03:31 -08:00
parent 528630a8d3
commit 1ef44721f5
3 changed files with 15 additions and 4 deletions

View file

@ -22,10 +22,21 @@ class CompaniesController extends Controller
{ {
$this->authorize('view', Company::class); $this->authorize('view', Company::class);
$allowed_columns = ['id','name']; $allowed_columns = [
'id',
'name',
'created_at',
'updated_at',
'users_count',
'assets_count',
'licenses_count',
'accessories_count',
'consumables_count',
'components_count',
];
$companies = Company::withCount('assets','licenses','accessories','consumables','components','users') $companies = Company::withCount('assets','licenses','accessories','consumables','components','users')
->withCount('users')->withCount('users')->withCount('assets') ->withCount('users')->withCount('assets')
->withCount('licenses')->withCount('accessories') ->withCount('licenses')->withCount('accessories')
->withCount('consumables')->withCount('components'); ->withCount('consumables')->withCount('components');

View file

@ -47,7 +47,7 @@ class DepartmentsTransformer
$permissions_array['available_actions'] = [ $permissions_array['available_actions'] = [
'update' => Gate::allows('update', Department::class) ? true : false, 'update' => Gate::allows('update', Department::class) ? true : false,
'delete' => Gate::allows('delete', Department::class) ? true : false, 'delete' => (Gate::allows('delete', Department::class) && ($department->users_count==0) && ($department->deleted_at=='')) ? true : false,
]; ];
$array += $permissions_array; $array += $permissions_array;

View file

@ -57,7 +57,7 @@ class LocationsTransformer
$permissions_array['available_actions'] = [ $permissions_array['available_actions'] = [
'update' => Gate::allows('update', Location::class) ? true : false, 'update' => Gate::allows('update', Location::class) ? true : false,
'delete' => Gate::allows('delete', Location::class) ? true : false, 'delete' => (Gate::allows('delete', Department::class) && ($location->assigned_assets_count==0) && ($location->assets_count==0) && ($location->users_count==0) && ($location->deleted_at=='')) ? true : false,
]; ];
$array += $permissions_array; $array += $permissions_array;