Skip to content

Commit

Permalink
Adding warning before disabling the guest accounts access (mattermost…
Browse files Browse the repository at this point in the history
…#4131)

* Adding warning before disabling the guest accounts access

* Adding tests

* Fixing types problems

* fixing i18n

* Addressing PR review comments
  • Loading branch information
jespino committed Nov 15, 2019
1 parent 515c817 commit 3479fdc
Show file tree
Hide file tree
Showing 5 changed files with 326 additions and 6 deletions.
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>
`;
9 changes: 3 additions & 6 deletions components/admin_console/admin_definition.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {trackEvent} from 'actions/diagnostics_actions.jsx';

import Audits from './audits';
import CustomUrlSchemesSetting from './custom_url_schemes_setting.jsx';
import CustomEnableDisableGuestAccountsSetting from './custom_enable_disable_guest_accounts_setting';
import LicenseSettings from './license_settings';
import PermissionSchemesSettings from './permission_schemes_settings';
import PermissionSystemSchemeSettings from './permission_schemes_settings/permission_system_scheme_settings';
Expand Down Expand Up @@ -3495,13 +3496,9 @@ const AdminDefinition = {
name_default: 'Guest Access (Beta)',
settings: [
{
type: Constants.SettingsTypes.TYPE_BOOL,
type: Constants.SettingsTypes.TYPE_CUSTOM,
component: CustomEnableDisableGuestAccountsSetting,
key: 'GuestAccountsSettings.Enable',
label: t('admin.guest_access.enableTitle'),
label_default: 'Enable Guest Access: ',
help_text: t('admin.guest_access.enableDescription'),
help_text_default: '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.',
help_text_markdown: true,
},
{
type: Constants.SettingsTypes.TYPE_TEXT,
Expand Down
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);
});
});
});
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})}
/>
</>
);
}
}
3 changes: 3 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,9 @@
"admin.group_settings.introBanner": "Groups are a way to organize users and apply actions to all users within that group.\nFor more information on Groups, please see [documentation](!https://www.mattermost.com/default-ad-ldap-groups).",
"admin.group_settings.ldapGroupsDescription": "Link and configure groups from your AD/LDAP to Mattermost. Please ensure you have configured a [group filter]({siteURL}/admin_console/authentication/ldap).",
"admin.group_settings.ldapGroupsTitle": "AD/LDAP Groups",
"admin.guest_access.disableConfirmButton": "Disable Guest Access",
"admin.guest_access.disableConfirmMessage": "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.",
"admin.guest_access.disableConfirmTitle": "Disable Guest Access?",
"admin.guest_access.enableDescription": "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.",
"admin.guest_access.enableTitle": "Enable Guest Access: ",
"admin.guest_access.mfaDescription": "When true, [multi-factor authentication](!https://docs.mattermost.com/deployment/auth.html) for guests is required for login. New guest users will be required to configure MFA on signup. Logged in guest users without MFA configured are redirected to the MFA setup page until configuration is complete.\n \nIf your system has guest users with login methods other than AD/LDAP and email, MFA must be enforced with the authentication provider outside of Mattermost.",
Expand Down

0 comments on commit 3479fdc

Please sign in to comment.