Prevent Viewer role from overriding temp vars from URL query
parent
b8d7e317db
commit
3c99cabd8f
|
@ -3,6 +3,8 @@ import {replace} from 'react-router-redux'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import queryString from 'query-string'
|
import queryString from 'query-string'
|
||||||
|
|
||||||
|
import {isUserAuthorized, EDITOR_ROLE} from 'src/auth/Authorized'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
getDashboards as getDashboardsAJAX,
|
getDashboards as getDashboardsAJAX,
|
||||||
getDashboard as getDashboardAJAX,
|
getDashboard as getDashboardAJAX,
|
||||||
|
@ -21,6 +23,7 @@ import {errorThrown} from 'src/shared/actions/errors'
|
||||||
|
|
||||||
import {
|
import {
|
||||||
generateURLQueryFromTempVars,
|
generateURLQueryFromTempVars,
|
||||||
|
findUpdatedTempVarsInURLQuery,
|
||||||
findInvalidTempVarsInURLQuery,
|
findInvalidTempVarsInURLQuery,
|
||||||
} from 'src/dashboards/utils/tempVars'
|
} from 'src/dashboards/utils/tempVars'
|
||||||
import {validTimeRange, validAbsoluteTimeRange} from 'src/dashboards/utils/time'
|
import {validTimeRange, validAbsoluteTimeRange} from 'src/dashboards/utils/time'
|
||||||
|
@ -39,6 +42,7 @@ import {
|
||||||
notifyInvalidTempVarValueInURLQuery,
|
notifyInvalidTempVarValueInURLQuery,
|
||||||
notifyInvalidZoomedTimeRangeValueInURLQuery,
|
notifyInvalidZoomedTimeRangeValueInURLQuery,
|
||||||
notifyInvalidTimeRangeValueInURLQuery,
|
notifyInvalidTimeRangeValueInURLQuery,
|
||||||
|
notifyViewerUnauthorizedToSetTempVars,
|
||||||
} from 'src/shared/copy/notifications'
|
} from 'src/shared/copy/notifications'
|
||||||
|
|
||||||
import {CellType} from 'src/types/dashboard'
|
import {CellType} from 'src/types/dashboard'
|
||||||
|
@ -778,9 +782,23 @@ const syncDashboardTempVarsFromURLQueries = (dashboardID, urlQueries) => (
|
||||||
dispatch,
|
dispatch,
|
||||||
getState
|
getState
|
||||||
) => {
|
) => {
|
||||||
const dashboard = getState().dashboardUI.dashboards.find(
|
const {
|
||||||
d => d.id === dashboardID
|
dashboardUI,
|
||||||
|
auth: {isUsingAuth, me},
|
||||||
|
} = getState()
|
||||||
|
const dashboard = dashboardUI.dashboards.find(d => d.id === dashboardID)
|
||||||
|
|
||||||
|
// viewers are not currently allowed to select temp vars and/or use overrides
|
||||||
|
if (isUsingAuth && !isUserAuthorized(me.role, EDITOR_ROLE)) {
|
||||||
|
const urlQueryTempVarsWithUpdatedValues = findUpdatedTempVarsInURLQuery(
|
||||||
|
dashboard.templates,
|
||||||
|
urlQueries
|
||||||
)
|
)
|
||||||
|
if (urlQueryTempVarsWithUpdatedValues.length) {
|
||||||
|
dispatch(notify(notifyViewerUnauthorizedToSetTempVars()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const urlQueryTempVarsWithInvalidValues = findInvalidTempVarsInURLQuery(
|
const urlQueryTempVarsWithInvalidValues = findInvalidTempVarsInURLQuery(
|
||||||
dashboard.templates,
|
dashboard.templates,
|
||||||
|
|
|
@ -134,6 +134,29 @@ export const applyDashboardTempVarOverrides = (
|
||||||
),
|
),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const findUpdatedTempVarsInURLQuery = (tempVars, urlQueries) => {
|
||||||
|
const urlQueryTempVarsWithInvalidValues = _.reduce(
|
||||||
|
urlQueries,
|
||||||
|
(acc, v, k) => {
|
||||||
|
const matchedTempVar = tempVars.find(
|
||||||
|
({tempVar}) => stripTempVar(tempVar) === k
|
||||||
|
)
|
||||||
|
if (matchedTempVar) {
|
||||||
|
const isDifferentTempVarValue = !!matchedTempVar.values.find(
|
||||||
|
({value, selected}) => selected && value !== v
|
||||||
|
)
|
||||||
|
if (isDifferentTempVarValue) {
|
||||||
|
acc.push({key: k, value: v})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return acc
|
||||||
|
},
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
|
||||||
|
return urlQueryTempVarsWithInvalidValues
|
||||||
|
}
|
||||||
|
|
||||||
export const findInvalidTempVarsInURLQuery = (tempVars, urlQueries) => {
|
export const findInvalidTempVarsInURLQuery = (tempVars, urlQueries) => {
|
||||||
const urlQueryTempVarsWithInvalidValues = _.reduce(
|
const urlQueryTempVarsWithInvalidValues = _.reduce(
|
||||||
urlQueries,
|
urlQueries,
|
||||||
|
|
|
@ -202,6 +202,11 @@ export const notifyJSONFeedFailed = url => ({
|
||||||
message: `Failed to fetch JSON Feed for News Feed from '${url}'`,
|
message: `Failed to fetch JSON Feed for News Feed from '${url}'`,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export const notifyViewerUnauthorizedToSetTempVars = () => ({
|
||||||
|
...defaultErrorNotification,
|
||||||
|
message: `Viewer role unauthorized to override template variable values from URL.`,
|
||||||
|
})
|
||||||
|
|
||||||
// Chronograf Admin Notifications
|
// Chronograf Admin Notifications
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
export const notifyMappingDeleted = (id, scheme) => ({
|
export const notifyMappingDeleted = (id, scheme) => ({
|
||||||
|
|
Loading…
Reference in New Issue