From 3fb62722a47e66c12982d1dee11248e87871d268 Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Thu, 26 Jun 2025 12:51:42 +0200 Subject: [PATCH] Show correct username and email for remote users (#31205) Co-authored-by: Miguel de la Cruz --- .../components/profile_popover/profile_popover.tsx | 2 +- .../profile_popover/profile_popover_name.tsx | 4 +++- .../src/components/user_profile/user_profile.tsx | 4 ++-- .../mattermost-redux/src/utils/user_utils.test.ts | 5 +++++ .../mattermost-redux/src/utils/user_utils.ts | 2 +- webapp/channels/src/utils/utils.tsx | 14 ++++++++++++++ 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/webapp/channels/src/components/profile_popover/profile_popover.tsx b/webapp/channels/src/components/profile_popover/profile_popover.tsx index fbf184652b..67e4bb14b3 100644 --- a/webapp/channels/src/components/profile_popover/profile_popover.tsx +++ b/webapp/channels/src/components/profile_popover/profile_popover.tsx @@ -181,7 +181,7 @@ const ProfilePopover = ({ />
diff --git a/webapp/channels/src/components/profile_popover/profile_popover_name.tsx b/webapp/channels/src/components/profile_popover/profile_popover_name.tsx index 1c1300dc6c..f72965a544 100644 --- a/webapp/channels/src/components/profile_popover/profile_popover_name.tsx +++ b/webapp/channels/src/components/profile_popover/profile_popover_name.tsx @@ -10,6 +10,8 @@ import FullName from 'components/profile_popover/profile_popover_full_name'; import Position from 'components/profile_popover/profile_popover_position'; import UserName from 'components/profile_popover/profile_popover_user_name'; +import {getUsername} from 'utils/utils'; + type Props = { haveOverrideProp: boolean; user: UserProfile; @@ -34,7 +36,7 @@ const ProfilePopoverName = ({ )} {(user.position && !haveOverrideProp) && ( { nickname: 'nick', first_name: 'test', last_name: 'user', + props: {RemoteUsername: 'remoteTestUser'}, }); it('should return username', () => { @@ -54,6 +55,10 @@ describe('user utils', () => { expect(displayUsername(noUserObj, 'UNKNOWN_PREFERENCE')).toBe('Someone'); }); + it('should return remote username string if the user is remote', () => { + expect(displayUsername({...userObj, remote_id: 'remoteid'}, Preferences.DISPLAY_PREFER_USERNAME)).toBe('remoteTestUser'); + }); + it('should return empty string when user does not exist and useDefaultUserName param is false', () => { let noUserObj; expect(displayUsername(noUserObj, 'UNKNOWN_PREFERENCE', false)).toBe(''); diff --git a/webapp/channels/src/packages/mattermost-redux/src/utils/user_utils.ts b/webapp/channels/src/packages/mattermost-redux/src/utils/user_utils.ts index d0a3173d88..6799cc450e 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/utils/user_utils.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/utils/user_utils.ts @@ -34,7 +34,7 @@ export function displayUsername( } else if (teammateNameDisplay === Preferences.DISPLAY_PREFER_FULL_NAME) { name = getFullName(user); } else { - name = user.username; + name = (user.remote_id && user.props?.RemoteUsername) ? user.props.RemoteUsername : user.username; } if (!name || name.trim().length === 0) { diff --git a/webapp/channels/src/utils/utils.tsx b/webapp/channels/src/utils/utils.tsx index a772bddb6f..e552025623 100644 --- a/webapp/channels/src/utils/utils.tsx +++ b/webapp/channels/src/utils/utils.tsx @@ -949,6 +949,20 @@ function changeColor(colourIn: string, amt: number): string { return rgb; } +export function getUsername(user: UserProfile) { + if (user.remote_id && user.props?.RemoteUsername) { + return user.props.RemoteUsername; + } + return user.username; +} + +export function getEmail(user: UserProfile) { + if (user.remote_id && user.props?.RemoteEmail) { + return user.props?.RemoteEmail; + } + return user.email; +} + export function getFullName(user: UserProfile) { if (user.first_name && user.last_name) { return user.first_name + ' ' + user.last_name;