Skip to content

Commit

Permalink
[mattermostGH-7494] Implement the system_admin and inactive filters f…
Browse files Browse the repository at this point in the history
…or users under system console (mattermost#2230)

* 7494 added the ui element for the options select

* mattermostGH-7494 added wired up the redux action and reducer for the filter parameter

* 7494 modified the selectors to respect the filters

* 7494 changed the label from filter to User status

* 7494 fixed the review comments
  • Loading branch information
pradeepmurugesan authored and grundleborg committed Jan 28, 2019
1 parent f45f3de commit b1c7fc7
Show file tree
Hide file tree
Showing 17 changed files with 187 additions and 40 deletions.
4 changes: 2 additions & 2 deletions actions/user_actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@ export async function uploadProfileImage(userPicture, success, error) {
}
}

export async function loadProfiles(page, perPage, success) {
const {data} = await UserActions.getProfiles(page, perPage)(dispatch, getState);
export async function loadProfiles(page, perPage, options = {}, success) {
const {data} = await UserActions.getProfiles(page, perPage, options)(dispatch, getState);
if (success) {
success(data);
}
Expand Down
4 changes: 2 additions & 2 deletions actions/views/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export function setModalSearchTerm(term) {
};
}

export function setSystemUsersSearch(term, team = '') {
export function setSystemUsersSearch(term, team, filter = '') {
return async (dispatch) => {
dispatch({
type: SearchTypes.SET_SYSTEM_USERS_SEARCH,
data: {term, team},
data: {term, team, filter},
});
return {data: true};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ exports[`components/admin_console/system_users should match default snapshot 1`]
<Connect(SystemUsersList)
enableUserAccessTokens={false}
experimentalEnableAuthenticationTransfer={false}
filter=""
loading={true}
mfaEnabled={false}
nextPage={[Function]}
Expand Down
3 changes: 3 additions & 0 deletions components/admin_console/system_users/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ function mapStateToProps(state) {
let totalUsers = 0;
let searchTerm = '';
let teamId = '';
let filter = '';
if (search) {
searchTerm = search.term || '';
teamId = search.team || '';
filter = search.filter || '';

if (!teamId || teamId === SearchUserTeamFilter.ALL_USERS) {
const stats = state.entities.admin.analytics || {[Stats.TOTAL_USERS]: 0, [Stats.TOTAL_INACTIVE_USERS]: 0};
Expand All @@ -52,6 +54,7 @@ function mapStateToProps(state) {
totalUsers,
searchTerm,
teamId,
filter,
enableUserAccessTokens,
users: getUsers(state),
experimentalEnableAuthenticationTransfer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ exports[`components/admin_console/system_users/list should match default snapsho
enableUserAccessTokens={false}
experimentalEnableAuthenticationTransfer={false}
extraInfo={Object {}}
filter=""
focusOnMount={false}
mfaEnabled={false}
nextPage={[Function]}
Expand Down Expand Up @@ -143,6 +144,7 @@ exports[`components/admin_console/system_users/list should match default snapsho
],
}
}
filter=""
focusOnMount={false}
mfaEnabled={false}
nextPage={[Function]}
Expand Down Expand Up @@ -308,6 +310,7 @@ exports[`components/admin_console/system_users/list should match default snapsho
],
}
}
filter=""
focusOnMount={false}
mfaEnabled={true}
nextPage={[Function]}
Expand Down
2 changes: 1 addition & 1 deletion components/admin_console/system_users/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {getUsers} from './selectors.jsx';

function mapStateToProps(state, ownProps) {
return {
users: getUsers(state, ownProps.loading, ownProps.teamId, ownProps.term),
users: getUsers(state, ownProps.loading, ownProps.teamId, ownProps.term, ownProps.filter),
};
}

Expand Down
16 changes: 9 additions & 7 deletions components/admin_console/system_users/list/selectors.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@

import {getUser, getProfiles, getProfilesInTeam, getProfilesWithoutTeam, searchProfiles, searchProfilesInTeam} from 'mattermost-redux/selectors/entities/users';

import {getFilterOptions} from 'utils/get_users';

const ALL_USERS = '';
const NO_TEAM = 'no_team';
const USER_ID_LENGTH = 26;

export function getUsers(state, loading, teamId, term) {
export function getUsers(state, loading, teamId, term, filter) {
if (loading) {
// Show no users while loading.
return [];
}

const filters = getFilterOptions(filter);
if (term) {
let users = [];
if (teamId) {
users = searchProfilesInTeam(state, teamId, term);
users = searchProfilesInTeam(state, teamId, term, false, filters);
} else {
users = searchProfiles(state, term);
users = searchProfiles(state, term, false, filters);
}

if (users.length === 0 && term.length === USER_ID_LENGTH) {
Expand All @@ -32,10 +34,10 @@ export function getUsers(state, loading, teamId, term) {
}

if (teamId === ALL_USERS) {
return getProfiles(state);
return getProfiles(state, filters);
} else if (teamId === NO_TEAM) {
return getProfilesWithoutTeam(state);
return getProfilesWithoutTeam(state, filters);
}

return getProfilesInTeam(state, teamId);
return getProfilesInTeam(state, teamId, filters);
}
57 changes: 47 additions & 10 deletions components/admin_console/system_users/list/selectors.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('components/admin_console/system_users/list/selectors', () => {
users.searchProfiles.mockReturnValue(expectedUsers);

expect(getUsers(state, loading, teamId, term)).toEqual(expectedUsers);
expect(users.searchProfiles).toBeCalledWith(state, term);
expect(users.searchProfiles).toBeCalledWith(state, term, false, {});
});

describe('falling back to fetching user by id', () => {
Expand All @@ -43,7 +43,7 @@ describe('components/admin_console/system_users/list/selectors', () => {
users.getUser.mockReturnValue(expectedUsers[0]);

expect(getUsers(state, loading, teamId, term)).toEqual(expectedUsers);
expect(users.searchProfiles).toBeCalledWith(state, term);
expect(users.searchProfiles).toBeCalledWith(state, term, false, {});
expect(users.getUser).toBeCalledWith(state, term);
});

Expand All @@ -53,7 +53,7 @@ describe('components/admin_console/system_users/list/selectors', () => {
users.getUser.mockReturnValue(null);

expect(getUsers(state, loading, teamId, term)).toEqual(expectedUsers);
expect(users.searchProfiles).toBeCalledWith(state, term);
expect(users.searchProfiles).toBeCalledWith(state, term, false, {});
expect(users.getUser).toBeCalledWith(state, term);
});
});
Expand All @@ -69,7 +69,7 @@ describe('components/admin_console/system_users/list/selectors', () => {
users.searchProfilesInTeam.mockReturnValue(expectedUsers);

expect(getUsers(state, loading, teamId, term)).toEqual(expectedUsers);
expect(users.searchProfilesInTeam).toBeCalledWith(state, teamId, term);
expect(users.searchProfilesInTeam).toBeCalledWith(state, teamId, term, false, {});
});

describe('falling back to fetching user by id', () => {
Expand All @@ -81,7 +81,7 @@ describe('components/admin_console/system_users/list/selectors', () => {
users.getUser.mockReturnValue(expectedUsers[0]);

expect(getUsers(state, loading, teamId, term)).toEqual(expectedUsers);
expect(users.searchProfilesInTeam).toBeCalledWith(state, teamId, term);
expect(users.searchProfilesInTeam).toBeCalledWith(state, teamId, term, false, {});
expect(users.getUser).toBeCalledWith(state, term);
});

Expand All @@ -91,7 +91,7 @@ describe('components/admin_console/system_users/list/selectors', () => {
users.getUser.mockReturnValue(null);

expect(getUsers(state, loading, teamId, term)).toEqual(expectedUsers);
expect(users.searchProfilesInTeam).toBeCalledWith(state, teamId, term);
expect(users.searchProfilesInTeam).toBeCalledWith(state, teamId, term, false, {});
expect(users.getUser).toBeCalledWith(state, term);
});
});
Expand All @@ -109,7 +109,7 @@ describe('components/admin_console/system_users/list/selectors', () => {
users.getProfiles.mockReturnValue(expectedUsers);

expect(getUsers(state, loading, teamId, term)).toEqual(expectedUsers);
expect(users.getProfiles).toBeCalledWith(state);
expect(users.getProfiles).toBeCalledWith(state, {});
});

it('profiles without a team', () => {
Expand All @@ -119,17 +119,54 @@ describe('components/admin_console/system_users/list/selectors', () => {
users.getProfilesWithoutTeam.mockReturnValue(expectedUsers);

expect(getUsers(state, loading, teamId, term)).toEqual(expectedUsers);
expect(users.getProfilesWithoutTeam).toBeCalledWith(state);
expect(users.getProfilesWithoutTeam).toBeCalledWith(state, {});
});

it('profiles for the given team', () => {
const teamId = 'team_id1';

const expectedUsers = [{id: 'id1'}, {id: 'id2'}];
users.getProfilesInTeam.mockReturnValue(expectedUsers);

expect(getUsers(state, loading, teamId, term)).toEqual(expectedUsers);
expect(users.getProfilesInTeam).toBeCalledWith(state, teamId);
expect(users.getProfilesInTeam).toBeCalledWith(state, teamId, {});
});
});

describe('filters', () => {
const loading = false;
const term = '';
const systemAdmin = 'system_admin';
const roleFilter = {role: 'system_admin'};
const inactiveFilter = {inactive: true};
const inactive = 'inactive';

it('all profiles with system admin', () => {
const teamId = '';

const expectedUsers = [{id: 'id1'}];
users.getProfiles.mockReturnValue(expectedUsers);

expect(getUsers(state, loading, teamId, term, systemAdmin)).toEqual(expectedUsers);
expect(users.getProfiles).toBeCalledWith(state, roleFilter);
});

it('inactive profiles without a team', () => {
const teamId = 'no_team';

const expectedUsers = [{id: 'id1'}, {id: 'id2'}];
users.getProfilesWithoutTeam.mockReturnValue(expectedUsers);

expect(getUsers(state, loading, teamId, term, inactive)).toEqual(expectedUsers);
expect(users.getProfilesWithoutTeam).toBeCalledWith(state, inactiveFilter);
});

it('system admin profiles for the given team', () => {
const teamId = 'team_id1';

const expectedUsers = [{id: 'id2'}];
users.getProfilesInTeam.mockReturnValue(expectedUsers);
expect(getUsers(state, loading, teamId, term, systemAdmin)).toEqual(expectedUsers);
expect(users.getProfilesInTeam).toBeCalledWith(state, teamId, roleFilter);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export default class SystemUsersList extends React.Component {
renderFilterRow: PropTypes.func,

teamId: PropTypes.string.isRequired,
filter: PropTypes.string.isRequired,
term: PropTypes.string.isRequired,
onTermChange: PropTypes.func.isRequired,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('components/admin_console/system_users/list', () => {
focusOnMount: false,
renderFilterRow: jest.fn(),
teamId: '',
filter: '',
term: '',
onTermChange: jest.fn(),
mfaEnabled: false,
Expand Down
Loading

0 comments on commit b1c7fc7

Please sign in to comment.