Skip to content

Commit

Permalink
small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Jul 28, 2020
1 parent aeab5f0 commit f3ae23b
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,23 @@ function getSwitcher(license$: Observable<ILicense>, 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]));
}

Expand All @@ -58,9 +57,3 @@ function getSwitcher(license$: Observable<ILicense>, logger: Logger): Capabiliti
}
};
}

function disableAllCapabilities(mlCaps: MlCapabilities) {
Object.keys(mlCaps).forEach((k) => {
mlCaps[k as keyof MlCapabilities] = false;
});
}

0 comments on commit f3ae23b

Please sign in to comment.