Skip to content

Commit

Permalink
[MM-16534] if user has bots, but the bots are disabled, don't s… (mat…
Browse files Browse the repository at this point in the history
…termost#3135)

bots will be disabled
  • Loading branch information
jfrerich authored and mickmister committed Jul 16, 2019
1 parent 66f8385 commit 6564247
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,39 @@ exports[`components/admin_console/system_users/system_users_dropdown/system_user
</div>
`;

exports[`components/admin_console/system_users/system_users_dropdown/system_users_dropdown.jsx renderDeactivateMemberModal should render the bot accounts warning in case the user do has any bot accounts 1`] = `
exports[`components/admin_console/system_users/system_users_dropdown/system_users_dropdown.jsx renderDeactivateMemberModal should not render the bot accounts warning. owner_id has no enabled bot accounts 1`] = `
<div>
<InjectIntl(FormattedMarkdownMessage)
defaultMessage="This action deactivates {username}. They will be logged out and not have access to any teams or channels on this system.\\\\n"
id="deactivate_member_modal.desc"
values={
Object {
"username": "some-user",
}
}
/>
<InjectIntl(FormattedMarkdownMessage)
defaultMessage="Are you sure you want to deactivate {username}?"
id="deactivate_member_modal.desc.confirm"
values={
Object {
"username": "some-user",
}
}
/>
<strong>
<br />
<br />
<FormattedMessage
defaultMessage="You must also deactivate this user in the SSO provider or they will be reactivated on next login or sync."
id="deactivate_member_modal.sso_warning"
values={Object {}}
/>
</strong>
</div>
`;

exports[`components/admin_console/system_users/system_users_dropdown/system_users_dropdown.jsx renderDeactivateMemberModal should render the bot accounts warning. owner_id has enabled bot accounts 1`] = `
<div>
<InjectIntl(FormattedMarkdownMessage)
defaultMessage="This action deactivates {username}.\\\\n \\\\n * They will be logged out and not have access to any teams or channels on this system.\\\\n * Bot accounts they manage will be disabled along with their integrations. To enable them again, go to Integrations > Bot Accounts. [Learn more about bot accounts](!https://mattermost.com/pl/default-bot-accounts).\\\\n \\\\n \\\\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export default class SystemUsersDropdown extends React.PureComponent {
let messageForUsersWithBotAccounts;
if (this.shouldDisableBotsWhenOwnerIsDeactivated()) {
for (const bot of Object.values(this.props.bots)) {
if (bot.owner_id === user.id) {
if ((bot.owner_id === user.id) && this.state.showDeactivateMemberModal && (bot.delete_at === 0)) {
messageForUsersWithBotAccounts = (
<FormattedMarkdownMessage
id='deactivate_member_modal.desc.for_users_with_bot_accounts'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,41 @@ describe('components/admin_console/system_users/system_users_dropdown/system_use
expect(modal.prop('message')).toMatchSnapshot();
});

test('renderDeactivateMemberModal should render the bot accounts warning in case the user do has any bot accounts', async () => {
test('renderDeactivateMemberModal should render the bot accounts warning. owner_id has enabled bot accounts', async () => {
const overrideProps = {
config: {
ServiceSettings: {
DisableBotsWhenOwnerIsDeactivated: true,
},
},
bots: {
1: {owner_id: '1'},
2: {owner_id: '1'},
3: {owner_id: 'user_id'},
1: {owner_id: '1', delete_at: 0},
2: {owner_id: '1', delete_at: 0},
3: {owner_id: 'user_id', delete_at: 0},
},
};
const wrapper = shallow(<SystemUsersDropdown {...{...requiredProps, ...overrideProps}}/>);
wrapper.setState({showDeactivateMemberModal: true});

const modal = wrapper.wrap(wrapper.instance().renderDeactivateMemberModal());
expect(modal.prop('message')).toMatchSnapshot();
});

test('renderDeactivateMemberModal should not render the bot accounts warning. owner_id has no enabled bot accounts', async () => {
const overrideProps = {
config: {
ServiceSettings: {
DisableBotsWhenOwnerIsDeactivated: true,
},
},
bots: {
1: {owner_id: '1', delete_at: 0},
2: {owner_id: '1', delete_at: 0},
3: {owner_id: 'user_id', delete_at: 1234},
},
};
const wrapper = shallow(<SystemUsersDropdown {...{...requiredProps, ...overrideProps}}/>);
wrapper.setState({showDeactivateMemberModal: true});

const modal = wrapper.wrap(wrapper.instance().renderDeactivateMemberModal());
expect(modal.prop('message')).toMatchSnapshot();
Expand Down

0 comments on commit 6564247

Please sign in to comment.