A free open source IT asset/license management system
Added ManagedUsers method, additional checks in isDeletable()
snipef769e8247f27
diff --git a/app/Models/User.php b/app/Models/User.phpindex e535fa0fde..e30136703e 100644--- a/app/Models/User.php+++ b/app/Models/User.php@@ -214,10 +214,12 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCopublic function isDeletable(){return Gate::allows('delete', $this)- && ($this->assets()->count() === 0)- && ($this->licenses()->count() === 0)- && ($this->consumables()->count() === 0)- && ($this->accessories()->count() === 0)+ && ($this->assets->count() === 0)+ && ($this->licenses->count() === 0)+ && ($this->consumables->count() === 0)+ && ($this->accessories->count() === 0)+ && ($this->managedLocations->count() === 0)+ && ($this->managesUsers->count() === 0)&& ($this->deleted_at == '');}@@ -410,6 +412,19 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCoreturn $this->belongsTo(self::class, 'manager_id')->withTrashed();}+ /**+ * Establishes the user -> managed users relationship+ *+ * @author A. Gianotto <[email protected]>+ * @since [v6.4.1]+ * @return \Illuminate\Database\Eloquent\Relations\Relation+ */+ public function managesUsers()+ {+ return $this->hasMany(\App\Models\User::class, 'manager_id');+ }++/*** Establishes the user -> managed locations relationship*