mirror of
https://github.com/coollabsio/coolify.git
synced 2026-09-28 02:06:37 -04:00
fix(team): resolve stored team on deletion and impersonation
Use resolveStoredTeam() instead of teams()->first() when picking the next active team after a team deletion or when an admin switches into a user's account, so a valid stored preference wins over an arbitrary first team. DeleteTeam now returns null when the deletion leaves the owner with multiple teams, deferring to the selection screen instead of guessing. refreshSession also stops persisting current_team_id while impersonating, so viewing another user's account no longer overwrites their real last-active team.
This commit is contained in:
committed by
Andras Bacsai
parent
f511921895
commit
e52390ec03
@@ -60,7 +60,12 @@ class DeleteTeam
|
||||
|
||||
$team->delete();
|
||||
|
||||
return $user->teams()->first();
|
||||
// Resolve the next active team the same way login does: the user's
|
||||
// stored choice when still valid, or their sole remaining team.
|
||||
// Returns null for a multi-team user whose active team was just
|
||||
// deleted, so refreshSession sends them to the selection screen
|
||||
// instead of silently dropping them into an arbitrary first team.
|
||||
return User::query()->find($user->id)?->resolveStoredTeam();
|
||||
});
|
||||
|
||||
Cache::forget("user:{$user->id}:team:{$team->id}");
|
||||
|
||||
@@ -33,7 +33,7 @@ class Index extends Component
|
||||
if (session('impersonating')) {
|
||||
session()->forget('impersonating');
|
||||
$user = User::find(0);
|
||||
$team_to_switch_to = $user->teams->first();
|
||||
$team_to_switch_to = $user->resolveStoredTeam() ?? $user->teams->first();
|
||||
Auth::login($user);
|
||||
refreshSession($team_to_switch_to);
|
||||
|
||||
@@ -69,7 +69,7 @@ class Index extends Component
|
||||
if (! $user) {
|
||||
abort(404);
|
||||
}
|
||||
$team_to_switch_to = $user->teams->first();
|
||||
$team_to_switch_to = $user->resolveStoredTeam() ?? $user->teams->first();
|
||||
Auth::login($user);
|
||||
refreshSession($team_to_switch_to);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user