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

[6.x] [ML] Adding rules and filters permission checks (#21097) #21129

Merged
merged 1 commit into from
Jul 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -32,6 +32,7 @@ import { EntityCell } from './entity_cell';
import { InfluencersCell } from './influencers_cell';
import { AnomalyDetails } from './anomaly_details';
import { LinksMenu } from './links_menu';
import { checkPermission } from 'plugins/ml/privilege/check_privilege';

import { mlAnomaliesTableService } from './anomalies_table_service';
import { mlFieldFormatService } from 'plugins/ml/services/field_format_service';
Expand All @@ -54,12 +55,11 @@ function renderTime(date, aggregationInterval) {
}

function showLinksMenuForItem(item) {
// TODO - add in checking of user privileges to see if they can view / edit rules.
const canViewRules = true;
return canViewRules ||
const canUpdateJob = checkPermission('canUpdateJob');
return (canUpdateJob ||
item.isTimeSeriesViewDetector ||
item.entityName === 'mlcategory' ||
item.customUrls !== undefined;
item.customUrls !== undefined);
}

function getColumns(
Expand Down
22 changes: 13 additions & 9 deletions x-pack/plugins/ml/public/components/anomalies_table/links_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import chrome from 'ui/chrome';
import { toastNotifications } from 'ui/notify';

import { ES_FIELD_TYPES } from 'plugins/ml/../common/constants/field_types';
import { checkPermission } from 'plugins/ml/privilege/check_privilege';
import { parseInterval } from 'plugins/ml/../common/util/parse_interval';
import { getFieldTypeFromMapping } from 'plugins/ml/services/mapping_service';
import { ml } from 'plugins/ml/services/ml_api_service';
Expand Down Expand Up @@ -335,6 +336,7 @@ export class LinksMenu extends Component {

render() {
const { anomaly, showViewSeriesLink } = this.props;
const canUpdateJob = checkPermission('canUpdateJob');

const button = (
<EuiButtonIcon
Expand Down Expand Up @@ -385,15 +387,17 @@ export class LinksMenu extends Component {
);
}

items.push(
<EuiContextMenuItem
key="create_rule"
icon="controlsHorizontal"
onClick={() => { this.closePopover(); this.props.showRuleEditorFlyout(anomaly); }}
>
Configure rules
</EuiContextMenuItem>
);
if (canUpdateJob) {
items.push(
<EuiContextMenuItem
key="create_rule"
icon="controlsHorizontal"
onClick={() => { this.closePopover(); this.props.showRuleEditorFlyout(anomaly); }}
>
Configure rules
</EuiContextMenuItem>
);
}

return (
<EuiPopover
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
import { toastNotifications } from 'ui/notify';

import { ActionsSection } from './actions_section';
import { checkPermission } from 'plugins/ml/privilege/check_privilege';
import { ConditionsSection } from './conditions_section';
import { ScopeSection } from './scope_section';
import { SelectRuleAction } from './select_rule_action';
Expand Down Expand Up @@ -67,6 +68,7 @@ export class RuleEditorFlyout extends Component {
};

this.partitioningFieldNames = [];
this.canGetFilters = checkPermission('canGetFilters');
}

componentDidMount() {
Expand Down Expand Up @@ -121,7 +123,7 @@ export class RuleEditorFlyout extends Component {
isFlyoutVisible: true
});

if (this.partitioningFieldNames.length > 0) {
if (this.partitioningFieldNames.length > 0 && this.canGetFilters) {
// Load the current list of filters.
ml.filters.filters()
.then((filters) => {
Expand Down
13 changes: 13 additions & 0 deletions x-pack/plugins/ml/public/components/rule_editor/scope_section.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
} from '@elastic/eui';

import { ScopeExpression } from './scope_expression';
import { checkPermission } from 'plugins/ml/privilege/check_privilege';
import { getScopeFieldDefaults } from './utils';


Expand Down Expand Up @@ -49,6 +50,14 @@ function NoFilterListsCallOut() {
);
}

function NoPermissionCallOut() {
return (
<EuiCallOut
title="You do not have permission to view filter lists"
iconType="gear"
/>
);
}

export function ScopeSection({
isEnabled,
Expand All @@ -58,6 +67,8 @@ export function ScopeSection({
scope,
updateScope }) {

const canGetFilters = checkPermission('canGetFilters');

if (partitioningFieldNames === null || partitioningFieldNames.length === 0) {
return null;
}
Expand Down Expand Up @@ -86,6 +97,8 @@ export function ScopeSection({
/>
);
});
} else if(canGetFilters === false) {
content = <NoPermissionCallOut />;
} else {
content = <NoFilterListsCallOut />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
EUI_MODAL_CONFIRM_BUTTON,
} from '@elastic/eui';

import { checkPermission } from 'plugins/ml/privilege/check_privilege';
import { deleteFilterLists } from './delete_filter_lists';

/*
Expand All @@ -28,6 +29,7 @@ export class DeleteFilterListModal extends Component {
this.state = {
isModalVisible: false
};
this.canDeleteFilter = checkPermission('canDeleteFilter');
}

closeModal = () => {
Expand Down Expand Up @@ -85,7 +87,7 @@ export class DeleteFilterListModal extends Component {
iconType="trash"
color="danger"
onClick={this.showModal}
isDisabled={selectedFilterLists.length === 0}
isDisabled={(selectedFilterLists.length === 0 || this.canDeleteFilter === false)}
>
Delete
</EuiButton>
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/ml/public/settings/filter_lists/list/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from '@elastic/eui';

import chrome from 'ui/chrome';
import { checkPermission } from 'plugins/ml/privilege/check_privilege';
import { DeleteFilterListModal } from '../components/delete_filter_list_modal';


Expand All @@ -44,10 +45,12 @@ UsedByIcon.propTypes = {
};

function NewFilterButton() {
const canCreateFilter = checkPermission('canCreateFilter');
return (
<EuiButton
key="new_filter_list"
href={`${chrome.getBasePath()}/app/ml#/settings/filter_lists/new_filter_list`}
isDisabled={(canCreateFilter === false)}
>
New
</EuiButton>
Expand Down
11 changes: 11 additions & 0 deletions x-pack/plugins/ml/public/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
</li>
<li class="col-xs-4 col-md-3 ng-scope">
<a
ng-if="(canCreateFilter === true)"
data-test-subj=""
class="management-panel__link ng-binding"
tooltip=""
Expand All @@ -39,6 +40,16 @@
href="ml#/settings/filter_lists">
Filter Lists
</a>
<span
ng-if="(canCreateFilter === false)"
class="management-panel__link disabled ng-binding"
tooltip="You do not have permission to manage filter lists"
tooltip-placement="bottom"
tooltip-popup-delay="400"
tooltip-append-to-body="1"
>
Filter Lists
</span>
</li>
</ul>
</div>
Expand Down
13 changes: 7 additions & 6 deletions x-pack/plugins/ml/public/settings/settings_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import uiRoutes from 'ui/routes';
import { checkLicense } from 'plugins/ml/license/check_license';
import { checkGetJobsPrivilege } from 'plugins/ml/privilege/check_privilege';
import { checkGetJobsPrivilege, checkPermission } from 'plugins/ml/privilege/check_privilege';
import { getMlNodeCount } from 'plugins/ml/ml_nodes_check/check_ml_nodes';
import { initPromise } from 'plugins/ml/util/promise';

Expand All @@ -30,9 +30,10 @@ uiRoutes
import { uiModules } from 'ui/modules';
const module = uiModules.get('apps/ml');

module.controller('MlSettings',
function () {
module.controller('MlSettings', function ($scope) {

timefilter.disableTimeRangeSelector(); // remove time picker from top of page
timefilter.disableAutoRefreshSelector(); // remove time picker from top of page
});
timefilter.disableTimeRangeSelector(); // remove time picker from top of page
timefilter.disableAutoRefreshSelector(); // remove time picker from top of page

$scope.canCreateFilter = checkPermission('canCreateFilter');
});
13 changes: 9 additions & 4 deletions x-pack/plugins/ml/public/settings/styles/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
}

ml-settings {
.management-panel .management-panel__link {
font-size: 17px;
line-height: 32px;
margin-left: 6px;
.management-panel {
.management-panel__link {
font-size: 17px;
line-height: 32px;
margin-left: 6px;
}
.disabled {
color: silver;
}
}
}

Expand Down