From 50b6f38f19109542978ffe0679f92e20f575af74 Mon Sep 17 00:00:00 2001 From: Brandon Farmer Date: Wed, 2 May 2018 11:46:35 -0700 Subject: [PATCH 1/3] Disable temp var dropdowns for viewers when auth enabled --- ui/src/dashboards/components/TemplateControlBar.tsx | 6 ++++++ .../dashboards/components/TemplateControlDropdown.tsx | 11 ++++++++++- ui/src/dashboards/containers/DashboardPage.js | 4 ++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ui/src/dashboards/components/TemplateControlBar.tsx b/ui/src/dashboards/components/TemplateControlBar.tsx index 5bd9e3360..319543b4e 100644 --- a/ui/src/dashboards/components/TemplateControlBar.tsx +++ b/ui/src/dashboards/components/TemplateControlBar.tsx @@ -12,6 +12,8 @@ interface Props { isOpen: boolean onOpenTemplateManager: () => void onSelectTemplate: (id: string) => void + meRole: string + isUsingAuth: boolean } const TemplateControlBar: SFC = ({ @@ -19,6 +21,8 @@ const TemplateControlBar: SFC = ({ templates, onSelectTemplate, onOpenTemplateManager, + meRole, + isUsingAuth, }) => (
@@ -27,6 +31,8 @@ const TemplateControlBar: SFC = ({ templates.map(template => ( diff --git a/ui/src/dashboards/components/TemplateControlDropdown.tsx b/ui/src/dashboards/components/TemplateControlDropdown.tsx index b3bb99d09..863031e7e 100644 --- a/ui/src/dashboards/components/TemplateControlDropdown.tsx +++ b/ui/src/dashboards/components/TemplateControlDropdown.tsx @@ -4,8 +4,11 @@ import Dropdown from 'src/shared/components/Dropdown' import {calculateDropdownWidth} from 'src/dashboards/constants/templateControlBar' import {Template} from 'src/types/dashboard' +export const VIEWER_ROLE = 'viewer' interface Props { template: Template + meRole: string + isUsingAuth: boolean onSelectTemplate: (id: string) => void } @@ -13,7 +16,12 @@ interface Props { // the full array, and [item] to all `selected` values when we update // this component to support multiple values -const TemplateControlDropdown: SFC = ({template, onSelectTemplate}) => { +const TemplateControlDropdown: SFC = ({ + template, + onSelectTemplate, + isUsingAuth, + meRole, +}) => { const dropdownItems = template.values.map(value => ({ ...value, text: value.value, @@ -34,6 +42,7 @@ const TemplateControlDropdown: SFC = ({template, onSelectTemplate}) => { menuClass="dropdown-astronaut" useAutoComplete={true} selected={selectedItem.text} + disabled={isUsingAuth && (!meRole || meRole === VIEWER_ROLE)} onChoose={onSelectTemplate(template.id)} /> diff --git a/ui/src/dashboards/containers/DashboardPage.js b/ui/src/dashboards/containers/DashboardPage.js index b25464121..dcab48338 100644 --- a/ui/src/dashboards/containers/DashboardPage.js +++ b/ui/src/dashboards/containers/DashboardPage.js @@ -305,6 +305,8 @@ class DashboardPage extends Component { const {zoomedTimeRange} = this.state const {zoomedLower, zoomedUpper} = zoomedTimeRange const { + isUsingAuth, + meRole, source, sources, timeRange, @@ -426,6 +428,8 @@ class DashboardPage extends Component { {inPresentationMode || ( Date: Wed, 2 May 2018 12:35:53 -0700 Subject: [PATCH 2/3] Use isUserAuthorized helper --- ui/src/dashboards/components/TemplateControlBar.tsx | 4 ++-- ui/src/dashboards/components/TemplateControlDropdown.tsx | 4 ++-- ui/test/dashboards/components/TemplateControlBar.test.tsx | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ui/src/dashboards/components/TemplateControlBar.tsx b/ui/src/dashboards/components/TemplateControlBar.tsx index 319543b4e..1b40f8648 100644 --- a/ui/src/dashboards/components/TemplateControlBar.tsx +++ b/ui/src/dashboards/components/TemplateControlBar.tsx @@ -8,12 +8,12 @@ import TemplateControlDropdown from 'src/dashboards/components/TemplateControlDr import {Template} from 'src/types/dashboard' interface Props { + meRole: string + isUsingAuth: boolean templates: Template[] isOpen: boolean onOpenTemplateManager: () => void onSelectTemplate: (id: string) => void - meRole: string - isUsingAuth: boolean } const TemplateControlBar: SFC = ({ diff --git a/ui/src/dashboards/components/TemplateControlDropdown.tsx b/ui/src/dashboards/components/TemplateControlDropdown.tsx index 863031e7e..f7011bd0f 100644 --- a/ui/src/dashboards/components/TemplateControlDropdown.tsx +++ b/ui/src/dashboards/components/TemplateControlDropdown.tsx @@ -2,9 +2,9 @@ import React, {SFC} from 'react' import Dropdown from 'src/shared/components/Dropdown' import {calculateDropdownWidth} from 'src/dashboards/constants/templateControlBar' +import {isUserAuthorized, EDITOR_ROLE} from 'src/auth/Authorized' import {Template} from 'src/types/dashboard' -export const VIEWER_ROLE = 'viewer' interface Props { template: Template meRole: string @@ -42,7 +42,7 @@ const TemplateControlDropdown: SFC = ({ menuClass="dropdown-astronaut" useAutoComplete={true} selected={selectedItem.text} - disabled={isUsingAuth && (!meRole || meRole === VIEWER_ROLE)} + disabled={!isUsingAuth || !isUserAuthorized(meRole, EDITOR_ROLE)} onChoose={onSelectTemplate(template.id)} /> diff --git a/ui/test/dashboards/components/TemplateControlBar.test.tsx b/ui/test/dashboards/components/TemplateControlBar.test.tsx index 65a52dc28..0c1418884 100644 --- a/ui/test/dashboards/components/TemplateControlBar.test.tsx +++ b/ui/test/dashboards/components/TemplateControlBar.test.tsx @@ -13,6 +13,8 @@ const defaultProps = { values: [{value: 'firstValue'}, {value: 'secondValue'}], }, ], + meRole: 'EDITOR', + isUsingAuth: true, onOpenTemplateManager: () => {}, onSelectTemplate: () => {}, } From d7ee8cd97fc5d5c83fc81e98a02255077c40887f Mon Sep 17 00:00:00 2001 From: Brandon Farmer Date: Wed, 2 May 2018 12:39:15 -0700 Subject: [PATCH 3/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 807e510b7..19f183eae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ 1. [#3256](https://github.com/influxdata/chronograf/pull/3256): Reduce font sizes in dashboards for increased space efficiency 1. [#3320](https://github.com/influxdata/chronograf/pull/3320): Add overlay animation to Template Variables Manager 1. [#3245](https://github.com/influxdata/chronograf/pull/3245): Display 'no results' on cells without results +1. [#3354](https://github.com/influxdata/chronograf/pull/3354): Disable template variables for non editing users ### Bug Fixes