Skip to content

Commit

Permalink
[MM-15195] Bot account can be edited even though it's managed by a pl…
Browse files Browse the repository at this point in the history
…ugin (mattermost#2685)

* If ownerUsername is 'plugin', don't show options to Create, Edit, or
Disable Bot accounts.

* When bot is managed by a plugin, test that elements to create token,
edit or diable bot are not shown.

When bot is not managed by a plugin, test that elements to create token,
edit or diable bot are shown.  Added these elements to test where bot is
not managed by a plugin.  # Please enter the commit message for your
changes. Lines starting
  • Loading branch information
jfrerich authored and levb committed Apr 23, 2019
1 parent f89c693 commit e4582e3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 34 deletions.
65 changes: 34 additions & 31 deletions components/integrations/bots/bot.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,37 +276,40 @@ export default class Bot extends React.PureComponent {
);
});

let options = (
<div className='item-actions'>
<button
id='createToken'
className='style--none color--link'
onClick={this.openCreateToken}
>
<FormattedMessage
id='bot.manage.create_token'
defaultMessage='Create New Token'
/>
</button>
{' - '}
<Link to={`/${this.props.team.name}/integrations/bots/edit?id=${this.props.bot.user_id}`}>
<FormattedMessage
id='bots.manage.edit'
defaultMessage='Edit'
/>
</Link>
{' - '}
<button
className='style--none color--link'
onClick={this.disableBot}
>
<FormattedMessage
id='bot.manage.disable'
defaultMessage='Disable'
/>
</button>
</div>
);
let options;
if (ownerUsername !== 'plugin') {
options = (
<div className='item-actions'>
<button
id='createToken'
className='style--none color--link'
onClick={this.openCreateToken}
>
<FormattedMessage
id='bot.manage.create_token'
defaultMessage='Create New Token'
/>
</button>
{' - '}
<Link to={`/${this.props.team.name}/integrations/bots/edit?id=${this.props.bot.user_id}`}>
<FormattedMessage
id='bots.manage.edit'
defaultMessage='Edit'
/>
</Link>
{' - '}
<button
className='style--none color--link'
onClick={this.disableBot}
>
<FormattedMessage
id='bot.manage.disable'
defaultMessage='Disable'
/>
</button>
</div>
);
}
if (this.props.bot.delete_at !== 0) {
options = (
<div className='item-actions'>
Expand Down
28 changes: 25 additions & 3 deletions components/integrations/bots/bot.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,26 @@ describe('components/integrations/bots/Bot', () => {
expect(wrapper.contains(bot.display_name + ' (@' + bot.username + ')')).toEqual(true);
expect(wrapper.contains(bot.description)).toEqual(true);
expect(wrapper.contains('plugin')).toEqual(true);

// if bot managed by plugin, remove ability to edit from UI
expect(wrapper.contains(
<FormattedMessage
id='bot.manage.create_token'
defaultMessage='Create New Token'
/>
)).toEqual(true);
)).toEqual(false);
expect(wrapper.contains(
<FormattedMessage
id='bots.manage.edit'
defaultMessage='Edit'
/>
)).toEqual(true);
)).toEqual(false);
expect(wrapper.contains(
<FormattedMessage
id='bot.manage.disable'
defaultMessage='Disable'
/>
)).toEqual(true);
)).toEqual(false);
expect(wrapper.contains(
<FormattedMessage
id='bot.manage.enable'
Expand Down Expand Up @@ -106,6 +108,26 @@ describe('components/integrations/bots/Bot', () => {
);
expect(wrapper.contains(user.username)).toEqual(true);
expect(wrapper.contains('plugin')).toEqual(false);

// if bot is not managed by plugin, ability to edit from UI is retained
expect(wrapper.contains(
<FormattedMessage
id='bot.manage.create_token'
defaultMessage='Create New Token'
/>
)).toEqual(true);
expect(wrapper.contains(
<FormattedMessage
id='bots.manage.edit'
defaultMessage='Edit'
/>
)).toEqual(true);
expect(wrapper.contains(
<FormattedMessage
id='bot.manage.disable'
defaultMessage='Disable'
/>
)).toEqual(true);
});

it('bot with access tokens', () => {
Expand Down

0 comments on commit e4582e3

Please sign in to comment.