Skip to content

Commit

Permalink
[Feature] Sharing disabled if dashboard has query params (#3439)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranbena authored and kravets-levko committed Feb 16, 2019
1 parent b9644b7 commit fba2a35
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
25 changes: 20 additions & 5 deletions client/app/pages/dashboards/ShareDashboardDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
};

Expand All @@ -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() {
Expand All @@ -43,7 +49,7 @@ class ShareDashboardDialog extends React.Component {
);
}

enable = () => {
enableAccess = () => {
const { dashboard } = this.props;
this.setState({ saving: true });

Expand All @@ -61,7 +67,7 @@ class ShareDashboardDialog extends React.Component {
});
}

disable = () => {
disableAccess = () => {
const { dashboard } = this.props;
this.setState({ saving: true });

Expand All @@ -81,9 +87,9 @@ class ShareDashboardDialog extends React.Component {

onChange = (checked) => {
if (checked) {
this.enable();
this.enableAccess();
} else {
this.disable();
this.disableAccess();
}
};

Expand All @@ -97,11 +103,20 @@ class ShareDashboardDialog extends React.Component {
footer={null}
>
<Form layout="horizontal">
{this.props.hasQueryParams && (
<Form.Item>
<Alert
message="Sharing is currently not supported for dashboards containing queries with parameters."
type="error"
/>
</Form.Item>
)}
<Form.Item label="Allow public access" {...this.formItemProps}>
<Switch
checked={dashboard.publicAccessEnabled}
onChange={this.onChange}
loading={this.state.saving}
disabled={this.disabled}
/>
</Form.Item>
{dashboard.public_url && (
Expand Down
11 changes: 10 additions & 1 deletion client/app/pages/dashboards/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
};
}

Expand Down

0 comments on commit fba2a35

Please sign in to comment.