mirror of
https://github.com/snipe/snipe-it.git
synced 2025-02-02 08:21:09 -08:00
Added/refactorerd isDeletable()
Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
parent
f7ccef16e7
commit
19877244cd
|
@ -6,6 +6,7 @@ use App\Models\Traits\Searchable;
|
||||||
use App\Presenters\Presentable;
|
use App\Presenters\Presentable;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
use Illuminate\Support\Facades\Gate;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Watson\Validating\ValidatingTrait;
|
use Watson\Validating\ValidatingTrait;
|
||||||
|
|
||||||
|
@ -188,6 +189,21 @@ class AssetModel extends SnipeModel
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the model is deletable
|
||||||
|
*
|
||||||
|
* @author A. Gianotto <snipe@snipe.net>
|
||||||
|
* @since [v6.3.4]
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isDeletable()
|
||||||
|
{
|
||||||
|
return Gate::allows('delete', $this)
|
||||||
|
&& ($this->assets_count == 0)
|
||||||
|
&& ($this->deleted_at == '');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get uploads for this model
|
* Get uploads for this model
|
||||||
*
|
*
|
||||||
|
|
|
@ -100,7 +100,8 @@ class Category extends SnipeModel
|
||||||
{
|
{
|
||||||
|
|
||||||
return Gate::allows('delete', $this)
|
return Gate::allows('delete', $this)
|
||||||
&& ($this->itemCount() == 0);
|
&& ($this->itemCount() == 0)
|
||||||
|
&& ($this->deleted_at == '');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -77,7 +77,8 @@ class Manufacturer extends SnipeModel
|
||||||
&& ($this->assets()->count() === 0)
|
&& ($this->assets()->count() === 0)
|
||||||
&& ($this->licenses()->count() === 0)
|
&& ($this->licenses()->count() === 0)
|
||||||
&& ($this->consumables()->count() === 0)
|
&& ($this->consumables()->count() === 0)
|
||||||
&& ($this->accessories()->count() === 0);
|
&& ($this->accessories()->count() === 0)
|
||||||
|
&& ($this->deleted_at == '');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function assets()
|
public function assets()
|
||||||
|
|
|
@ -17,6 +17,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Foundation\Auth\Access\Authorizable;
|
use Illuminate\Foundation\Auth\Access\Authorizable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
|
use Illuminate\Support\Facades\Gate;
|
||||||
use Laravel\Passport\HasApiTokens;
|
use Laravel\Passport\HasApiTokens;
|
||||||
use Watson\Validating\ValidatingTrait;
|
use Watson\Validating\ValidatingTrait;
|
||||||
|
|
||||||
|
@ -201,6 +202,23 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||||
return $this->checkPermissionSection('superuser');
|
return $this->checkPermissionSection('superuser');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the user is deletable
|
||||||
|
*
|
||||||
|
* @author A. Gianotto <snipe@snipe.net>
|
||||||
|
* @since [v6.3.4]
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isDeletable()
|
||||||
|
{
|
||||||
|
return Gate::allows('delete', $this)
|
||||||
|
&& ($this->assets()->count() === 0)
|
||||||
|
&& ($this->licenses()->count() === 0)
|
||||||
|
&& ($this->consumables()->count() === 0)
|
||||||
|
&& ($this->accessories()->count() === 0)
|
||||||
|
&& ($this->deleted_at == '');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Establishes the user -> company relationship
|
* Establishes the user -> company relationship
|
||||||
|
|
Loading…
Reference in a new issue