Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

block user from proceeding when she has no permissions to view rollup… #24024

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { JobList as JobListView } from './job_list';
import {
getPageOfJobs,
isLoading,
jobLoadError
} from '../../store/selectors';

import {
Expand All @@ -23,6 +24,7 @@ const mapStateToProps = (state) => {
return {
jobs: getPageOfJobs(state),
isLoading: isLoading(state),
jobLoadError: jobLoadError(state),
};
};

Expand Down
60 changes: 46 additions & 14 deletions x-pack/plugins/rollup/public/crud_app/sections/job_list/job_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import {
EuiPageContent,
EuiPageContentHeader,
EuiPageContentHeaderSection,
EuiSpacer,
EuiText,
EuiTextColor,
EuiTitle,
EuiCallOut,
} from '@elastic/eui';

import { CRUD_APP_BASE_PATH } from '../../constants';
Expand Down Expand Up @@ -85,7 +87,45 @@ export class JobListUi extends Component {
// this page.
this.props.closeDetailPanel();
}

getHeaderSection() {
return (
<EuiPageContentHeaderSection>
<EuiTitle size="l">
<h1>
<FormattedMessage
id="xpack.rollupJobs.jobListTitle"
defaultMessage="Rollup jobs"
/>
</h1>
</EuiTitle>
</EuiPageContentHeaderSection>
);
}
renderNoPermission() {

const { intl, jobLoadError } = this.props;
console.log(jobLoadError);
bmcconaghy marked this conversation as resolved.
Show resolved Hide resolved
const title = intl.formatMessage({
id: 'xpack.rollupJobs.jobList.noPermissionTitle',
defaultMessage: 'Permission error',
});
return (
<Fragment>
{this.getHeaderSection()}
<EuiSpacer size="m" />
<EuiCallOut
title={title}
color="warning"
iconType="help"
>
<FormattedMessage
id="xpack.rollupJobs.jobList.noPermissionText"
defaultMessage="You do not have permission to view or add rollup jobs."
/>
</EuiCallOut>
</Fragment>
);
}
renderEmpty() {
return (
<EuiEmptyPrompt
Expand Down Expand Up @@ -161,16 +201,7 @@ export class JobListUi extends Component {
return (
<Fragment>
<EuiPageContentHeader>
<EuiPageContentHeaderSection>
<EuiTitle size="l">
<h1>
<FormattedMessage
id="xpack.rollupJobs.jobListTitle"
defaultMessage="Rollup jobs"
/>
</h1>
</EuiTitle>
</EuiPageContentHeaderSection>
{this.getHeaderSection()}

<EuiPageContentHeaderSection>
<EuiButton fill {...getRouterLinkProps(`${CRUD_APP_BASE_PATH}/create`)}>
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const loadJobs = () => async (dispatch) => {
} catch (error) {
dispatch({
type: LOAD_JOBS_FAILURE,
payload: { error }
});

return toastNotifications.addDanger(error.data.message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function jobs(state = initialState, action) {
return {
...state,
isLoading: false,
jobLoadError: payload.error
};

case CREATE_JOB_SUCCESS:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down