From fba2a35cef412cabf6d68a20e03e078b238230b3 Mon Sep 17 00:00:00 2001 From: Ran Byron Date: Sat, 16 Feb 2019 17:06:09 +0200 Subject: [PATCH] [Feature] Sharing disabled if dashboard has query params (#3439) --- .../pages/dashboards/ShareDashboardDialog.jsx | 25 +++++++++++++++---- client/app/pages/dashboards/dashboard.js | 11 +++++++- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/client/app/pages/dashboards/ShareDashboardDialog.jsx b/client/app/pages/dashboards/ShareDashboardDialog.jsx index ddd47284f0..a296e2b963 100644 --- a/client/app/pages/dashboards/ShareDashboardDialog.jsx +++ b/client/app/pages/dashboards/ShareDashboardDialog.jsx @@ -4,6 +4,7 @@ import PropTypes from 'prop-types'; import Switch from 'antd/lib/switch'; import Modal from 'antd/lib/modal'; import Form from 'antd/lib/form'; +import Alert from 'antd/lib/alert'; import { $http, toastr } from '@/services/ng'; import { wrap as wrapDialog, DialogPropType } from '@/components/DialogWrapper'; import InputWithCopy from '@/components/InputWithCopy'; @@ -14,6 +15,7 @@ const API_SHARE_URL = 'api/dashboards/{id}/share'; class ShareDashboardDialog extends React.Component { static propTypes = { dashboard: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types + hasQueryParams: PropTypes.bool.isRequired, dialog: DialogPropType.isRequired, }; @@ -25,10 +27,14 @@ class ShareDashboardDialog extends React.Component { constructor(props) { super(props); + const { dashboard } = this.props; + this.state = { saving: false, }; - this.apiUrl = replace(API_SHARE_URL, '{id}', props.dashboard.id); + + this.apiUrl = replace(API_SHARE_URL, '{id}', dashboard.id); + this.disabled = this.props.hasQueryParams && !dashboard.publicAccessEnabled; } static get headerContent() { @@ -43,7 +49,7 @@ class ShareDashboardDialog extends React.Component { ); } - enable = () => { + enableAccess = () => { const { dashboard } = this.props; this.setState({ saving: true }); @@ -61,7 +67,7 @@ class ShareDashboardDialog extends React.Component { }); } - disable = () => { + disableAccess = () => { const { dashboard } = this.props; this.setState({ saving: true }); @@ -81,9 +87,9 @@ class ShareDashboardDialog extends React.Component { onChange = (checked) => { if (checked) { - this.enable(); + this.enableAccess(); } else { - this.disable(); + this.disableAccess(); } }; @@ -97,11 +103,20 @@ class ShareDashboardDialog extends React.Component { footer={null} >
+ {this.props.hasQueryParams && ( + + + + )} {dashboard.public_url && ( diff --git a/client/app/pages/dashboards/dashboard.js b/client/app/pages/dashboards/dashboard.js index 4ebbf2ebe7..1cecdf6a30 100644 --- a/client/app/pages/dashboards/dashboard.js +++ b/client/app/pages/dashboards/dashboard.js @@ -392,7 +392,16 @@ function DashboardCtrl( } this.openShareForm = () => { - ShareDashboardDialog.showModal({ dashboard: this.dashboard }); + // check if any of the wigets have query parameters + const hasQueryParams = _.some( + this.dashboard.widgets, + w => !_.isEmpty(w.getQuery() && w.getQuery().getParametersDefs()), + ); + + ShareDashboardDialog.showModal({ + dashboard: this.dashboard, + hasQueryParams, + }); }; }