From 83a2bbe67ae12b6ffd03bed9eeb87e93444356e2 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Tue, 6 Dec 2016 07:35:24 -0500 Subject: Only show edit/delete buttons for integrations if the user should have permissions to them (#4719) --- .../integrations/components/commands_container.jsx | 8 ++- .../integrations/components/installed_command.jsx | 68 ++++++++++++---------- .../integrations/components/installed_commands.jsx | 7 ++- .../components/installed_incoming_webhook.jsx | 32 ++++++---- .../components/installed_incoming_webhooks.jsx | 7 ++- .../components/installed_outgoing_webhook.jsx | 52 ++++++++++------- .../components/installed_outgoing_webhooks.jsx | 7 ++- 7 files changed, 111 insertions(+), 70 deletions(-) (limited to 'webapp/components/integrations') diff --git a/webapp/components/integrations/components/commands_container.jsx b/webapp/components/integrations/components/commands_container.jsx index 4ab465218..095dc4fea 100644 --- a/webapp/components/integrations/components/commands_container.jsx +++ b/webapp/components/integrations/components/commands_container.jsx @@ -12,7 +12,9 @@ export default class CommandsContainer extends React.Component { static get propTypes() { return { team: React.PropTypes.object, - children: React.PropTypes.node + user: React.PropTypes.object, + children: React.PropTypes.node.isRequired, + isAdmin: React.PropTypes.bool }; } @@ -65,7 +67,9 @@ export default class CommandsContainer extends React.Component { commands: this.state.commands, users: this.state.users, loading: this.state.loading, - team: this.props.team + team: this.props.team, + user: this.props.user, + isAdmin: this.props.isAdmin })} ); diff --git a/webapp/components/integrations/components/installed_command.jsx b/webapp/components/integrations/components/installed_command.jsx index 96ccaf3e3..2e45739a0 100644 --- a/webapp/components/integrations/components/installed_command.jsx +++ b/webapp/components/integrations/components/installed_command.jsx @@ -13,7 +13,8 @@ export default class InstalledCommand extends React.Component { onRegenToken: React.PropTypes.func.isRequired, onDelete: React.PropTypes.func.isRequired, filter: React.PropTypes.string, - creator: React.PropTypes.object.isRequired + creator: React.PropTypes.object.isRequired, + canChange: React.PropTypes.bool.isRequired }; } @@ -84,6 +85,40 @@ export default class InstalledCommand extends React.Component { trigger += ' ' + command.auto_complete_hint; } + let actions = null; + if (this.props.canChange) { + actions = ( +
+ + + + {' - '} + + + + {' - '} + + + +
+ ); + } + return (
@@ -120,36 +155,7 @@ export default class InstalledCommand extends React.Component {
-
- - - - {' - '} - - - - {' - '} - - - -
+ {actions} ); } diff --git a/webapp/components/integrations/components/installed_commands.jsx b/webapp/components/integrations/components/installed_commands.jsx index e080cd706..1854e6eb1 100644 --- a/webapp/components/integrations/components/installed_commands.jsx +++ b/webapp/components/integrations/components/installed_commands.jsx @@ -14,9 +14,11 @@ export default class InstalledCommands extends React.Component { static get propTypes() { return { team: React.PropTypes.object, + user: React.PropTypes.object, users: React.PropTypes.object, commands: React.PropTypes.array, - loading: React.PropTypes.bool + loading: React.PropTypes.bool, + isAdmin: React.PropTypes.bool }; } @@ -37,6 +39,8 @@ export default class InstalledCommands extends React.Component { render() { const commands = this.props.commands.map((command) => { + const canChange = this.props.isAdmin || this.props.user.id === command.creator_id; + return ( ); }); diff --git a/webapp/components/integrations/components/installed_incoming_webhook.jsx b/webapp/components/integrations/components/installed_incoming_webhook.jsx index 86274c3d6..10328c605 100644 --- a/webapp/components/integrations/components/installed_incoming_webhook.jsx +++ b/webapp/components/integrations/components/installed_incoming_webhook.jsx @@ -14,7 +14,8 @@ export default class InstalledIncomingWebhook extends React.Component { incomingWebhook: React.PropTypes.object.isRequired, onDelete: React.PropTypes.func.isRequired, filter: React.PropTypes.string, - creator: React.PropTypes.object.isRequired + creator: React.PropTypes.object.isRequired, + canChange: React.PropTypes.bool.isRequired }; } @@ -83,6 +84,23 @@ export default class InstalledIncomingWebhook extends React.Component { ); } + let actions = null; + if (this.props.canChange) { + actions = ( +
+ + + +
+ ); + } + return (
@@ -116,17 +134,7 @@ export default class InstalledIncomingWebhook extends React.Component {
-
- - - -
+ {actions} ); } diff --git a/webapp/components/integrations/components/installed_incoming_webhooks.jsx b/webapp/components/integrations/components/installed_incoming_webhooks.jsx index ed98f1053..5b0bc185a 100644 --- a/webapp/components/integrations/components/installed_incoming_webhooks.jsx +++ b/webapp/components/integrations/components/installed_incoming_webhooks.jsx @@ -19,7 +19,9 @@ import {FormattedMessage} from 'react-intl'; export default class InstalledIncomingWebhooks extends React.Component { static get propTypes() { return { - team: React.PropTypes.object + team: React.PropTypes.object, + user: React.PropTypes.object, + isAdmin: React.PropTypes.bool }; } @@ -74,12 +76,15 @@ export default class InstalledIncomingWebhooks extends React.Component { render() { const incomingWebhooks = this.state.incomingWebhooks.map((incomingWebhook) => { + const canChange = this.props.isAdmin || this.props.user.id === incomingWebhook.user_id; + return ( ); }); diff --git a/webapp/components/integrations/components/installed_outgoing_webhook.jsx b/webapp/components/integrations/components/installed_outgoing_webhook.jsx index 3ff2c01a4..04cc1b033 100644 --- a/webapp/components/integrations/components/installed_outgoing_webhook.jsx +++ b/webapp/components/integrations/components/installed_outgoing_webhook.jsx @@ -14,7 +14,8 @@ export default class InstalledOutgoingWebhook extends React.Component { onRegenToken: React.PropTypes.func.isRequired, onDelete: React.PropTypes.func.isRequired, filter: React.PropTypes.string, - creator: React.PropTypes.object.isRequired + creator: React.PropTypes.object.isRequired, + canChange: React.PropTypes.bool.isRequired }; } @@ -146,6 +147,33 @@ export default class InstalledOutgoingWebhook extends React.Component { ); } + let actions = null; + if (this.props.canChange) { + actions = ( +
+ + + + {' - '} + + + +
+ ); + } + return (
@@ -203,27 +231,7 @@ export default class InstalledOutgoingWebhook extends React.Component {
{urls}
-
- - - - {' - '} - - - -
+ {actions} ); } diff --git a/webapp/components/integrations/components/installed_outgoing_webhooks.jsx b/webapp/components/integrations/components/installed_outgoing_webhooks.jsx index 4e9a0260f..7f278d112 100644 --- a/webapp/components/integrations/components/installed_outgoing_webhooks.jsx +++ b/webapp/components/integrations/components/installed_outgoing_webhooks.jsx @@ -19,7 +19,9 @@ import {FormattedMessage} from 'react-intl'; export default class InstalledOutgoingWebhooks extends React.Component { static get propTypes() { return { - team: React.PropTypes.object + team: React.PropTypes.object, + user: React.PropTypes.object, + isAdmin: React.PropTypes.bool }; } @@ -77,6 +79,8 @@ export default class InstalledOutgoingWebhooks extends React.Component { render() { const outgoingWebhooks = this.state.outgoingWebhooks.map((outgoingWebhook) => { + const canChange = this.props.isAdmin || this.props.user.id === outgoingWebhook.creator_id; + return ( ); }); -- cgit v1.2.3-1-g7c22