Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Capabilities to new platform #51438

Merged
merged 41 commits into from
Dec 3, 2019
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8774c11
create service skeleton
pgayvallet Nov 21, 2019
7b38121
move registerCapabilitiesModifier to capabilities service and rename …
pgayvallet Nov 21, 2019
590e743
starts to move capabilities logic to CapabilitiesService
pgayvallet Nov 21, 2019
a0628bb
move capabilities route to service
pgayvallet Nov 22, 2019
5182e14
add initial integration test for capabilities route
pgayvallet Nov 22, 2019
b700cda
capabilitiesMixin now delegates to capability service
pgayvallet Nov 22, 2019
ca62942
use server-side Capabilities import in server code
pgayvallet Nov 22, 2019
0d27559
update generated doc
pgayvallet Nov 22, 2019
85b8645
remove capabilities from injectedMetadatas
pgayvallet Nov 25, 2019
bdd07d0
use applications sent from client instead of server-registered navLinks
pgayvallet Nov 25, 2019
6650273
disable authRequired for capabilities route
pgayvallet Nov 25, 2019
dd160fe
(temp) exposes two endpoints for capabilities
pgayvallet Nov 25, 2019
ad99a96
Add fetch-mock on capabilities call for karma tests
pgayvallet Nov 25, 2019
90234d7
adapt xpack Capabilities test - first attempt
pgayvallet Nov 25, 2019
3a81fb6
adapt x-pack ui_capabilities test
pgayvallet Nov 25, 2019
f5acc1f
add '/status' to the list of anonymous pages
pgayvallet Nov 26, 2019
2c66167
Add documentation on Capabilities APIs
pgayvallet Nov 26, 2019
33848c1
move Capabilities to core/types
pgayvallet Nov 26, 2019
bd7064e
update generated docs
pgayvallet Nov 26, 2019
bd98c78
add service tests
pgayvallet Nov 26, 2019
d4ce55c
protecting resolveCapabilities against added/removed capabilities
pgayvallet Nov 26, 2019
7746d5d
update generated docs
pgayvallet Nov 26, 2019
e99dba8
adapt mocks due to rebase
pgayvallet Nov 26, 2019
f6c76d2
add forgotten exports
pgayvallet Nov 26, 2019
707a2c4
improve capabilities routes registering
pgayvallet Nov 27, 2019
a1cc7fc
name capabilities registering methods
pgayvallet Nov 27, 2019
1625cb3
Merge remote-tracking branch 'upstream/master' into kbn-45393-capabil…
pgayvallet Nov 27, 2019
912cb8f
Merge remote-tracking branch 'upstream/master' into kbn-45393-capabil…
pgayvallet Nov 27, 2019
997e476
resolve conflicts due to merge
pgayvallet Nov 27, 2019
b37034a
address review issues
pgayvallet Nov 27, 2019
ebcfdde
add comment about reason for exposing two routes
pgayvallet Nov 29, 2019
ad0ffbb
extract createHttpServer test helper
pgayvallet Nov 29, 2019
349e1d8
Merge remote-tracking branch 'upstream/master' into kbn-45393-capabil…
pgayvallet Nov 29, 2019
d705f69
fix merge conflicts
pgayvallet Nov 29, 2019
9518a8d
Merge remote-tracking branch 'upstream/master' into kbn-45393-capabil…
pgayvallet Nov 29, 2019
a20df2a
Merge remote-tracking branch 'upstream/master' into kbn-45393-capabil…
pgayvallet Dec 2, 2019
7cb5513
improve documentation
pgayvallet Dec 2, 2019
dbf5131
remove `/status` anon registration as now done in NP status plugin
pgayvallet Dec 2, 2019
c4e313f
Merge remote-tracking branch 'upstream/master' into kbn-45393-capabil…
pgayvallet Dec 2, 2019
f66b237
Merge remote-tracking branch 'upstream/master' into kbn-45393-capabil…
pgayvallet Dec 3, 2019
4cee19c
fix merge conflicts
pgayvallet Dec 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ module.exports = {
'!src/core/server/index.ts',
'!src/core/server/mocks.ts',
'!src/core/server/types.ts',
'!src/core/server/test_utils.ts',
// for absolute imports until fixed in
// https://github.com/elastic/kibana/issues/36096
'!src/core/server/types',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [Capabilities](./kibana-plugin-server.capabilities.md) &gt; [catalogue](./kibana-plugin-server.capabilities.catalogue.md)

## Capabilities.catalogue property

Catalogue capabilities. Catalogue entries drive the visibility of the Kibana homepage options.

<b>Signature:</b>

```typescript
catalogue: Record<string, boolean>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [Capabilities](./kibana-plugin-server.capabilities.md) &gt; [management](./kibana-plugin-server.capabilities.management.md)

## Capabilities.management property

Management section capabilities.

<b>Signature:</b>

```typescript
management: {
[sectionId: string]: Record<string, boolean>;
};
```
22 changes: 22 additions & 0 deletions docs/development/core/server/kibana-plugin-server.capabilities.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [Capabilities](./kibana-plugin-server.capabilities.md)

## Capabilities interface

The read-only set of capabilities available for the current UI session. Capabilities are simple key-value pairs of (string, boolean), where the string denotes the capability ID, and the boolean is a flag indicating if the capability is enabled or disabled.

<b>Signature:</b>

```typescript
export interface Capabilities
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [catalogue](./kibana-plugin-server.capabilities.catalogue.md) | <code>Record&lt;string, boolean&gt;</code> | Catalogue capabilities. Catalogue entries drive the visibility of the Kibana homepage options. |
| [management](./kibana-plugin-server.capabilities.management.md) | <code>{</code><br/><code> [sectionId: string]: Record&lt;string, boolean&gt;;</code><br/><code> }</code> | Management section capabilities. |
| [navLinks](./kibana-plugin-server.capabilities.navlinks.md) | <code>Record&lt;string, boolean&gt;</code> | Navigation link capabilities. |

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [Capabilities](./kibana-plugin-server.capabilities.md) &gt; [navLinks](./kibana-plugin-server.capabilities.navlinks.md)

## Capabilities.navLinks property

Navigation link capabilities.

<b>Signature:</b>

```typescript
navLinks: Record<string, boolean>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [CapabilitiesProvider](./kibana-plugin-server.capabilitiesprovider.md)

## CapabilitiesProvider type

See [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md)

<b>Signature:</b>

```typescript
export declare type CapabilitiesProvider = () => Partial<Capabilities>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md)

## CapabilitiesSetup interface

APIs to manage the [Capabilities](./kibana-plugin-server.capabilities.md) that will be used by the application.

Plugins relying on capabilities to toggle some of their features should register them during the setup phase using the `registerProvider` method.

Plugins having the responsibility to restrict capabilities depending on a given context should register their capabilities switcher using the `registerSwitcher` method.

Refers to the methods documentation for complete description and examples.

<b>Signature:</b>

```typescript
export interface CapabilitiesSetup
```

## Methods

| Method | Description |
| --- | --- |
| [registerProvider(provider)](./kibana-plugin-server.capabilitiessetup.registerprovider.md) | Register a [CapabilitiesProvider](./kibana-plugin-server.capabilitiesprovider.md) to be used to provide [Capabilities](./kibana-plugin-server.capabilities.md) when resolving them. |
| [registerSwitcher(switcher)](./kibana-plugin-server.capabilitiessetup.registerswitcher.md) | Register a [CapabilitiesSwitcher](./kibana-plugin-server.capabilitiesswitcher.md) to be used to change the default state of the [Capabilities](./kibana-plugin-server.capabilities.md) entries when resolving them.<!-- -->A capabilities switcher can only change the state of existing capabilities. Capabilities added or removed when invoking the switcher will be ignored. |

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md) &gt; [registerProvider](./kibana-plugin-server.capabilitiessetup.registerprovider.md)

## CapabilitiesSetup.registerProvider() method

Register a [CapabilitiesProvider](./kibana-plugin-server.capabilitiesprovider.md) to be used to provide [Capabilities](./kibana-plugin-server.capabilities.md) when resolving them.

<b>Signature:</b>

```typescript
registerProvider(provider: CapabilitiesProvider): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| provider | <code>CapabilitiesProvider</code> | |

<b>Returns:</b>

`void`

## Example

How to register a plugin's capabilities during setup

```ts
// my-plugin/server/plugin.ts
public setup(core: CoreSetup, deps: {}) {
core.capabilities.registerProvider(() => {
return {
catalogue: {
myPlugin: true,
},
myPlugin: {
someFeature: true,
featureDisabledByDefault: false,
},
}
});
}

```

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md) &gt; [registerSwitcher](./kibana-plugin-server.capabilitiessetup.registerswitcher.md)

## CapabilitiesSetup.registerSwitcher() method

Register a [CapabilitiesSwitcher](./kibana-plugin-server.capabilitiesswitcher.md) to be used to change the default state of the [Capabilities](./kibana-plugin-server.capabilities.md) entries when resolving them.

A capabilities switcher can only change the state of existing capabilities. Capabilities added or removed when invoking the switcher will be ignored.

<b>Signature:</b>

```typescript
registerSwitcher(switcher: CapabilitiesSwitcher): void;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| switcher | <code>CapabilitiesSwitcher</code> | |

<b>Returns:</b>

`void`

## Example

How to restrict some capabilities

```ts
// my-plugin/server/plugin.ts
public setup(core: CoreSetup, deps: {}) {
core.capabilities.registerSwitcher((request, capabilities) => {
if(myPluginApi.shouldRestrictSomePluginBecauseOf(request)) {
return {
somePlugin: {
featureEnabledByDefault: false // `featureEnabledByDefault` will be disabled. All other capabilities will remain unchanged.
}
}
}
return {}; // All capabilities will remain unchanged.
});
}

```

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [CapabilitiesStart](./kibana-plugin-server.capabilitiesstart.md)

## CapabilitiesStart interface

APIs to access the application [Capabilities](./kibana-plugin-server.capabilities.md)<!-- -->.

<b>Signature:</b>

```typescript
export interface CapabilitiesStart
```

## Methods

| Method | Description |
| --- | --- |
| [resolveCapabilities(request)](./kibana-plugin-server.capabilitiesstart.resolvecapabilities.md) | Resolve the [Capabilities](./kibana-plugin-server.capabilities.md) to be used for given request |

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [CapabilitiesStart](./kibana-plugin-server.capabilitiesstart.md) &gt; [resolveCapabilities](./kibana-plugin-server.capabilitiesstart.resolvecapabilities.md)

## CapabilitiesStart.resolveCapabilities() method

Resolve the [Capabilities](./kibana-plugin-server.capabilities.md) to be used for given request

<b>Signature:</b>

```typescript
resolveCapabilities(request: KibanaRequest): Promise<Capabilities>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| request | <code>KibanaRequest</code> | |

<b>Returns:</b>

`Promise<Capabilities>`

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [CapabilitiesSwitcher](./kibana-plugin-server.capabilitiesswitcher.md)

## CapabilitiesSwitcher type

See [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md)

<b>Signature:</b>

```typescript
export declare type CapabilitiesSwitcher = (request: KibanaRequest, uiCapabilities: Capabilities) => Partial<Capabilities> | Promise<Partial<Capabilities>>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [CoreSetup](./kibana-plugin-server.coresetup.md) &gt; [capabilities](./kibana-plugin-server.coresetup.capabilities.md)

## CoreSetup.capabilities property

[CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md)

<b>Signature:</b>

```typescript
capabilities: CapabilitiesSetup;
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface CoreSetup

| Property | Type | Description |
| --- | --- | --- |
| [capabilities](./kibana-plugin-server.coresetup.capabilities.md) | <code>CapabilitiesSetup</code> | [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md) |
| [context](./kibana-plugin-server.coresetup.context.md) | <code>ContextSetup</code> | [ContextSetup](./kibana-plugin-server.contextsetup.md) |
| [elasticsearch](./kibana-plugin-server.coresetup.elasticsearch.md) | <code>ElasticsearchServiceSetup</code> | [ElasticsearchServiceSetup](./kibana-plugin-server.elasticsearchservicesetup.md) |
| [http](./kibana-plugin-server.coresetup.http.md) | <code>HttpServiceSetup</code> | [HttpServiceSetup](./kibana-plugin-server.httpservicesetup.md) |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-server](./kibana-plugin-server.md) &gt; [CoreStart](./kibana-plugin-server.corestart.md) &gt; [capabilities](./kibana-plugin-server.corestart.capabilities.md)

## CoreStart.capabilities property

[CapabilitiesStart](./kibana-plugin-server.capabilitiesstart.md)

<b>Signature:</b>

```typescript
capabilities: CapabilitiesStart;
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ export interface CoreStart

| Property | Type | Description |
| --- | --- | --- |
| [capabilities](./kibana-plugin-server.corestart.capabilities.md) | <code>CapabilitiesStart</code> | [CapabilitiesStart](./kibana-plugin-server.capabilitiesstart.md) |
| [savedObjects](./kibana-plugin-server.corestart.savedobjects.md) | <code>SavedObjectsServiceStart</code> | [SavedObjectsServiceStart](./kibana-plugin-server.savedobjectsservicestart.md) |

5 changes: 5 additions & 0 deletions docs/development/core/server/kibana-plugin-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [AuthResultParams](./kibana-plugin-server.authresultparams.md) | Result of an incoming request authentication. |
| [AuthToolkit](./kibana-plugin-server.authtoolkit.md) | A tool set defining an outcome of Auth interceptor for incoming request. |
| [CallAPIOptions](./kibana-plugin-server.callapioptions.md) | The set of options that defines how API call should be made and result be processed. |
| [Capabilities](./kibana-plugin-server.capabilities.md) | The read-only set of capabilities available for the current UI session. Capabilities are simple key-value pairs of (string, boolean), where the string denotes the capability ID, and the boolean is a flag indicating if the capability is enabled or disabled. |
| [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md) | APIs to manage the [Capabilities](./kibana-plugin-server.capabilities.md) that will be used by the application.<!-- -->Plugins relying on capabilities to toggle some of their features should register them during the setup phase using the <code>registerProvider</code> method.<!-- -->Plugins having the responsibility to restrict capabilities depending on a given context should register their capabilities switcher using the <code>registerSwitcher</code> method.<!-- -->Refers to the methods documentation for complete description and examples. |
| [CapabilitiesStart](./kibana-plugin-server.capabilitiesstart.md) | APIs to access the application [Capabilities](./kibana-plugin-server.capabilities.md)<!-- -->. |
| [ContextSetup](./kibana-plugin-server.contextsetup.md) | An object that handles registration of context providers and configuring handlers with context. |
| [CoreSetup](./kibana-plugin-server.coresetup.md) | Context passed to the plugins <code>setup</code> method. |
| [CoreStart](./kibana-plugin-server.corestart.md) | Context passed to the plugins <code>start</code> method. |
Expand Down Expand Up @@ -144,6 +147,8 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
| [AuthenticationHandler](./kibana-plugin-server.authenticationhandler.md) | See [AuthToolkit](./kibana-plugin-server.authtoolkit.md)<!-- -->. |
| [AuthHeaders](./kibana-plugin-server.authheaders.md) | Auth Headers map |
| [AuthResult](./kibana-plugin-server.authresult.md) | |
| [CapabilitiesProvider](./kibana-plugin-server.capabilitiesprovider.md) | See [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md) |
| [CapabilitiesSwitcher](./kibana-plugin-server.capabilitiesswitcher.md) | See [CapabilitiesSetup](./kibana-plugin-server.capabilitiessetup.md) |
| [ConfigPath](./kibana-plugin-server.configpath.md) | |
| [ElasticsearchClientConfig](./kibana-plugin-server.elasticsearchclientconfig.md) | |
| [GetAuthHeaders](./kibana-plugin-server.getauthheaders.md) | Get headers to authenticate a user against Elasticsearch. |
Expand Down
4 changes: 2 additions & 2 deletions src/core/public/application/application_service.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ describe('#start()', () => {
expect(MockCapabilitiesService.start).toHaveBeenCalledWith({
apps: new Map([['app1', { id: 'app1' }]]),
legacyApps: new Map(),
injectedMetadata,
http,
});
});

Expand All @@ -153,7 +153,7 @@ describe('#start()', () => {
expect(MockCapabilitiesService.start).toHaveBeenCalledWith({
apps: new Map(),
legacyApps: new Map([['legacyApp1', { id: 'legacyApp1' }]]),
injectedMetadata,
http,
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/core/public/application/application_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ export class ApplicationService {
const legacyMode = injectedMetadata.getLegacyMode();
const currentAppId$ = new BehaviorSubject<string | undefined>(undefined);
const { availableApps, availableLegacyApps, capabilities } = await this.capabilities.start({
http,
apps: new Map([...this.apps$.value].map(([id, { app }]) => [id, app])),
legacyApps: this.legacyApps$.value,
injectedMetadata,
});

// Only setup history if we're not in legacy mode
Expand Down
Loading