Added Company policy to fix company deletion issue

This commit is contained in:
snipe 2018-01-19 17:51:28 -08:00
parent 2c722ffc4f
commit c242abb42e
4 changed files with 45 additions and 1 deletions

View file

@ -38,7 +38,7 @@ class CompaniesTransformer
$permissions_array['available_actions'] = [ $permissions_array['available_actions'] = [
'update' => Gate::allows('update', Company::class) ? true : false, 'update' => Gate::allows('update', Company::class) ? true : false,
'delete' => (Gate::allows('delete', Category::class) && ($company->assets_count == 0) && ($company->accessories_count == 0) && ($company->consumables_count == 0) && ($company->components_count == 0) && ($company->users_count == 0)) ? true : false, 'delete' => (Gate::allows('delete', Company::class) && ($company->assets_count == 0) && ($company->accessories_count == 0) && ($company->consumables_count == 0) && ($company->components_count == 0) && ($company->users_count == 0)) ? true : false,
]; ];
$array += $permissions_array; $array += $permissions_array;

View file

@ -0,0 +1,13 @@
<?php
namespace App\Policies;
use App\Policies\SnipePermissionsPolicy;
class CompanyPolicy extends SnipePermissionsPolicy
{
protected function columnName()
{
return 'companies';
}
}

View file

@ -15,6 +15,7 @@ use App\Models\Location;
use App\Models\Statuslabel; use App\Models\Statuslabel;
use App\Models\Supplier; use App\Models\Supplier;
use App\Models\Manufacturer; use App\Models\Manufacturer;
use App\Models\Company;
use App\Models\User; use App\Models\User;
use App\Policies\AccessoryPolicy; use App\Policies\AccessoryPolicy;
use App\Policies\AssetModelPolicy; use App\Policies\AssetModelPolicy;
@ -30,6 +31,7 @@ use App\Policies\StatuslabelPolicy;
use App\Policies\SupplierPolicy; use App\Policies\SupplierPolicy;
use App\Policies\UserPolicy; use App\Policies\UserPolicy;
use App\Policies\ManufacturerPolicy; use App\Policies\ManufacturerPolicy;
use App\Policies\CompanyPolicy;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate; use Illuminate\Support\Facades\Gate;
@ -59,6 +61,7 @@ class AuthServiceProvider extends ServiceProvider
Supplier::class => SupplierPolicy::class, Supplier::class => SupplierPolicy::class,
User::class => UserPolicy::class, User::class => UserPolicy::class,
Manufacturer::class => ManufacturerPolicy::class, Manufacturer::class => ManufacturerPolicy::class,
Company::class => CompanyPolicy::class,
]; ];
/** /**
@ -132,6 +135,7 @@ class AuthServiceProvider extends ServiceProvider
|| $user->can('view', \App\Models\Location::class) || $user->can('view', \App\Models\Location::class)
|| $user->can('view', \App\Models\Company::class) || $user->can('view', \App\Models\Company::class)
|| $user->can('view', \App\Models\Manufacturer::class) || $user->can('view', \App\Models\Manufacturer::class)
|| $user->can('view', \App\Models\Company::class)
|| $user->can('view', \App\Models\Depreciation::class); || $user->can('view', \App\Models\Depreciation::class);
}); });
} }

View file

@ -521,6 +521,33 @@ return array(
), ),
), ),
'Companies' => array(
array(
'permission' => 'companies.view',
'label' => 'View ',
'note' => '',
'display' => true,
),
array(
'permission' => 'companies.create',
'label' => 'Create ',
'note' => '',
'display' => true,
),
array(
'permission' => 'companies.edit',
'label' => 'Edit ',
'note' => '',
'display' => true,
),
array(
'permission' => 'companies.delete',
'label' => 'Delete ',
'note' => '',
'display' => true,
),
),