Skip to content

A free open source IT asset/license management system

Added isDeletable() method

snipe50cf15fb712b
diff --git a/app/Models/Department.php b/app/Models/Department.php
index 7e8b848cb4..3e9a538146 100644
--- a/app/Models/Department.php
+++ b/app/Models/Department.php
@@ -7,6 +7,7 @@ use App\Models\Traits\CompanyableTrait;
use App\Models\Traits\Searchable;
use App\Presenters\Presentable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
+use Illuminate\Support\Facades\Gate;
use Watson\Validating\ValidatingTrait;
class Department extends SnipeModel
@@ -77,6 +78,13 @@ class Department extends SnipeModel
*/
protected $searchableRelations = [];
+
+ public function isDeletable()
+ {
+ return Gate::allows('delete', $this) && (($this->users_count ?? $this->users()->count()) === 0);
+ }
+
+
/**
* Establishes the department -> company relationship
*
diff --git a/app/Models/Statuslabel.php b/app/Models/Statuslabel.php
index 049b8d7de1..e1293ec07d 100755
--- a/app/Models/Statuslabel.php
+++ b/app/Models/Statuslabel.php
@@ -4,21 +4,27 @@ namespace App\Models;
use App\Http\Traits\UniqueUndeletedTrait;
use App\Models\Traits\Searchable;
+use App\Presenters\Presentable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
+use Illuminate\Support\Facades\Gate;
use Watson\Validating\ValidatingTrait;
+
class Statuslabel extends SnipeModel
{
use HasFactory;
use SoftDeletes;
use ValidatingTrait;
use UniqueUndeletedTrait;
+ use Presentable;
protected $injectUniqueIdentifier = true;
protected $table = 'status_labels';
protected $hidden = ['user_id', 'deleted_at'];
+ protected $presenter = \App\Presenters\StatusLabelPresenter::class;
+
protected $rules = [
'name' => 'required|max:255|string|unique_undeleted',
@@ -52,6 +58,13 @@ class Statuslabel extends SnipeModel
*/
protected $searchableRelations = [];
+ public function isDeletable()
+ {
+ return Gate::allows('delete', $this)
+ && (($this->assets_count ?? $this->assets()->count()) === 0)
+ && ($this->deleted_at == '');
+ }
+
/**
* Establishes the status label -> assets relationship
*