Skip to content

Commit

Permalink
[Assist] Fix random user selection (#26183)
Browse files Browse the repository at this point in the history
Currently, after selecting a user for command execution in Teleport Assist the user can randomly change. This PR fixes this behavior.
  • Loading branch information
jakule committed Jun 2, 2023
1 parent d5af6aa commit bf000a0
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion web/packages/teleport/src/Assist/contexts/messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,22 @@ export const remoteCommandToMessage = async (
errorMsg = 'no users found';
}

// If the login has been selected, use it.
let avLogin = execCmd.selectedLogin;
if (!avLogin) {
// If the login has not been selected, use the first one.
avLogin = availableLogins ? availableLogins[0] : '';
} else {
// If the login has been selected, check if it is available.
// Updated query could have changed the available logins.
if (!availableLogins.includes(avLogin)) {
avLogin = availableLogins ? availableLogins[0] : '';
}
}

return {
...execCmd,
selectedLogin: availableLogins ? availableLogins[0] : '',
selectedLogin: avLogin,
availableLogins: availableLogins,
errorMsg: errorMsg,
};
Expand Down

0 comments on commit bf000a0

Please sign in to comment.