mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Added Company policy to fix company deletion issue
This commit is contained in:
parent
2c722ffc4f
commit
c242abb42e
|
@ -38,7 +38,7 @@ class CompaniesTransformer
|
|||
|
||||
$permissions_array['available_actions'] = [
|
||||
'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;
|
||||
|
|
13
app/Policies/CompanyPolicy.php
Normal file
13
app/Policies/CompanyPolicy.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Policies\SnipePermissionsPolicy;
|
||||
|
||||
class CompanyPolicy extends SnipePermissionsPolicy
|
||||
{
|
||||
protected function columnName()
|
||||
{
|
||||
return 'companies';
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ use App\Models\Location;
|
|||
use App\Models\Statuslabel;
|
||||
use App\Models\Supplier;
|
||||
use App\Models\Manufacturer;
|
||||
use App\Models\Company;
|
||||
use App\Models\User;
|
||||
use App\Policies\AccessoryPolicy;
|
||||
use App\Policies\AssetModelPolicy;
|
||||
|
@ -30,6 +31,7 @@ use App\Policies\StatuslabelPolicy;
|
|||
use App\Policies\SupplierPolicy;
|
||||
use App\Policies\UserPolicy;
|
||||
use App\Policies\ManufacturerPolicy;
|
||||
use App\Policies\CompanyPolicy;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
@ -59,6 +61,7 @@ class AuthServiceProvider extends ServiceProvider
|
|||
Supplier::class => SupplierPolicy::class,
|
||||
User::class => UserPolicy::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\Company::class)
|
||||
|| $user->can('view', \App\Models\Manufacturer::class)
|
||||
|| $user->can('view', \App\Models\Company::class)
|
||||
|| $user->can('view', \App\Models\Depreciation::class);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
),
|
||||
),
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue