From 1b5a76af554a56fc51f823dffbc9d989f645c13d Mon Sep 17 00:00:00 2001 From: catalintomai <56169943+catalintomai@users.noreply.github.com> Date: Mon, 16 Jun 2025 13:09:09 +0200 Subject: [PATCH] MM-61437: [Shared Channels] Disable DM button from profile for shared channel user (#30903) --- .../profile_popover_other_user_row.test.tsx | 133 ++++++++++++++++++ .../profile_popover_other_user_row.tsx | 41 ++++-- .../channels/src/sass/components/_post.scss | 2 +- 3 files changed, 161 insertions(+), 15 deletions(-) create mode 100644 webapp/channels/src/components/profile_popover/profile_popover_other_user_row.test.tsx diff --git a/webapp/channels/src/components/profile_popover/profile_popover_other_user_row.test.tsx b/webapp/channels/src/components/profile_popover/profile_popover_other_user_row.test.tsx new file mode 100644 index 0000000000..8e8b64432d --- /dev/null +++ b/webapp/channels/src/components/profile_popover/profile_popover_other_user_row.test.tsx @@ -0,0 +1,133 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import {screen} from '@testing-library/react'; +import React from 'react'; + +import {renderWithContext} from 'tests/react_testing_utils'; +import {TestHelper} from 'utils/test_helper'; + +import type {GlobalState} from 'types/store'; + +import ProfilePopoverOtherUserRow from './profile_popover_other_user_row'; + +describe('components/ProfilePopoverOtherUserRow', () => { + const baseProps = { + user: TestHelper.getUserMock({id: 'user1'}), + fullname: 'User One', + currentUserId: 'currentUser', + haveOverrideProp: false, + handleShowDirectChannel: jest.fn(), + returnFocus: jest.fn(), + handleCloseModals: jest.fn(), + hide: jest.fn(), + }; + + const initialState = { + entities: { + general: { + config: { + FeatureFlagEnableSharedChannelsDMs: 'false', + }, + }, + }, + } as unknown as GlobalState; + + test('should show message button for regular users', () => { + renderWithContext( + , + initialState, + ); + + expect(screen.getByText('Message')).toBeInTheDocument(); + }); + + test('should show message button for remote users when EnableSharedChannelsDMs is enabled', () => { + const remoteUser = { + ...baseProps.user, + remote_id: 'remote1', + }; + + const state = { + ...initialState, + entities: { + ...initialState.entities, + general: { + ...initialState.entities?.general, + config: { + ...initialState.entities?.general?.config, + FeatureFlagEnableSharedChannelsDMs: 'true', + }, + }, + }, + }; + + renderWithContext( + , + state, + ); + + expect(screen.getByText('Message')).toBeInTheDocument(); + }); + + test('should hide message button for remote users when EnableSharedChannelsDMs is disabled', () => { + const remoteUser = { + ...baseProps.user, + remote_id: 'remote1', + }; + + const state = { + ...initialState, + entities: { + ...initialState.entities, + general: { + ...initialState.entities?.general, + config: { + ...initialState.entities?.general?.config, + FeatureFlagEnableSharedChannelsDMs: 'false', + }, + }, + }, + }; + + renderWithContext( + , + state, + ); + + expect(screen.queryByText('Message')).not.toBeInTheDocument(); + }); + + test('should show message button for local users when EnableSharedChannelsDMs is disabled', () => { + const state = { + ...initialState, + entities: { + ...initialState.entities, + general: { + ...initialState.entities?.general, + config: { + ...initialState.entities?.general?.config, + FeatureFlagEnableSharedChannelsDMs: 'false', + }, + }, + }, + }; + + renderWithContext( + , + state, + ); + + expect(screen.getByText('Message')).toBeInTheDocument(); + }); +}); diff --git a/webapp/channels/src/components/profile_popover/profile_popover_other_user_row.tsx b/webapp/channels/src/components/profile_popover/profile_popover_other_user_row.tsx index a7e8d07e96..39e969d14e 100644 --- a/webapp/channels/src/components/profile_popover/profile_popover_other_user_row.tsx +++ b/webapp/channels/src/components/profile_popover/profile_popover_other_user_row.tsx @@ -3,12 +3,17 @@ import React from 'react'; import {FormattedMessage} from 'react-intl'; +import {useSelector} from 'react-redux'; import type {UserProfile} from '@mattermost/types/users'; +import {getFeatureFlagValue} from 'mattermost-redux/selectors/entities/general'; + import ProfilePopoverAddToChannel from 'components/profile_popover/profile_popover_add_to_channel'; import ProfilePopoverCallButtonWrapper from 'components/profile_popover/profile_popover_call_button_wrapper'; +import type {GlobalState} from 'types/store'; + type Props = { user: UserProfile; fullname: string; @@ -30,26 +35,34 @@ const ProfilePopoverOtherUserRow = ({ hide, fullname, }: Props) => { + const isSharedChannelsDMsEnabled = useSelector((state: GlobalState) => getFeatureFlagValue(state, 'EnableSharedChannelsDMs') === 'true'); + if (user.id === currentUserId || haveOverrideProp) { return null; } + // Hide Message button for remote users when EnableSharedChannelsDMs feature flag is off + const isRemoteUser = Boolean(user.remote_id); + const showMessageButton = isSharedChannelsDMsEnabled || !isRemoteUser; + return (
-