forked from mattermost/mattermost-webapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding warning before disabling the guest accounts access (mattermost…
…#4131) * Adding warning before disabling the guest accounts access * Adding tests * Fixing types problems * fixing i18n * Addressing PR review comments
- Loading branch information
Showing
5 changed files
with
326 additions
and
6 deletions.
There are no files selected for viewing
135 changes: 135 additions & 0 deletions
135
...ts/admin_console/__snapshots__/custom_enable_disable_guest_accounts_setting.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`components/AdminConsole/CustomEnableDisableGuestAccountsSetting initial state with false 1`] = ` | ||
<Fragment> | ||
<BooleanSetting | ||
disabled={false} | ||
falseText={ | ||
<FormattedMessage | ||
defaultMessage="false" | ||
id="admin.false" | ||
values={Object {}} | ||
/> | ||
} | ||
helpText={ | ||
<injectIntl(FormattedMarkdownMessage) | ||
defaultMessage="When true, external guest can be invited to channels within teams. Please see [Permissions Schemes](../user_management/permissions/system_scheme) for which roles can invite guests." | ||
id="admin.guest_access.enableDescription" | ||
/> | ||
} | ||
id="MySetting" | ||
label={ | ||
<FormattedMessage | ||
defaultMessage="Enable Guest Access: " | ||
id="admin.guest_access.enableTitle" | ||
values={Object {}} | ||
/> | ||
} | ||
onChange={[Function]} | ||
setByEnv={false} | ||
trueText={ | ||
<FormattedMessage | ||
defaultMessage="true" | ||
id="admin.true" | ||
values={Object {}} | ||
/> | ||
} | ||
value={false} | ||
/> | ||
<ConfirmModal | ||
confirmButtonClass="btn btn-primary" | ||
confirmButtonText={ | ||
<FormattedMessage | ||
defaultMessage="Disable Guest Access" | ||
id="admin.guest_access.disableConfirmButton" | ||
values={Object {}} | ||
/> | ||
} | ||
message={ | ||
<FormattedMessage | ||
defaultMessage="Disabling guest access will revoke all current Guest Account sessions. Guests will no longer be able to login and new guests cannot be invited into Mattermost. Guest users will be marked as inactive in user lists. Enabling this feature will not reinstate previous guest accounts." | ||
id="admin.guest_access.disableConfirmMessage" | ||
values={Object {}} | ||
/> | ||
} | ||
modalClass="" | ||
onCancel={[Function]} | ||
onConfirm={[Function]} | ||
show={false} | ||
title={ | ||
<FormattedMessage | ||
defaultMessage="Disable Guest Access?" | ||
id="admin.guest_access.disableConfirmTitle" | ||
values={Object {}} | ||
/> | ||
} | ||
/> | ||
</Fragment> | ||
`; | ||
|
||
exports[`components/AdminConsole/CustomEnableDisableGuestAccountsSetting initial state with true 1`] = ` | ||
<Fragment> | ||
<BooleanSetting | ||
disabled={false} | ||
falseText={ | ||
<FormattedMessage | ||
defaultMessage="false" | ||
id="admin.false" | ||
values={Object {}} | ||
/> | ||
} | ||
helpText={ | ||
<injectIntl(FormattedMarkdownMessage) | ||
defaultMessage="When true, external guest can be invited to channels within teams. Please see [Permissions Schemes](../user_management/permissions/system_scheme) for which roles can invite guests." | ||
id="admin.guest_access.enableDescription" | ||
/> | ||
} | ||
id="MySetting" | ||
label={ | ||
<FormattedMessage | ||
defaultMessage="Enable Guest Access: " | ||
id="admin.guest_access.enableTitle" | ||
values={Object {}} | ||
/> | ||
} | ||
onChange={[Function]} | ||
setByEnv={false} | ||
trueText={ | ||
<FormattedMessage | ||
defaultMessage="true" | ||
id="admin.true" | ||
values={Object {}} | ||
/> | ||
} | ||
value={true} | ||
/> | ||
<ConfirmModal | ||
confirmButtonClass="btn btn-primary" | ||
confirmButtonText={ | ||
<FormattedMessage | ||
defaultMessage="Disable Guest Access" | ||
id="admin.guest_access.disableConfirmButton" | ||
values={Object {}} | ||
/> | ||
} | ||
message={ | ||
<FormattedMessage | ||
defaultMessage="Disabling guest access will revoke all current Guest Account sessions. Guests will no longer be able to login and new guests cannot be invited into Mattermost. Guest users will be marked as inactive in user lists. Enabling this feature will not reinstate previous guest accounts." | ||
id="admin.guest_access.disableConfirmMessage" | ||
values={Object {}} | ||
/> | ||
} | ||
modalClass="" | ||
onCancel={[Function]} | ||
onConfirm={[Function]} | ||
show={false} | ||
title={ | ||
<FormattedMessage | ||
defaultMessage="Disable Guest Access?" | ||
id="admin.guest_access.disableConfirmTitle" | ||
values={Object {}} | ||
/> | ||
} | ||
/> | ||
</Fragment> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
components/admin_console/custom_enable_disable_guest_accounts_setting.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import React from 'react'; | ||
import {shallow} from 'enzyme'; | ||
|
||
import CustomEnableDisableGuestAccountsSetting from './custom_enable_disable_guest_accounts_setting'; | ||
|
||
describe('components/AdminConsole/CustomEnableDisableGuestAccountsSetting', () => { | ||
const baseProps = { | ||
id: 'MySetting', | ||
value: false, | ||
onChange: jest.fn(), | ||
disabled: false, | ||
setByEnv: false, | ||
}; | ||
|
||
describe('initial state', () => { | ||
test('with true', () => { | ||
const props = { | ||
...baseProps, | ||
value: true, | ||
}; | ||
|
||
const wrapper = shallow( | ||
<CustomEnableDisableGuestAccountsSetting {...props}/> | ||
); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
test('with false', () => { | ||
const props = { | ||
...baseProps, | ||
value: false, | ||
}; | ||
|
||
const wrapper = shallow( | ||
<CustomEnableDisableGuestAccountsSetting {...props}/> | ||
); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
}); | ||
|
||
describe('handleChange', () => { | ||
test('should enable without show confirmation modal', () => { | ||
const props = { | ||
...baseProps, | ||
onChange: jest.fn(), | ||
}; | ||
|
||
const wrapper = shallow<CustomEnableDisableGuestAccountsSetting>( | ||
<CustomEnableDisableGuestAccountsSetting {...props}/> | ||
); | ||
|
||
wrapper.instance().handleChange('MySetting', true); | ||
expect(props.onChange).toBeCalledWith(baseProps.id, true); | ||
expect(wrapper.state().showConfirm).toBe(false); | ||
}); | ||
|
||
test('should show confirmation modal on disable without confirm', () => { | ||
const props = { | ||
...baseProps, | ||
onChange: jest.fn(), | ||
}; | ||
|
||
const wrapper = shallow<CustomEnableDisableGuestAccountsSetting>( | ||
<CustomEnableDisableGuestAccountsSetting {...props}/> | ||
); | ||
|
||
wrapper.instance().handleChange('MySetting', false); | ||
expect(props.onChange).not.toBeCalled(); | ||
expect(wrapper.state().showConfirm).toBe(true); | ||
}); | ||
|
||
test('should disable when confirm param is passed', () => { | ||
const props = { | ||
...baseProps, | ||
onChange: jest.fn(), | ||
}; | ||
|
||
const wrapper = shallow<CustomEnableDisableGuestAccountsSetting>( | ||
<CustomEnableDisableGuestAccountsSetting {...props}/> | ||
); | ||
|
||
wrapper.instance().handleChange('MySetting', false, true); | ||
expect(props.onChange).toBeCalledWith(baseProps.id, false); | ||
expect(wrapper.state().showConfirm).toBe(false); | ||
}); | ||
}); | ||
}); |
95 changes: 95 additions & 0 deletions
95
components/admin_console/custom_enable_disable_guest_accounts_setting.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import React from 'react'; | ||
import {FormattedMessage} from 'react-intl'; | ||
|
||
import FormattedMarkdownMessage from 'components/formatted_markdown_message'; | ||
|
||
import ConfirmModal from 'components/confirm_modal.jsx'; | ||
|
||
import BooleanSetting from './boolean_setting'; | ||
|
||
type Props = { | ||
id: string; | ||
value: boolean; | ||
onChange: (id: string, value: any) => void; | ||
disabled?: boolean; | ||
setByEnv: boolean; | ||
} | ||
|
||
type State = { | ||
showConfirm: boolean; | ||
} | ||
|
||
export default class CustomEnableDisableGuestAccountsSetting extends React.Component<Props, State> { | ||
public constructor(props: Props) { | ||
super(props); | ||
|
||
this.state = { | ||
showConfirm: false, | ||
}; | ||
} | ||
|
||
public handleChange = (id: string, value: boolean, confirm?: boolean) => { | ||
if (!value && !confirm) { | ||
this.setState({showConfirm: true}); | ||
} else { | ||
this.props.onChange(id, value); | ||
} | ||
}; | ||
|
||
public render() { | ||
const label = ( | ||
<FormattedMessage | ||
id='admin.guest_access.enableTitle' | ||
defaultMessage='Enable Guest Access: ' | ||
/> | ||
); | ||
const helpText = ( | ||
<FormattedMarkdownMessage | ||
id='admin.guest_access.enableDescription' | ||
defaultMessage='When true, external guest can be invited to channels within teams. Please see [Permissions Schemes](../user_management/permissions/system_scheme) for which roles can invite guests.' | ||
/> | ||
); | ||
|
||
return ( | ||
<> | ||
<BooleanSetting | ||
id={this.props.id} | ||
value={this.props.value} | ||
label={label} | ||
helpText={helpText} | ||
setByEnv={this.props.setByEnv} | ||
onChange={this.handleChange} | ||
/> | ||
<ConfirmModal | ||
show={this.state.showConfirm} | ||
title={ | ||
<FormattedMessage | ||
id='admin.guest_access.disableConfirmTitle' | ||
defaultMessage='Disable Guest Access?' | ||
/> | ||
} | ||
message={ | ||
<FormattedMessage | ||
id='admin.guest_access.disableConfirmMessage' | ||
defaultMessage='Disabling guest access will revoke all current Guest Account sessions. Guests will no longer be able to login and new guests cannot be invited into Mattermost. Guest users will be marked as inactive in user lists. Enabling this feature will not reinstate previous guest accounts.' | ||
/> | ||
} | ||
confirmButtonText={ | ||
<FormattedMessage | ||
id='admin.guest_access.disableConfirmButton' | ||
defaultMessage='Disable Guest Access' | ||
/> | ||
} | ||
onConfirm={() => { | ||
this.handleChange(this.props.id, false, true); | ||
this.setState({showConfirm: false}); | ||
}} | ||
onCancel={() => this.setState({showConfirm: false})} | ||
/> | ||
</> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters