import { KibanaRequest } from 'kibana/server' ; import { PLUGIN_ID } from '../constants/app' ; import { ML_SAVED_OBJECT_TYPE } from './saved_objects' ; import { ML_ALERT_TYPES } from '../constants/alerts' ; export const apmUserMlCapabilities = { canGetJobs : false , canAccessML : false , } ; export const userMlCapabilities = { canAccessML : false , canGetJobs : false , canGetDatafeeds : false , canGetCalendars : false , canFindFileStructure : false , canGetDataFrameAnalytics : false , canGetAnnotations : false , canCreateAnnotation : false , canDeleteAnnotation : false , canUseMlAlerts : false , } ; export const adminMlCapabilities = { canCreateJob : false , canDeleteJob : false , canOpenJob : false , canCloseJob : false , canResetJob : false , canUpdateJob : false , canForecastJob : false , canCreateDatafeed : false , canDeleteDatafeed : false , canStartStopDatafeed : false , canUpdateDatafeed : false , canPreviewDatafeed : false , canGetFilters : false , canCreateCalendar : false , canDeleteCalendar : false , canCreateFilter : false , canDeleteFilter : false , canCreateDataFrameAnalytics : false , canDeleteDataFrameAnalytics : false , canStartStopDataFrameAnalytics : false , canCreateMlAlerts : false , canUseMlAlerts : false , canViewMlNodes : false , } ; export type UserMlCapabilities = typeof userMlCapabilities ; export type AdminMlCapabilities = typeof adminMlCapabilities ; export type MlCapabilities = UserMlCapabilities & AdminMlCapabilities ; export type MlCapabilitiesKey = keyof MlCapabilities ; export const basicLicenseMlCapabilities = [ 'canAccessML' , 'canFindFileStructure' ] as Array < keyof MlCapabilities > ; export function getDefaultCapabilities ( ) { return { ... userMlCapabilities , ... adminMlCapabilities , } ; } export function getPluginPrivileges ( ) { const apmUserMlCapabilitiesKeys = Object . keys ( apmUserMlCapabilities ) ; const userMlCapabilitiesKeys = Object . keys ( userMlCapabilities ) ; const adminMlCapabilitiesKeys = Object . keys ( adminMlCapabilities ) ; const allMlCapabilitiesKeys = [ ... adminMlCapabilitiesKeys , ... userMlCapabilitiesKeys ] ; const savedObjects = [ 'index-pattern' , 'dashboard' , 'search' , 'visualization' , ML_SAVED_OBJECT_TYPE , ] ; const privilege = { app : [ PLUGIN_ID , 'kibana' ] , excludeFromBasePrivileges : false , management : { insightsAndAlerting : [ 'jobsListLink' ] , } , catalogue : [ PLUGIN_ID ] , } ; return { admin : { ... privilege , api : [ 'fileUpload:analyzeFile' , ... allMlCapabilitiesKeys . map ( ( k ) => `ml:${ k }` ) ] , catalogue : [ PLUGIN_ID , `${ PLUGIN_ID }_file_data_visualizer` ] , ui : allMlCapabilitiesKeys , savedObject : { all : savedObjects , read : savedObjects , } , alerting : { rule : { all : Object . values ( ML_ALERT_TYPES ) , } , alert : { all : Object . values ( ML_ALERT_TYPES ) , } , } , } , user : { ... privilege , api : [ 'fileUpload:analyzeFile' , ... userMlCapabilitiesKeys . map ( ( k ) => `ml:${ k }` ) ] , catalogue : [ PLUGIN_ID ] , management : { insightsAndAlerting : [ ] } , ui : userMlCapabilitiesKeys , savedObject : { all : [ ] , read : savedObjects , } , alerting : { rule : { read : Object . values ( ML_ALERT_TYPES ) , } , alert : { read : Object . values ( ML_ALERT_TYPES ) , } , } , } , apmUser : { excludeFromBasePrivileges : true , app : [ ] , catalogue : [ ] , savedObject : { all : [ ] , read : [ ML_SAVED_OBJECT_TYPE ] , } , api : apmUserMlCapabilitiesKeys . map ( ( k ) => `ml:${ k }` ) , ui : apmUserMlCapabilitiesKeys , } , } ; } export interface MlCapabilitiesResponse { capabilities : MlCapabilities ; upgradeInProgress : boolean ; isPlatinumOrTrialLicense : boolean ; mlFeatureEnabledInSpace : boolean ; } export type ResolveMlCapabilities = ( request : KibanaRequest ) => Promise < MlCapabilities | null > ;