Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 src/plugins/data_views/common/data_views/data_views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,7 @@ export class DataViewsService {
body,
{
id: dataView.id,
initialNamespaces: dataView.namespaces.length > 0 ? dataView.namespaces : undefined,
}
)) as SavedObject<DataViewAttributes>;

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data_views/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export interface SavedObjectsClientCommon {
create: (
type: string,
attributes: DataViewAttributes,
options: SavedObjectsCreateOptions
options: SavedObjectsCreateOptions & { initialNamespaces?: string[] }
) => Promise<SavedObject>;
/**
* Delete a saved object by id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const dataViewSpecSchema = schema.object({
allowNoIndex: schema.maybe(schema.boolean()),
runtimeFieldMap: schema.maybe(schema.recordOf(schema.string(), runtimeFieldSchema)),
name: schema.maybe(schema.string()),
namespaces: schema.maybe(schema.arrayOf(schema.string())),
});

const registerCreateDataViewRouteFactory =
Expand Down Expand Up @@ -124,7 +125,10 @@ const registerCreateDataViewRouteFactory =
'content-type': 'application/json',
},
body: {
[serviceKey]: dataView.toSpec(),
[serviceKey]: {
...dataView.toSpec(),
namespaces: dataView.namespaces,
},
},
});
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../../ftr_provider_context';
import { configArray } from '../../constants';
import { configArray, dataViewConfig } from '../../constants';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
Expand Down Expand Up @@ -290,5 +290,59 @@ export default function ({ getService }: FtrProviderContext) {
});
});
});

describe('spaces', () => {
const kibanaServer = getService('kibanaServer');
const fooNamespace = 'foo-namespace';

before(async () => {
await kibanaServer.spaces.create({
id: fooNamespace,
name: fooNamespace,
});
});

after(async () => {
await kibanaServer.spaces.delete(fooNamespace);
});

it('can specify optional namespaces array when creating a data view', async () => {
const title = `foo-${Date.now()}-${Math.random()}*`;
const namespaces = ['default', fooNamespace];
const createResponse = await supertest.post(dataViewConfig.path).send({
[dataViewConfig.serviceKey]: {
title,
namespaces,
},
});

expect(createResponse.status).to.be(200);
expect(createResponse.body[dataViewConfig.serviceKey].namespaces).to.eql(namespaces);

const getResponse = await supertest.get(dataViewConfig.basePath);
const dataView = getResponse.body.data_view.find((dv: any) => dv.title === title);

expect(dataView.namespaces).to.eql(namespaces);
});

it('sets namespaces to the current space if namespaces array is not specified', async () => {
const title = `foo-${Date.now()}-${Math.random()}*`;
const createResponse = await supertest
.post(`/s/${fooNamespace}${dataViewConfig.path}`)
.send({
[dataViewConfig.serviceKey]: {
title,
},
});

expect(createResponse.status).to.be(200);
expect(createResponse.body[dataViewConfig.serviceKey].namespaces).to.eql([fooNamespace]);

const getResponse = await supertest.get(`/s/${fooNamespace}${dataViewConfig.basePath}`);
const dataView = getResponse.body.data_view.find((dv: any) => dv.title === title);

expect(dataView.namespaces).to.eql([fooNamespace]);
});
});
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default function ({ getService }: FtrProviderContext) {
expect(response6.status).to.be(200);
const recreatedIndexPattern = response6.body.index_pattern;

expect(_.omit(recreatedIndexPattern, 'version')).to.eql(
expect(_.omit(recreatedIndexPattern, 'version', 'namespaces')).to.eql(
_.omit(resultIndexPattern, 'version')
);
});
Expand Down