From 3abe7e0478899b2859c12f4290a9fef2408ece9d Mon Sep 17 00:00:00 2001 From: Bill McConaghy Date: Mon, 15 Oct 2018 10:22:30 -0400 Subject: [PATCH 1/2] block user from proceeding when she has no permissions to view rollup jobs --- .../sections/job_list/job_list.container.js | 2 + .../crud_app/sections/job_list/job_list.js | 60 ++++++++++++++----- .../crud_app/store/actions/load_jobs.js | 1 + .../public/crud_app/store/reducers/jobs.js | 1 + .../public/crud_app/store/selectors/index.js | 1 + 5 files changed, 51 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/rollup/public/crud_app/sections/job_list/job_list.container.js b/x-pack/plugins/rollup/public/crud_app/sections/job_list/job_list.container.js index 6a7949a856358..b0281994b55a5 100644 --- a/x-pack/plugins/rollup/public/crud_app/sections/job_list/job_list.container.js +++ b/x-pack/plugins/rollup/public/crud_app/sections/job_list/job_list.container.js @@ -10,6 +10,7 @@ import { JobList as JobListView } from './job_list'; import { getPageOfJobs, isLoading, + jobLoadError } from '../../store/selectors'; import { @@ -23,6 +24,7 @@ const mapStateToProps = (state) => { return { jobs: getPageOfJobs(state), isLoading: isLoading(state), + jobLoadError: jobLoadError(state), }; }; diff --git a/x-pack/plugins/rollup/public/crud_app/sections/job_list/job_list.js b/x-pack/plugins/rollup/public/crud_app/sections/job_list/job_list.js index 1b26ae767b31c..3587a724dbea6 100644 --- a/x-pack/plugins/rollup/public/crud_app/sections/job_list/job_list.js +++ b/x-pack/plugins/rollup/public/crud_app/sections/job_list/job_list.js @@ -19,9 +19,11 @@ import { EuiPageContent, EuiPageContentHeader, EuiPageContentHeaderSection, + EuiSpacer, EuiText, EuiTextColor, EuiTitle, + EuiCallOut, } from '@elastic/eui'; import { CRUD_APP_BASE_PATH } from '../../constants'; @@ -85,7 +87,45 @@ export class JobListUi extends Component { // this page. this.props.closeDetailPanel(); } - + getHeaderSection() { + return ( + + +

+ +

+
+
+ ); + } + renderNoPermission() { + + const { intl, jobLoadError } = this.props; + console.log(jobLoadError); + const title = intl.formatMessage({ + id: 'xpack.rollupJobs.jobList.noPermissionTitle', + defaultMessage: 'Permission error', + }); + return ( + + {this.getHeaderSection()} + + + + + + ); + } renderEmpty() { return ( - - -

- -

-
-
+ {this.getHeaderSection()} @@ -190,11 +221,12 @@ export class JobListUi extends Component { } render() { - const { isLoading, jobs } = this.props; + const { isLoading, jobs, jobLoadError } = this.props; let content; - - if (!isLoading && !jobs.length) { + if (jobLoadError && jobLoadError.status === 403) { + content = this.renderNoPermission(); + } else if (!isLoading && !jobs.length) { content = this.renderEmpty(); } else { content = this.renderList(); diff --git a/x-pack/plugins/rollup/public/crud_app/store/actions/load_jobs.js b/x-pack/plugins/rollup/public/crud_app/store/actions/load_jobs.js index adddd5d0a0976..65891ebff33b0 100644 --- a/x-pack/plugins/rollup/public/crud_app/store/actions/load_jobs.js +++ b/x-pack/plugins/rollup/public/crud_app/store/actions/load_jobs.js @@ -23,6 +23,7 @@ export const loadJobs = () => async (dispatch) => { } catch (error) { dispatch({ type: LOAD_JOBS_FAILURE, + payload: { error } }); return toastNotifications.addDanger(error.data.message); diff --git a/x-pack/plugins/rollup/public/crud_app/store/reducers/jobs.js b/x-pack/plugins/rollup/public/crud_app/store/reducers/jobs.js index 4a430dfd4eef9..5e6f7834aacb7 100644 --- a/x-pack/plugins/rollup/public/crud_app/store/reducers/jobs.js +++ b/x-pack/plugins/rollup/public/crud_app/store/reducers/jobs.js @@ -57,6 +57,7 @@ export function jobs(state = initialState, action) { return { ...state, isLoading: false, + jobLoadError: payload.error }; case CREATE_JOB_SUCCESS: diff --git a/x-pack/plugins/rollup/public/crud_app/store/selectors/index.js b/x-pack/plugins/rollup/public/crud_app/store/selectors/index.js index 0300aa4a1c014..5a6072e5e3d8a 100644 --- a/x-pack/plugins/rollup/public/crud_app/store/selectors/index.js +++ b/x-pack/plugins/rollup/public/crud_app/store/selectors/index.js @@ -21,6 +21,7 @@ export const getDetailPanelJob = (state) => getJobByJobId(state, state.detailPan export const getDetailPanelJobId = (state) => state.detailPanel.jobId; export const isLoading = (state) => state.jobs.isLoading; +export const jobLoadError = (state) => state.jobs.jobLoadError; export const isSaving = (state) => state.createJob.isSaving; export const getCreateJobError = (state) => state.createJob.error; From a66010abd7bae71a4d60b5e7889f3c9f6c1882dd Mon Sep 17 00:00:00 2001 From: Bill McConaghy Date: Mon, 15 Oct 2018 12:01:53 -0400 Subject: [PATCH 2/2] removing stray console.log --- .../rollup/public/crud_app/sections/job_list/job_list.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/x-pack/plugins/rollup/public/crud_app/sections/job_list/job_list.js b/x-pack/plugins/rollup/public/crud_app/sections/job_list/job_list.js index 3587a724dbea6..52b459cc781b8 100644 --- a/x-pack/plugins/rollup/public/crud_app/sections/job_list/job_list.js +++ b/x-pack/plugins/rollup/public/crud_app/sections/job_list/job_list.js @@ -102,9 +102,7 @@ export class JobListUi extends Component { ); } renderNoPermission() { - - const { intl, jobLoadError } = this.props; - console.log(jobLoadError); + const { intl } = this.props; const title = intl.formatMessage({ id: 'xpack.rollupJobs.jobList.noPermissionTitle', defaultMessage: 'Permission error',