Fix join private channel (#30875)
* Fix join private channel not showing on all needed scenarios * Fix for other two instances of the logic * Fix test --------- Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
c46ed6c681
Коммит
c1a0710ab5
@@ -179,9 +179,7 @@ describe('Actions', () => {
|
||||
...initialState.entities.users,
|
||||
profiles: {
|
||||
...initialState.entities.users.profiles,
|
||||
current_user_id: {
|
||||
roles: 'system_admin',
|
||||
},
|
||||
current_user_id: {},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -205,9 +203,7 @@ describe('Actions', () => {
|
||||
...initialState.entities.users,
|
||||
profiles: {
|
||||
...initialState.entities.users.profiles,
|
||||
current_user_id: {
|
||||
roles: 'system_user',
|
||||
},
|
||||
current_user_id: {},
|
||||
},
|
||||
},
|
||||
channels: {
|
||||
|
||||
@@ -10,9 +10,8 @@ import {joinChannel, getChannelByNameAndTeamName, getChannelMember, markGroupCha
|
||||
import {getUser, getUserByUsername, getUserByEmail} from 'mattermost-redux/actions/users';
|
||||
import {Client4} from 'mattermost-redux/client';
|
||||
import {getChannelByName, getOtherChannels, getChannel, getChannelsNameMapInTeam, getRedirectChannelNameForTeam} from 'mattermost-redux/selectors/entities/channels';
|
||||
import {getTeamByName, getMyTeamMember} from 'mattermost-redux/selectors/entities/teams';
|
||||
import {getCurrentUser, getCurrentUserId, getUserByUsername as selectUserByUsername, getUser as selectUser, getUserByEmail as selectUserByEmail} from 'mattermost-redux/selectors/entities/users';
|
||||
import * as UserUtils from 'mattermost-redux/utils/user_utils';
|
||||
import {getTeamByName} from 'mattermost-redux/selectors/entities/teams';
|
||||
import {getCurrentUserId, getUserByUsername as selectUserByUsername, getUser as selectUser, getUserByEmail as selectUserByEmail} from 'mattermost-redux/selectors/entities/users';
|
||||
|
||||
import {openDirectChannelToUserId} from 'actions/channel_actions';
|
||||
import * as GlobalActions from 'actions/global_actions';
|
||||
@@ -187,23 +186,13 @@ export function goToChannelByChannelName(match: Match, history: History): Action
|
||||
|
||||
if (!channel || !member) {
|
||||
if (channel?.type === Constants.PRIVATE_CHANNEL) {
|
||||
// Prompt system admins and team admins before joining the private channel
|
||||
const user = getCurrentUser(getState());
|
||||
const isSystemAdmin = UserUtils.isSystemAdmin(user?.roles);
|
||||
let prompt = false;
|
||||
if (isSystemAdmin) {
|
||||
prompt = true;
|
||||
} else {
|
||||
const teamMember = getMyTeamMember(state, teamObj.id);
|
||||
prompt = Boolean(teamMember && teamMember.scheme_admin);
|
||||
}
|
||||
if (prompt) {
|
||||
// If we are here, we have permissions to join the channel
|
||||
// and the channel is private. Therefore prompt always.
|
||||
const joinPromptResult = await dispatch(joinPrivateChannelPrompt(teamObj, channel.display_name));
|
||||
if ('data' in joinPromptResult && !joinPromptResult.data!.join) {
|
||||
return {data: undefined};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const joinChannelDispatchResult = await dispatch(joinChannel(getCurrentUserId(state), teamObj!.id, channel?.id || '', channelName));
|
||||
if ('error' in joinChannelDispatchResult) {
|
||||
|
||||
@@ -10,10 +10,8 @@ import {getMissingProfilesByIds} from 'mattermost-redux/actions/users';
|
||||
import {Client4} from 'mattermost-redux/client';
|
||||
import {getCurrentChannel, getChannel as getChannelFromRedux} from 'mattermost-redux/selectors/entities/channels';
|
||||
import {isCollapsedThreadsEnabled} from 'mattermost-redux/selectors/entities/preferences';
|
||||
import {getCurrentTeam, getTeam, getMyTeamMember} from 'mattermost-redux/selectors/entities/teams';
|
||||
import {getCurrentUser} from 'mattermost-redux/selectors/entities/users';
|
||||
import {getCurrentTeam, getTeam} from 'mattermost-redux/selectors/entities/teams';
|
||||
import {getUserIdFromChannelName} from 'mattermost-redux/utils/channel_utils';
|
||||
import {isSystemAdmin} from 'mattermost-redux/utils/user_utils';
|
||||
|
||||
import {loadChannelsForCurrentUser} from 'actions/channel_actions';
|
||||
import {loadNewDMIfNeeded, loadNewGMIfNeeded} from 'actions/user_actions';
|
||||
@@ -109,18 +107,10 @@ export function focusPost(postId: string, returnTo = '', currentUserId: string,
|
||||
}
|
||||
|
||||
if (!postInfo.has_joined_channel) {
|
||||
// Prompt system admins and team admins before joining the private channel
|
||||
const user = getCurrentUser(state);
|
||||
let prompt = false;
|
||||
if (postInfo.channel_type === Constants.PRIVATE_CHANNEL) {
|
||||
if (isSystemAdmin(user.roles)) {
|
||||
prompt = true;
|
||||
} else {
|
||||
const teamMember = getMyTeamMember(state, currentTeam.id);
|
||||
prompt = Boolean(teamMember && teamMember.scheme_admin);
|
||||
}
|
||||
}
|
||||
if (prompt) {
|
||||
// Prompt system admins and team admins before joining the private channel.
|
||||
// There is no need for permission check because if we received the info of
|
||||
// the post means that we can join the channel.
|
||||
privateChannelJoinPromptVisible = true;
|
||||
const joinPromptResult = await dispatch(joinPrivateChannelPrompt(currentTeam, postInfo.channel_display_name));
|
||||
privateChannelJoinPromptVisible = false;
|
||||
|
||||
@@ -23,6 +23,7 @@ import TestHelper from 'packages/mattermost-redux/test/test_helper';
|
||||
import {mountWithIntl} from 'tests/helpers/intl-test-helper';
|
||||
import mockStore from 'tests/test_store';
|
||||
import {getHistory} from 'utils/browser_history';
|
||||
import {joinPrivateChannelPrompt} from 'utils/channel_utils';
|
||||
import {ErrorPageTypes} from 'utils/constants';
|
||||
|
||||
jest.mock('actions/channel_actions', () => ({
|
||||
@@ -543,13 +544,7 @@ describe('components/PermalinkView', () => {
|
||||
},
|
||||
};
|
||||
|
||||
jest.mock('utils/channel_utils', () => ({
|
||||
joinPrivateChannelPrompt: jest.fn(() => {
|
||||
return async () => {
|
||||
return {data: {join: true}};
|
||||
};
|
||||
}),
|
||||
}));
|
||||
jest.mocked(joinPrivateChannelPrompt).mockReturnValueOnce(async () => ({data: {join: true}}));
|
||||
|
||||
const postId = 'privatepostid1';
|
||||
nockInfoForPrivatePost(postId);
|
||||
|
||||
@@ -1297,7 +1297,6 @@ export async function handleFormattedTextClick(e: React.MouseEvent, currentRelat
|
||||
|
||||
let isReply = false;
|
||||
|
||||
if (isSystemAdmin(user.roles)) {
|
||||
if (match) {
|
||||
// Get team by name
|
||||
const {teamName} = match;
|
||||
@@ -1360,7 +1359,6 @@ export async function handleFormattedTextClick(e: React.MouseEvent, currentRelat
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
e.stopPropagation();
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user