Skip to content

Commit

Permalink
MM-14452 - When a non-sysadmin tries to navigate to a system co… (mat…
Browse files Browse the repository at this point in the history
…termost#4208)

* proper redirect from admin console

* test

* test name
  • Loading branch information
reflog authored Nov 18, 2019
1 parent e26e129 commit 81d6ee7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ exports[`components/AdminConsole should generate the routes 1`] = `
</div>
`;

exports[`components/AdminConsole should redirect to / when not system admin 1`] = `
exports[`components/AdminConsole should redirect to town-square when not system admin 1`] = `
<Redirect
to="/"
to="/team-id/channels/town-square"
/>
`;
3 changes: 2 additions & 1 deletion components/admin_console/admin_console.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default class AdminConsole extends React.Component {
adminDefinition: PropTypes.object.isRequired,
environmentConfig: PropTypes.object,
license: PropTypes.object.isRequired,
unauthorizedRoute: PropTypes.string.isRequired,
buildEnterpriseReady: PropTypes.bool,
roles: PropTypes.object.isRequired,
match: PropTypes.shape({
Expand Down Expand Up @@ -122,7 +123,7 @@ export default class AdminConsole extends React.Component {

if (!this.props.isCurrentUserSystemAdmin) {
return (
<Redirect to='/'/>
<Redirect to={this.props.unauthorizedRoute}/>
);
}

Expand Down
4 changes: 3 additions & 1 deletion components/admin_console/admin_console.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ describe('components/AdminConsole', () => {
},
};

test('should redirect to / when not system admin', () => {
test('should redirect to town-square when not system admin', () => {
const props = {
...baseProps,
unauthorizedRoute: '/team-id/channels/town-square',
isCurrentUserSystemAdmin: false,
};
const wrapper = shallow(
Expand All @@ -56,6 +57,7 @@ describe('components/AdminConsole', () => {
test('should generate the routes', () => {
const props = {
...baseProps,
unauthorizedRoute: '/team-id/channels/town-square',
isCurrentUserSystemAdmin: true,
};
const wrapper = shallow(
Expand Down
11 changes: 10 additions & 1 deletion components/admin_console/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,33 @@ import * as Selectors from 'mattermost-redux/selectors/entities/admin';
import {withRouter} from 'react-router-dom';
import {getConfig as getGeneralConfig, getLicense} from 'mattermost-redux/selectors/entities/general';
import {getRoles} from 'mattermost-redux/selectors/entities/roles';
import {isCurrentUserSystemAdmin} from 'mattermost-redux/selectors/entities/users';
import {isCurrentUserSystemAdmin, getCurrentUserId} from 'mattermost-redux/selectors/entities/users';
import {getTeam} from 'mattermost-redux/selectors/entities/teams';

import {General} from 'mattermost-redux/constants';

import {setNavigationBlocked, deferNavigation, cancelNavigation, confirmNavigation} from 'actions/admin_actions.jsx';
import {getNavigationBlocked, showNavigationPrompt} from 'selectors/views/admin';
import {getAdminDefinition} from 'selectors/admin_console';

import LocalStorageStore from 'stores/local_storage_store';

import AdminConsole from './admin_console.jsx';

function mapStateToProps(state) {
const generalConfig = getGeneralConfig(state);
const buildEnterpriseReady = generalConfig.BuildEnterpriseReady === 'true';
const adminDefinition = getAdminDefinition(state);
const teamId = LocalStorageStore.getPreviousTeamId(getCurrentUserId(state));
const team = getTeam(state, teamId);
const unauthorizedRoute = team ? `/${team.name}/channels/${General.DEFAULT_CHANNEL}` : '/';

return {
config: Selectors.getConfig(state),
environmentConfig: Selectors.getEnvironmentConfig(state),
license: getLicense(state),
buildEnterpriseReady,
unauthorizedRoute,
navigationBlocked: getNavigationBlocked(state),
showNavigationPrompt: showNavigationPrompt(state),
isCurrentUserSystemAdmin: isCurrentUserSystemAdmin(state),
Expand Down

0 comments on commit 81d6ee7

Please sign in to comment.