From 865975f7b245566162cf1d264a126fac64b5fcf1 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Mon, 23 Jul 2018 18:00:52 +0100 Subject: [PATCH 1/2] [ML] Adding rules and filters permission checks --- .../anomalies_table/anomalies_table.js | 8 +++---- .../components/anomalies_table/links_menu.js | 22 +++++++++++-------- .../rule_editor/rule_editor_flyout.js | 4 +++- .../components/rule_editor/scope_section.js | 13 +++++++++++ .../delete_filter_list_modal.js | 4 +++- .../settings/filter_lists/list/table.js | 3 +++ .../plugins/ml/public/settings/settings.html | 10 +++++++++ .../ml/public/settings/settings_controller.js | 13 ++++++----- .../ml/public/settings/styles/main.less | 13 +++++++---- 9 files changed, 65 insertions(+), 25 deletions(-) diff --git a/x-pack/plugins/ml/public/components/anomalies_table/anomalies_table.js b/x-pack/plugins/ml/public/components/anomalies_table/anomalies_table.js index e229cae321168..7f1e37999795a 100644 --- a/x-pack/plugins/ml/public/components/anomalies_table/anomalies_table.js +++ b/x-pack/plugins/ml/public/components/anomalies_table/anomalies_table.js @@ -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'; @@ -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( diff --git a/x-pack/plugins/ml/public/components/anomalies_table/links_menu.js b/x-pack/plugins/ml/public/components/anomalies_table/links_menu.js index 1855b5b50297e..fe7e02e9b8b46 100644 --- a/x-pack/plugins/ml/public/components/anomalies_table/links_menu.js +++ b/x-pack/plugins/ml/public/components/anomalies_table/links_menu.js @@ -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'; @@ -335,6 +336,7 @@ export class LinksMenu extends Component { render() { const { anomaly, showViewSeriesLink } = this.props; + const canUpdateJob = checkPermission('canUpdateJob'); const button = ( { this.closePopover(); this.props.showRuleEditorFlyout(anomaly); }} - > - Configure rules - - ); + if (canUpdateJob) { + items.push( + { this.closePopover(); this.props.showRuleEditorFlyout(anomaly); }} + > + Configure rules + + ); + } return ( 0) { + if (this.partitioningFieldNames.length > 0 && this.canGetFilters) { // Load the current list of filters. ml.filters.filters() .then((filters) => { diff --git a/x-pack/plugins/ml/public/components/rule_editor/scope_section.js b/x-pack/plugins/ml/public/components/rule_editor/scope_section.js index d7c52fab492be..63a2ffc34f319 100644 --- a/x-pack/plugins/ml/public/components/rule_editor/scope_section.js +++ b/x-pack/plugins/ml/public/components/rule_editor/scope_section.js @@ -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'; @@ -49,6 +50,14 @@ function NoFilterListsCallOut() { ); } +function NoPermissionCallOut() { + return ( + + ); +} export function ScopeSection({ isEnabled, @@ -58,6 +67,8 @@ export function ScopeSection({ scope, updateScope }) { + const canGetFilters = checkPermission('canGetFilters'); + if (partitioningFieldNames === null || partitioningFieldNames.length === 0) { return null; } @@ -86,6 +97,8 @@ export function ScopeSection({ /> ); }); + } else if(canGetFilters === false) { + content = ; } else { content = ; } diff --git a/x-pack/plugins/ml/public/settings/filter_lists/components/delete_filter_list_modal/delete_filter_list_modal.js b/x-pack/plugins/ml/public/settings/filter_lists/components/delete_filter_list_modal/delete_filter_list_modal.js index 25511700558c8..43b5be11a4ca7 100644 --- a/x-pack/plugins/ml/public/settings/filter_lists/components/delete_filter_list_modal/delete_filter_list_modal.js +++ b/x-pack/plugins/ml/public/settings/filter_lists/components/delete_filter_list_modal/delete_filter_list_modal.js @@ -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'; /* @@ -28,6 +29,7 @@ export class DeleteFilterListModal extends Component { this.state = { isModalVisible: false }; + this.canDeleteFilter = checkPermission('canDeleteFilter'); } closeModal = () => { @@ -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 diff --git a/x-pack/plugins/ml/public/settings/filter_lists/list/table.js b/x-pack/plugins/ml/public/settings/filter_lists/list/table.js index f80e8c53958e5..d3c170883213d 100644 --- a/x-pack/plugins/ml/public/settings/filter_lists/list/table.js +++ b/x-pack/plugins/ml/public/settings/filter_lists/list/table.js @@ -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'; @@ -44,10 +45,12 @@ UsedByIcon.propTypes = { }; function NewFilterButton() { + const canCreateFilter = checkPermission('canCreateFilter'); return ( New diff --git a/x-pack/plugins/ml/public/settings/settings.html b/x-pack/plugins/ml/public/settings/settings.html index 4ec6ab99ced7e..265e846729363 100644 --- a/x-pack/plugins/ml/public/settings/settings.html +++ b/x-pack/plugins/ml/public/settings/settings.html @@ -30,6 +30,7 @@
  • Filter Lists + + Filter Lists +
  • diff --git a/x-pack/plugins/ml/public/settings/settings_controller.js b/x-pack/plugins/ml/public/settings/settings_controller.js index e82cf9a15d4d9..ea4311cb40d23 100644 --- a/x-pack/plugins/ml/public/settings/settings_controller.js +++ b/x-pack/plugins/ml/public/settings/settings_controller.js @@ -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'; @@ -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'); +}); diff --git a/x-pack/plugins/ml/public/settings/styles/main.less b/x-pack/plugins/ml/public/settings/styles/main.less index 80de8028b3b6a..edf655f96d406 100644 --- a/x-pack/plugins/ml/public/settings/styles/main.less +++ b/x-pack/plugins/ml/public/settings/styles/main.less @@ -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; + } } } From 415a8802f3e5425cb355dfdeb35f60f088e3dee0 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Mon, 23 Jul 2018 18:04:14 +0100 Subject: [PATCH 2/2] fixing disabled link check --- x-pack/plugins/ml/public/settings/settings.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/ml/public/settings/settings.html b/x-pack/plugins/ml/public/settings/settings.html index 265e846729363..738297f346400 100644 --- a/x-pack/plugins/ml/public/settings/settings.html +++ b/x-pack/plugins/ml/public/settings/settings.html @@ -30,7 +30,7 @@