forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add platinum licensing check to Meta Engines table/call (elastic#11)
* Licensing plugin setup * Add LicensingContext setup * Update EngineOverview to not hit meta engines API on platinum license * Add Jest test helpers for future shallow/context use
- Loading branch information
Showing
15 changed files
with
204 additions
and
34 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
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
11 changes: 11 additions & 0 deletions
11
x-pack/plugins/enterprise_search/public/applications/__mocks__/license_context.mock.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,11 @@ | ||
/* | ||
* 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 { licensingMock } from '../../../../licensing/public/mocks'; | ||
|
||
export const mockLicenseContext = { | ||
license: licensingMock.createLicense(), | ||
}; |
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
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
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
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/enterprise_search/public/applications/shared/licensing/index.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,8 @@ | ||
/* | ||
* 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 { LicenseContext, LicenseProvider, ILicenseContext } from './license_context'; | ||
export { hasPlatinumLicense } from './license_checks'; |
33 changes: 33 additions & 0 deletions
33
x-pack/plugins/enterprise_search/public/applications/shared/licensing/license_checks.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,33 @@ | ||
/* | ||
* 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 { hasPlatinumLicense } from './license_checks'; | ||
|
||
describe('hasPlatinumLicense', () => { | ||
it('is true for platinum licenses', () => { | ||
expect(hasPlatinumLicense({ isActive: true, type: 'platinum' })).toEqual(true); | ||
}); | ||
|
||
it('is true for enterprise licenses', () => { | ||
expect(hasPlatinumLicense({ isActive: true, type: 'enterprise' })).toEqual(true); | ||
}); | ||
|
||
it('is true for trial licenses', () => { | ||
expect(hasPlatinumLicense({ isActive: true, type: 'platinum' })).toEqual(true); | ||
}); | ||
|
||
it('is false if the current license is expired', () => { | ||
expect(hasPlatinumLicense({ isActive: false, type: 'platinum' })).toEqual(false); | ||
expect(hasPlatinumLicense({ isActive: false, type: 'enterprise' })).toEqual(false); | ||
expect(hasPlatinumLicense({ isActive: false, type: 'trial' })).toEqual(false); | ||
}); | ||
|
||
it('is false for licenses below platinum', () => { | ||
expect(hasPlatinumLicense({ isActive: true, type: 'basic' })).toEqual(false); | ||
expect(hasPlatinumLicense({ isActive: false, type: 'standard' })).toEqual(false); | ||
expect(hasPlatinumLicense({ isActive: true, type: 'gold' })).toEqual(false); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
x-pack/plugins/enterprise_search/public/applications/shared/licensing/license_checks.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,11 @@ | ||
/* | ||
* 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 { ILicense } from '../../../../../../licensing/public'; | ||
|
||
export const hasPlatinumLicense = (license: ILicenseContext) => { | ||
return license?.isActive && ['platinum', 'enterprise', 'trial'].includes(license?.type); | ||
}; |
28 changes: 28 additions & 0 deletions
28
...k/plugins/enterprise_search/public/applications/shared/licensing/license_context.test.tsx
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,28 @@ | ||
/* | ||
* 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 React, { useContext } from 'react'; | ||
|
||
import { mountWithKibanaContext } from '../../__mocks__'; | ||
import { LicenseContext, ILicenseContext } from './'; | ||
|
||
describe('LicenseProvider', () => { | ||
const MockComponent: React.FC<> = () => { | ||
const { license } = useContext(LicenseContext) as ILicenseContext; | ||
return <div className="license-test">{license.type}</div>; | ||
}; | ||
|
||
it('renders children', () => { | ||
const wrapper = mountWithKibanaContext( | ||
<LicenseContext.Provider value={{ license: { type: 'basic' } }}> | ||
<MockComponent /> | ||
</LicenseContext.Provider> | ||
); | ||
|
||
expect(wrapper.find('.license-test')).toHaveLength(1); | ||
expect(wrapper.text()).toEqual('basic'); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
x-pack/plugins/enterprise_search/public/applications/shared/licensing/license_context.tsx
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,27 @@ | ||
/* | ||
* 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 React, { useContext } from 'react'; | ||
import useObservable from 'react-use/lib/useObservable'; | ||
|
||
import { KibanaContext, IKibanaContext } from '../../'; | ||
|
||
import { ILicense } from '../../../../licensing/public'; | ||
|
||
export interface ILicenseContext { | ||
license?: ILicense; | ||
} | ||
|
||
export const LicenseContext = React.createContext(); | ||
|
||
export const LicenseProvider: React.FC<> = ({ children }) => { | ||
// Listen for changes to license subscription | ||
const { license$ } = useContext(KibanaContext) as IKibanaContext; | ||
const license = useObservable(license$); | ||
|
||
// Render rest of application and pass down license via context | ||
return <LicenseContext.Provider value={{ license }} children={children} />; | ||
}; |
Oops, something went wrong.