Opensearch dashboards.capabilitiessetup.registerswitcher
Home > opensearch-dashboards > CapabilitiesSetup > registerSwitcher
CapabilitiesSetup.registerSwitcher() method
Register a CapabilitiesSwitcher to be used to change the default state of the Capabilities 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.
Signature:
registerSwitcher(switcher: CapabilitiesSwitcher): void;
Parameters
Parameter | Type | Description |
---|---|---|
switcher | CapabilitiesSwitcher |
Returns:
void
Example
How to restrict some capabilities
// 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.
});
}