Skip to content

Commit f3ae23b

Browse files
committed
small refactor
1 parent aeab5f0 commit f3ae23b

1 file changed

Lines changed: 7 additions & 14 deletions

File tree

x-pack/plugins/ml/server/lib/capabilities/capabilities_switcher.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,23 @@ function getSwitcher(license$: Observable<ILicense>, logger: Logger): Capabiliti
3030

3131
try {
3232
const license = await license$.pipe(take(1)).toPromise();
33-
const mlCaps = capabilities.ml as MlCapabilities;
34-
if (isMlEnabled(license) === false) {
35-
disableAllCapabilities(mlCaps);
36-
return capabilities;
37-
}
33+
const mlEnabled = isMlEnabled(license);
3834

3935
// full license, leave capabilities as they were
40-
if (isFullLicense(license)) {
36+
if (mlEnabled && isFullLicense(license)) {
4137
return capabilities;
4238
}
4339

40+
const mlCaps = capabilities.ml as MlCapabilities;
4441
const originalCapabilities = cloneDeep(mlCaps);
4542

4643
// not full licence, switch off all capabilities
47-
disableAllCapabilities(mlCaps);
44+
Object.keys(mlCaps).forEach((k) => {
45+
mlCaps[k as keyof MlCapabilities] = false;
46+
});
4847

4948
// for a basic license, reapply the original capabilities for the basic license features
50-
if (isMinimumLicense(license)) {
49+
if (mlEnabled && isMinimumLicense(license)) {
5150
basicLicenseMlCapabilities.forEach((c) => (mlCaps[c] = originalCapabilities[c]));
5251
}
5352

@@ -58,9 +57,3 @@ function getSwitcher(license$: Observable<ILicense>, logger: Logger): Capabiliti
5857
}
5958
};
6059
}
61-
62-
function disableAllCapabilities(mlCaps: MlCapabilities) {
63-
Object.keys(mlCaps).forEach((k) => {
64-
mlCaps[k as keyof MlCapabilities] = false;
65-
});
66-
}

0 commit comments

Comments
 (0)