From f3ae23b5296725ccf712fe022eedfbf01d413d86 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Tue, 28 Jul 2020 13:46:53 +0100 Subject: [PATCH] small refactor --- .../lib/capabilities/capabilities_switcher.ts | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts b/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts index 0eeb7a8851345..f2fff4cc64aab 100644 --- a/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts +++ b/x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts @@ -30,24 +30,23 @@ function getSwitcher(license$: Observable, logger: Logger): Capabiliti try { const license = await license$.pipe(take(1)).toPromise(); - const mlCaps = capabilities.ml as MlCapabilities; - if (isMlEnabled(license) === false) { - disableAllCapabilities(mlCaps); - return capabilities; - } + const mlEnabled = isMlEnabled(license); // full license, leave capabilities as they were - if (isFullLicense(license)) { + if (mlEnabled && isFullLicense(license)) { return capabilities; } + const mlCaps = capabilities.ml as MlCapabilities; const originalCapabilities = cloneDeep(mlCaps); // not full licence, switch off all capabilities - disableAllCapabilities(mlCaps); + Object.keys(mlCaps).forEach((k) => { + mlCaps[k as keyof MlCapabilities] = false; + }); // for a basic license, reapply the original capabilities for the basic license features - if (isMinimumLicense(license)) { + if (mlEnabled && isMinimumLicense(license)) { basicLicenseMlCapabilities.forEach((c) => (mlCaps[c] = originalCapabilities[c])); } @@ -58,9 +57,3 @@ function getSwitcher(license$: Observable, logger: Logger): Capabiliti } }; } - -function disableAllCapabilities(mlCaps: MlCapabilities) { - Object.keys(mlCaps).forEach((k) => { - mlCaps[k as keyof MlCapabilities] = false; - }); -}