fix(models): improve user deletion logic in User model to handle team member roles and prevent deletion if user is alone in root team
This commit is contained in:
parent
ac4324e682
commit
24b6b32025
1 changed files with 44 additions and 43 deletions
|
|
@ -74,7 +74,7 @@ protected static function boot()
|
||||||
});
|
});
|
||||||
|
|
||||||
static::deleting(function (User $user) {
|
static::deleting(function (User $user) {
|
||||||
|
\DB::transaction(function () use ($user) {
|
||||||
$teams = $user->teams;
|
$teams = $user->teams;
|
||||||
foreach ($teams as $team) {
|
foreach ($teams as $team) {
|
||||||
$user_alone_in_team = $team->members->count() === 1;
|
$user_alone_in_team = $team->members->count() === 1;
|
||||||
|
|
@ -124,6 +124,7 @@ protected static function boot()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue