forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spaces - migrate default space and enter space view to KP (elastic#66098
) (elastic#66336)
- Loading branch information
Showing
14 changed files
with
601 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
x-pack/legacy/plugins/spaces/server/routes/views/enter_space.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { SpacesLicense } from '.'; | ||
|
||
export const licenseMock = { | ||
create: (): jest.Mocked<SpacesLicense> => ({ | ||
isEnabled: jest.fn().mockReturnValue(true), | ||
}), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { SpacesLicenseService, SpacesLicense } from './license_service'; |
46 changes: 46 additions & 0 deletions
46
x-pack/plugins/spaces/common/licensing/license_service.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { of } from 'rxjs'; | ||
import { licensingMock } from '../../../licensing/public/mocks'; | ||
import { SpacesLicenseService } from './license_service'; | ||
import { LICENSE_TYPE, LicenseType } from '../../../licensing/common/types'; | ||
|
||
describe('license#isEnabled', function() { | ||
it('should indicate that Spaces is disabled when there is no license information', () => { | ||
const serviceSetup = new SpacesLicenseService().setup({ | ||
license$: of(undefined as any), | ||
}); | ||
expect(serviceSetup.license.isEnabled()).toEqual(false); | ||
}); | ||
|
||
it('should indicate that Spaces is disabled when xpack is unavailable', () => { | ||
const rawLicenseMock = licensingMock.createLicenseMock(); | ||
rawLicenseMock.isAvailable = false; | ||
const serviceSetup = new SpacesLicenseService().setup({ | ||
license$: of(rawLicenseMock), | ||
}); | ||
expect(serviceSetup.license.isEnabled()).toEqual(false); | ||
}); | ||
|
||
for (const level in LICENSE_TYPE) { | ||
if (isNaN(level as any)) { | ||
it(`should indicate that Spaces is enabled with a ${level} license`, () => { | ||
const rawLicense = licensingMock.createLicense({ | ||
license: { | ||
status: 'active', | ||
type: level as LicenseType, | ||
}, | ||
}); | ||
|
||
const serviceSetup = new SpacesLicenseService().setup({ | ||
license$: of(rawLicense), | ||
}); | ||
expect(serviceSetup.license.isEnabled()).toEqual(true); | ||
}); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { Observable, Subscription } from 'rxjs'; | ||
import { ILicense } from '../../../licensing/common/types'; | ||
|
||
export interface SpacesLicense { | ||
isEnabled(): boolean; | ||
} | ||
|
||
interface SetupDeps { | ||
license$: Observable<ILicense>; | ||
} | ||
|
||
export class SpacesLicenseService { | ||
private licenseSubscription?: Subscription; | ||
|
||
public setup({ license$ }: SetupDeps) { | ||
let rawLicense: Readonly<ILicense> | undefined; | ||
|
||
this.licenseSubscription = license$.subscribe(nextRawLicense => { | ||
rawLicense = nextRawLicense; | ||
}); | ||
|
||
return { | ||
license: Object.freeze({ | ||
isEnabled: () => this.isSpacesEnabledFromRawLicense(rawLicense), | ||
}), | ||
}; | ||
} | ||
|
||
public stop() { | ||
if (this.licenseSubscription) { | ||
this.licenseSubscription.unsubscribe(); | ||
this.licenseSubscription = undefined; | ||
} | ||
} | ||
|
||
private isSpacesEnabledFromRawLicense(rawLicense: Readonly<ILicense> | undefined) { | ||
if (!rawLicense || !rawLicense.isAvailable) { | ||
return false; | ||
} | ||
|
||
const licenseCheck = rawLicense.check('spaces', 'basic'); | ||
return licenseCheck.state !== 'unavailable' && licenseCheck.state !== 'invalid'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.