import { i18n } from '@kbn/i18n' ; import { Privileges } from '../../../../../common/types/privileges' ; import { isPopulatedObject } from '../../../../../common/shared_imports' ; export interface Capabilities { canGetTransform : boolean ; canDeleteTransform : boolean ; canPreviewTransform : boolean ; canCreateTransform : boolean ; canStartStopTransform : boolean ; canCreateTransformAlerts : boolean ; canUseTransformAlerts : boolean ; } export type Privilege = [ string , string ] ; function isPrivileges ( arg ) { return ( isPopulatedObject ( arg , [ 'hasAllPrivileges' , 'missingPrivileges' ] ) && typeof arg . hasAllPrivileges === 'boolean' && typeof arg . missingPrivileges === 'object' && arg . missingPrivileges !== null ) ; } export const toArray = ( value ) : string [ ] => Array . isArray ( value ) ? value : [ value ] ; export const hasPrivilegeFactory = ( privileges ) => ( privilege ) => { const [ section , requiredPrivilege ] = privilege ; if ( isPrivileges ( privileges ) && ! privileges . missingPrivileges [ section ] ) { return true ; } if ( isPrivileges ( privileges ) && privileges . missingPrivileges [ section ] ! . length === 0 ) { return true ; } if ( requiredPrivilege === '*' ) { return false ; } return ( isPrivileges ( privileges ) && ! privileges . missingPrivileges [ section ] ! . includes ( requiredPrivilege ) ) ; } ; export function createCapabilityFailureMessage ( capability ) { let message = '' ; switch ( capability ) { case 'canCreateTransform' : message = i18n . translate ( 'xpack.transform.capability.noPermission.createTransformTooltip' , { defaultMessage : 'You do not have permission to create transforms.' , } ) ; break ; case 'canCreateTransformAlerts' : message = i18n . translate ( 'xpack.transform.capability.noPermission.canCreateTransformAlertsTooltip' , { defaultMessage : 'You do not have permission to create transform alert rules.' , } ) ; break ; case 'canStartStopTransform' : message = i18n . translate ( 'xpack.transform.capability.noPermission.startOrStopTransformTooltip' , { defaultMessage : 'You do not have permission to start or stop transforms.' , } ) ; break ; case 'canDeleteTransform' : message = i18n . translate ( 'xpack.transform.capability.noPermission.deleteTransformTooltip' , { defaultMessage : 'You do not have permission to delete transforms.' , } ) ; break ; case 'noTransformNodes' : message = i18n . translate ( 'xpack.transform.capability.noPermission.noTransformNodesTooltip' , { defaultMessage : 'There are no transform nodes available.' , } ) ; break ; } return i18n . translate ( 'xpack.transform.capability.pleaseContactAdministratorTooltip' , { defaultMessage : '{message} Please contact your administrator.' , values : { message , } , } ) ; }