[Canvas] Fixes workpad update error for read only users (#32831) (#32838)

* waits for write permission test before loading workpad

* Adds setRefreshInterval to list of skipped actions in es_persist
This commit is contained in:
Catherine Liu 2019-03-09 22:18:25 -07:00 committed by GitHub
parent 41b8931569
commit b41c59a9a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View file

@ -55,21 +55,21 @@ export const routes = [
try {
const fetchedWorkpad = await workpadService.get(params.id);
const { assets, ...workpad } = fetchedWorkpad;
dispatch(setWorkpad(workpad));
dispatch(setAssets(assets));
// tests if user has permissions to write to workpads
// TODO: remove this and switch to checking user privileges when canvas loads when granular app privileges are introduced
// https://github.com/elastic/kibana/issues/20277
if (firstLoad) {
workpadService.update(params.id, fetchedWorkpad).catch(err => {
await workpadService.update(params.id, fetchedWorkpad).catch(err => {
if (err.response && err.response.status === 403) {
dispatch(setCanUserWrite(false));
}
});
dispatch(setFirstLoad(false));
}
const { assets, ...workpad } = fetchedWorkpad;
dispatch(setWorkpad(workpad));
dispatch(setAssets(assets));
} catch (err) {
notify.error(err, { title: `Couldn't load workpad with ID` });
return router.redirectTo('home');

View file

@ -7,7 +7,7 @@
import { isEqual } from 'lodash';
import { getWorkpad, getFullWorkpadPersisted, getWorkpadPersisted } from '../selectors/workpad';
import { getAssetIds } from '../selectors/assets';
import { setWorkpad } from '../actions/workpad';
import { setWorkpad, setRefreshInterval } from '../actions/workpad';
import { setAssets, resetAssets } from '../actions/assets';
import * as transientActions from '../actions/transient';
import * as resolvedArgsActions from '../actions/resolved_args';
@ -31,6 +31,7 @@ export const esPersistMiddleware = ({ getState }) => {
setWorkpad, // used for loading and creating workpads
setAssets, // used when loading assets
resetAssets, // used when creating new workpads
setRefreshInterval, // used to set refresh time interval which is a transient value
...Object.values(resolvedArgsActions), // no resolved args affect persisted values
...Object.values(transientActions), // no transient actions cause persisted state changes
].map(a => a.toString());