filter remote users if remote dms not supported (#28953)
* filter remote users if remote dms not supported * move filter to selectors * lint fix * add test * add filter to search
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
4f88eabfba
Коммит
a65ba84697
@@ -0,0 +1,91 @@
|
|||||||
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||||
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
|
import {TestHelper} from 'utils/test_helper';
|
||||||
|
|
||||||
|
import type {GlobalState} from 'types/store';
|
||||||
|
|
||||||
|
import {makeMapStateToProps} from './index';
|
||||||
|
|
||||||
|
describe('mapStateToProps', () => {
|
||||||
|
const mockedUser = TestHelper.getUserMock();
|
||||||
|
const currentTeamId = 'team-id';
|
||||||
|
const currentUserId = 'user-id';
|
||||||
|
|
||||||
|
const initialState = {
|
||||||
|
entities: {
|
||||||
|
users: {
|
||||||
|
currentUserId,
|
||||||
|
profiles: {
|
||||||
|
mockedUser_1: {
|
||||||
|
...mockedUser,
|
||||||
|
id: 'mockedUser_1',
|
||||||
|
remote_id: 'remote',
|
||||||
|
},
|
||||||
|
mockedUser_2: {
|
||||||
|
...mockedUser,
|
||||||
|
id: 'mockedUser_2',
|
||||||
|
remote_id: 'remote',
|
||||||
|
},
|
||||||
|
mockedUser_3: {
|
||||||
|
...mockedUser,
|
||||||
|
id: 'mockedUser_3',
|
||||||
|
},
|
||||||
|
mockedUser_4: {
|
||||||
|
...mockedUser,
|
||||||
|
id: 'mockedUser_4',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
profilesInTeam: {
|
||||||
|
[currentTeamId]: [
|
||||||
|
'mockedUser_1',
|
||||||
|
'mockedUser_2',
|
||||||
|
'mockedUser_3',
|
||||||
|
'mockedUser_4',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
teams: {
|
||||||
|
currentTeamId,
|
||||||
|
teams: {
|
||||||
|
[currentTeamId]: {
|
||||||
|
id: currentTeamId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
general: {
|
||||||
|
config: {
|
||||||
|
FeatureFlagEnableSharedChannelsDMs: 'false',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
views: {
|
||||||
|
search: {
|
||||||
|
modalSearch: '',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as unknown as GlobalState;
|
||||||
|
|
||||||
|
test('should not include remote users', () => {
|
||||||
|
const f = makeMapStateToProps();
|
||||||
|
const props = f(initialState, {isExistingChannel: false});
|
||||||
|
expect(props.users.length).toEqual(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should include remote users', () => {
|
||||||
|
const testState = {
|
||||||
|
...initialState,
|
||||||
|
entities: {
|
||||||
|
...initialState.entities,
|
||||||
|
general: {
|
||||||
|
config: {
|
||||||
|
FeatureFlagEnableSharedChannelsDMs: 'true',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
} as unknown as GlobalState;
|
||||||
|
const f = makeMapStateToProps();
|
||||||
|
const props = f(testState, {isExistingChannel: false});
|
||||||
|
expect(props.users.length).toEqual(4);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -14,7 +14,7 @@ import {
|
|||||||
getTotalUsersStats,
|
getTotalUsersStats,
|
||||||
searchProfiles,
|
searchProfiles,
|
||||||
} from 'mattermost-redux/actions/users';
|
} from 'mattermost-redux/actions/users';
|
||||||
import {getConfig} from 'mattermost-redux/selectors/entities/general';
|
import {getConfig, getFeatureFlagValue} from 'mattermost-redux/selectors/entities/general';
|
||||||
import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams';
|
import {getCurrentTeam} from 'mattermost-redux/selectors/entities/teams';
|
||||||
import {
|
import {
|
||||||
getCurrentUserId,
|
getCurrentUserId,
|
||||||
@@ -39,7 +39,7 @@ type OwnProps = {
|
|||||||
isExistingChannel: boolean;
|
isExistingChannel: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const makeMapStateToProps = () => {
|
export const makeMapStateToProps = () => {
|
||||||
const searchProfilesStartingWithTerm = makeSearchProfilesStartingWithTerm();
|
const searchProfilesStartingWithTerm = makeSearchProfilesStartingWithTerm();
|
||||||
|
|
||||||
return (state: GlobalState, ownProps: OwnProps) => {
|
return (state: GlobalState, ownProps: OwnProps) => {
|
||||||
@@ -54,17 +54,23 @@ const makeMapStateToProps = () => {
|
|||||||
|
|
||||||
const searchTerm = state.views.search.modalSearch;
|
const searchTerm = state.views.search.modalSearch;
|
||||||
|
|
||||||
|
let filters;
|
||||||
|
const enableSharedChannelsDMs = getFeatureFlagValue(state, 'EnableSharedChannelsDMs') === 'true';
|
||||||
|
if (!enableSharedChannelsDMs) {
|
||||||
|
filters = {exclude_remote: true};
|
||||||
|
}
|
||||||
|
|
||||||
let users: UserProfile[];
|
let users: UserProfile[];
|
||||||
if (searchTerm) {
|
if (searchTerm) {
|
||||||
if (restrictDirectMessage === 'any') {
|
if (restrictDirectMessage === 'any') {
|
||||||
users = searchProfilesStartingWithTerm(state, searchTerm, false);
|
users = searchProfilesStartingWithTerm(state, searchTerm, false, filters);
|
||||||
} else {
|
} else {
|
||||||
users = searchProfilesInCurrentTeam(state, searchTerm, false);
|
users = searchProfilesInCurrentTeam(state, searchTerm, false, filters);
|
||||||
}
|
}
|
||||||
} else if (restrictDirectMessage === 'any') {
|
} else if (restrictDirectMessage === 'any') {
|
||||||
users = selectProfiles(state);
|
users = selectProfiles(state, filters);
|
||||||
} else {
|
} else {
|
||||||
users = getProfilesInCurrentTeam(state);
|
users = getProfilesInCurrentTeam(state, filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
const team = getCurrentTeam(state);
|
const team = getCurrentTeam(state);
|
||||||
|
|||||||
@@ -293,10 +293,87 @@ describe('Selectors.Users', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getProfilesInCurrentTeam', () => {
|
||||||
it('getProfilesInCurrentTeam', () => {
|
it('getProfilesInCurrentTeam', () => {
|
||||||
const users = [user1, user2, user7].sort(sortByUsername);
|
const users = [user1, user2, user7].sort(sortByUsername);
|
||||||
expect(Selectors.getProfilesInCurrentTeam(testState)).toEqual(users);
|
expect(Selectors.getProfilesInCurrentTeam(testState)).toEqual(users);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const remoteUser = TestHelper.fakeUserWithId();
|
||||||
|
remoteUser.remote_id = 'remoteID';
|
||||||
|
const state = {
|
||||||
|
...testState,
|
||||||
|
entities: {
|
||||||
|
...testState.entities,
|
||||||
|
users: {
|
||||||
|
...testState.entities.users,
|
||||||
|
profiles: {
|
||||||
|
...testState.entities.users.profiles,
|
||||||
|
[remoteUser.id]: remoteUser,
|
||||||
|
},
|
||||||
|
profilesInTeam: {
|
||||||
|
...testState.entities.users.profilesInTeam,
|
||||||
|
[team1.id]: new Set([...testState.entities.users.profilesInTeam[team1.id], remoteUser.id]),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
teams: {
|
||||||
|
...testState.teams,
|
||||||
|
currentTeamId: team1.id,
|
||||||
|
membersInTeam,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
it('getProfilesInCurrentTeam include remote', () => {
|
||||||
|
const users = [user1, user2, user7, remoteUser].sort(sortByUsername);
|
||||||
|
expect(Selectors.getProfilesInCurrentTeam(state)).toEqual(users);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getProfilesInCurrentTeam with remote filter', () => {
|
||||||
|
const users = [user1, user2, user7].sort(sortByUsername);
|
||||||
|
const filters = {exclude_remote: true};
|
||||||
|
expect(Selectors.getProfilesInCurrentTeam(state, filters)).toEqual(users);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('getProfilesNotInCurrentChannel', () => {
|
||||||
|
it('getProfilesNotInCurrentChannel', () => {
|
||||||
|
const users = [user2, user3].sort(sortByUsername);
|
||||||
|
expect(Selectors.getProfilesNotInCurrentChannel(testState)).toEqual(users);
|
||||||
|
});
|
||||||
|
|
||||||
|
const remoteUser = TestHelper.fakeUserWithId();
|
||||||
|
remoteUser.remote_id = 'remoteID';
|
||||||
|
const state = {
|
||||||
|
...testState,
|
||||||
|
entities: {
|
||||||
|
...testState.entities,
|
||||||
|
users: {
|
||||||
|
...testState.entities.users,
|
||||||
|
profiles: {
|
||||||
|
...testState.entities.users.profiles,
|
||||||
|
[remoteUser.id]: remoteUser,
|
||||||
|
},
|
||||||
|
profilesNotInChannel: {
|
||||||
|
...testState.entities.users.profilesNotInChannel,
|
||||||
|
[channel1.id]: new Set([...testState.entities.users.profilesNotInChannel[channel1.id], remoteUser.id]),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
it('getProfilesNotInCurrentChannel include remote', () => {
|
||||||
|
const users = [user2, user3, remoteUser].sort(sortByUsername);
|
||||||
|
expect(Selectors.getProfilesNotInCurrentChannel(state)).toEqual(users);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('getProfilesNotInCurrentChannel with remote filter', () => {
|
||||||
|
const users = [user2, user3].sort(sortByUsername);
|
||||||
|
const filters = {exclude_remote: true};
|
||||||
|
expect(Selectors.getProfilesNotInCurrentChannel(state, filters)).toEqual(users);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('getProfilesInTeam', () => {
|
describe('getProfilesInTeam', () => {
|
||||||
it('getProfilesInTeam without filter', () => {
|
it('getProfilesInTeam without filter', () => {
|
||||||
const users = [user1, user2, user7].sort(sortByUsername);
|
const users = [user1, user2, user7].sort(sortByUsername);
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ export type Filters = {
|
|||||||
channel_roles?: string[];
|
channel_roles?: string[];
|
||||||
team_roles?: string[];
|
team_roles?: string[];
|
||||||
exclude_bots?: boolean;
|
exclude_bots?: boolean;
|
||||||
|
exclude_remote?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getUserIdsInChannels(state: GlobalState): RelationOneToManyUnique<Channel, UserProfile> {
|
export function getUserIdsInChannels(state: GlobalState): RelationOneToManyUnique<Channel, UserProfile> {
|
||||||
@@ -334,6 +335,10 @@ export function filterProfiles(profiles: IDMappedObjects<UserProfile>, filters?:
|
|||||||
users = users.filter((user) => user.delete_at === 0);
|
users = users.filter((user) => user.delete_at === 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (filters.exclude_remote) {
|
||||||
|
users = users.filter((user) => !user.remote_id);
|
||||||
|
}
|
||||||
|
|
||||||
return users.reduce((acc, user) => {
|
return users.reduce((acc, user) => {
|
||||||
acc[user.id] = user;
|
acc[user.id] = user;
|
||||||
return acc;
|
return acc;
|
||||||
@@ -371,21 +376,23 @@ export const getActiveProfilesInCurrentChannelWithoutSorting: (state: GlobalStat
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
export const getProfilesNotInCurrentChannel: (state: GlobalState) => UserProfile[] = createSelector(
|
export const getProfilesNotInCurrentChannel: (state: GlobalState, filters?: Filters) => UserProfile[] = createSelector(
|
||||||
'getProfilesNotInCurrentChannel',
|
'getProfilesNotInCurrentChannel',
|
||||||
getUsers,
|
getUsers,
|
||||||
getProfileSetNotInCurrentChannel,
|
getProfileSetNotInCurrentChannel,
|
||||||
(profiles, notInCurrentChannelProfileSet) => {
|
(state: GlobalState, filters?: Filters) => filters,
|
||||||
return sortAndInjectProfiles(profiles, notInCurrentChannelProfileSet);
|
(profiles, notInCurrentChannelProfileSet, filters) => {
|
||||||
|
return sortAndInjectProfiles(filterProfiles(profiles, filters), notInCurrentChannelProfileSet);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
export const getProfilesInCurrentTeam: (state: GlobalState) => UserProfile[] = createSelector(
|
export const getProfilesInCurrentTeam: (state: GlobalState, filters?: Filters) => UserProfile[] = createSelector(
|
||||||
'getProfilesInCurrentTeam',
|
'getProfilesInCurrentTeam',
|
||||||
getUsers,
|
getUsers,
|
||||||
getProfileSetInCurrentTeam,
|
getProfileSetInCurrentTeam,
|
||||||
(profiles, currentTeamProfileSet) => {
|
(state: GlobalState, filters?: Filters) => filters,
|
||||||
return sortAndInjectProfiles(profiles, currentTeamProfileSet);
|
(profiles, currentTeamProfileSet, filters) => {
|
||||||
|
return sortAndInjectProfiles(filterProfiles(profiles, filters), currentTeamProfileSet);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -524,8 +531,8 @@ export function searchProfilesNotInCurrentChannel(state: GlobalState, term: stri
|
|||||||
return profiles;
|
return profiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function searchProfilesInCurrentTeam(state: GlobalState, term: string, skipCurrent = false): UserProfile[] {
|
export function searchProfilesInCurrentTeam(state: GlobalState, term: string, skipCurrent = false, filters?: Filters): UserProfile[] {
|
||||||
const profiles = filterProfilesStartingWithTerm(getProfilesInCurrentTeam(state), term);
|
const profiles = filterProfilesStartingWithTerm(getProfilesInCurrentTeam(state, filters), term);
|
||||||
if (skipCurrent) {
|
if (skipCurrent) {
|
||||||
removeCurrentUserFromList(profiles, getCurrentUserId(state));
|
removeCurrentUserFromList(profiles, getCurrentUserId(state));
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user