Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions x-pack/platform/plugins/shared/spaces/server/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,12 @@ describe('config schema', () => {
)
).toThrow();
});

it('should not throw error if defaultSolution uses valid value', () => {
expect(() => ConfigSchema.validate({ defaultSolution: 'es' })).not.toThrow();
});

it('should throw error if defaultSolution uses invalid value', () => {
expect(() => ConfigSchema.validate({ defaultSolution: 'test' })).toThrow();
});
});
8 changes: 8 additions & 0 deletions x-pack/platform/plugins/shared/spaces/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import type { Observable } from 'rxjs';
import type { TypeOf } from '@kbn/config-schema';
import { offeringBasedSchema, schema } from '@kbn/config-schema';
import type { PluginInitializerContext } from '@kbn/core/server';
import type { SolutionId } from '@kbn/core-chrome-browser';

const solutions = ['es', 'oblt', 'security'] as const;

const solutionSchemaLiterals = [...solutions].map((s) => schema.literal(s)) as [
ReturnType<typeof schema.literal<Exclude<SolutionId, 'chat'>>>
];

export const ConfigSchema = schema.object({
enabled: schema.conditional(
Expand Down Expand Up @@ -54,6 +61,7 @@ export const ConfigSchema = schema.object({
defaultValue: true,
}),
}),
defaultSolution: schema.maybe(schema.oneOf(solutionSchemaLiterals)),
});

export function createConfig$(context: PluginInitializerContext) {
Expand Down
19 changes: 18 additions & 1 deletion x-pack/platform/plugins/shared/spaces/server/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ describe('Spaces plugin', () => {
expect(usageCollection.getCollectorByType('spaces')).toBeDefined();
});

it('can setup space with default solution', async () => {
it('can setup space with default solution for cloud', async () => {
const initializerContext = coreMock.createPluginInitializerContext({ maxSpaces: 1000 });
const core = coreMock.createSetup() as CoreSetup<PluginsStart>;
const features = featuresPluginMock.createSetup();
Expand All @@ -100,6 +100,23 @@ describe('Spaces plugin', () => {
expect.objectContaining({ solution: 'security' })
);
});

it('can setup space with default solution for onprem', async () => {
const initializerContext = coreMock.createPluginInitializerContext({
maxSpaces: 1000,
defaultSolution: 'oblt',
});
const core = coreMock.createSetup() as CoreSetup<PluginsStart>;
const features = featuresPluginMock.createSetup();
const licensing = licensingMock.createSetup();

const plugin = new SpacesPlugin(initializerContext);
plugin.setup(core, { features, licensing });

expect(createDefaultSpace).toHaveBeenCalledWith(
expect.objectContaining({ solution: 'oblt' })
);
});
});

describe('#start', () => {
Expand Down
10 changes: 8 additions & 2 deletions x-pack/platform/plugins/shared/spaces/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { Observable } from 'rxjs';
import { map } from 'rxjs';
import { map, take } from 'rxjs';

import type { CloudSetup } from '@kbn/cloud-plugin/server';
import type {
Expand Down Expand Up @@ -155,14 +155,20 @@ export class SpacesPlugin

const { license } = this.spacesLicenseService.setup({ license$: plugins.licensing.license$ });

let defaultSolution;

this.config$.pipe(take(1)).subscribe((config) => {
defaultSolution = config.defaultSolution;
});

this.defaultSpaceService = new DefaultSpaceService();
this.defaultSpaceService.setup({
coreStatus: core.status,
getSavedObjects: async () => (await core.getStartServices())[0].savedObjects,
license$: plugins.licensing.license$,
spacesLicense: license,
logger: this.log,
solution: plugins.cloud?.onboarding?.defaultSolution,
solution: plugins.cloud?.onboarding?.defaultSolution || defaultSolution,
});

initSpacesViewsRoutes({
Expand Down