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 x-pack/legacy/plugins/spaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const spaces = (kibana: Record<string, any>) =>
savedObjectSchemas: {
space: {
isNamespaceAgnostic: true,
hidden: true,
},
},
home: ['plugins/spaces/register_feature'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function createDefaultSpace({ elasticsearch, savedObjects }: Deps)

const client = await elasticsearch.dataClient$.pipe(first()).toPromise();

const savedObjectsRepository = getSavedObjectsRepository(client.callAsInternalUser);
const savedObjectsRepository = getSavedObjectsRepository(client.callAsInternalUser, ['space']);

const defaultSpaceExists = await doesDefaultSpaceExist(
SavedObjectsClient,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,6 @@ const createSpacesService = async (spaceId: string) => {
).rejects.toThrowErrorMatchingSnapshot();
});

test(`throws error if type is space`, async () => {
const request = createMockRequest();
const baseClient = createMockClient();
const spacesService = await createSpacesService(currentSpace.id);

const client = new SpacesSavedObjectsClient({
request,
baseClient,
spacesService,
types,
});

await expect(client.get('space', '')).rejects.toThrowErrorMatchingSnapshot();
});

test(`supplements options with undefined namespace`, async () => {
const request = createMockRequest();
const baseClient = createMockClient();
Expand Down Expand Up @@ -114,23 +99,6 @@ const createSpacesService = async (spaceId: string) => {
).rejects.toThrowErrorMatchingSnapshot();
});

test(`throws error if objects type is space`, async () => {
const request = createMockRequest();
const baseClient = createMockClient();
const spacesService = await createSpacesService(currentSpace.id);

const client = new SpacesSavedObjectsClient({
request,
baseClient,
spacesService,
types,
});

await expect(
client.bulkGet([{ id: '', type: 'foo' }, { id: '', type: 'space' }], { namespace: 'bar' })
).rejects.toThrowErrorMatchingSnapshot();
});

test(`supplements options with undefined namespace`, async () => {
const request = createMockRequest();
const baseClient = createMockClient();
Expand Down Expand Up @@ -174,23 +142,6 @@ const createSpacesService = async (spaceId: string) => {
await expect(client.find({ namespace: 'bar' })).rejects.toThrowErrorMatchingSnapshot();
});

test(`throws error if options.type is space`, async () => {
const request = createMockRequest();
const baseClient = createMockClient();
const expectedReturnValue = Symbol();
baseClient.find.mockReturnValue(expectedReturnValue);
const spacesService = await createSpacesService(currentSpace.id);

const client = new SpacesSavedObjectsClient({
request,
baseClient,
spacesService,
types,
});

await expect(client.find({ type: 'space' })).rejects.toThrowErrorMatchingSnapshot();
});

test(`passes options.type to baseClient if valid singular type specified`, async () => {
const request = createMockRequest();
const baseClient = createMockClient();
Expand All @@ -215,44 +166,6 @@ const createSpacesService = async (spaceId: string) => {
});
});

test(`throws error if options.type is array containing space`, async () => {
const request = createMockRequest();
const baseClient = createMockClient();
const expectedReturnValue = Symbol();
baseClient.find.mockReturnValue(expectedReturnValue);
const spacesService = await createSpacesService(currentSpace.id);

const client = new SpacesSavedObjectsClient({
request,
baseClient,
spacesService,
types,
});

await expect(
client.find({ type: ['space', 'foo'] })
).rejects.toThrowErrorMatchingSnapshot();
});

test(`if options.type isn't provided specifies options.type based on the types excluding the space`, async () => {
const request = createMockRequest();
const baseClient = createMockClient();
const expectedReturnValue = Symbol();
baseClient.find.mockReturnValue(expectedReturnValue);
const spacesService = await createSpacesService(currentSpace.id);

const client = new SpacesSavedObjectsClient({
request,
baseClient,
spacesService,
types,
});

await expect(
client.find({ type: ['space', 'foo'] })
).rejects.toThrowErrorMatchingSnapshot();
});

test(`supplements options with undefined namespace`, async () => {
const request = createMockRequest();
const baseClient = createMockClient();
Expand Down Expand Up @@ -296,21 +209,6 @@ const createSpacesService = async (spaceId: string) => {
).rejects.toThrowErrorMatchingSnapshot();
});

test(`throws error if type is space`, async () => {
const request = createMockRequest();
const baseClient = createMockClient();
const spacesService = await createSpacesService(currentSpace.id);

const client = new SpacesSavedObjectsClient({
request,
baseClient,
spacesService,
types,
});

await expect(client.create('space', {})).rejects.toThrowErrorMatchingSnapshot();
});

test(`supplements options with undefined namespace`, async () => {
const request = createMockRequest();
const baseClient = createMockClient();
Expand Down Expand Up @@ -357,26 +255,6 @@ const createSpacesService = async (spaceId: string) => {
).rejects.toThrowErrorMatchingSnapshot();
});

test(`throws error if objects type is space`, async () => {
const request = createMockRequest();
const baseClient = createMockClient();
const spacesService = await createSpacesService(currentSpace.id);

const client = new SpacesSavedObjectsClient({
request,
baseClient,
spacesService,
types,
});

await expect(
client.bulkCreate([
{ id: '', type: 'foo', attributes: {} },
{ id: '', type: 'space', attributes: {} },
])
).rejects.toThrowErrorMatchingSnapshot();
});

test(`supplements options with undefined namespace`, async () => {
const request = createMockRequest();
const baseClient = createMockClient();
Expand Down Expand Up @@ -423,21 +301,6 @@ const createSpacesService = async (spaceId: string) => {
).rejects.toThrowErrorMatchingSnapshot();
});

test(`throws error if type is space`, async () => {
const request = createMockRequest();
const baseClient = createMockClient();
const spacesService = await createSpacesService(currentSpace.id);

const client = new SpacesSavedObjectsClient({
request,
baseClient,
spacesService,
types,
});

await expect(client.update('space', '', {})).rejects.toThrowErrorMatchingSnapshot();
});

test(`supplements options with undefined namespace`, async () => {
const request = createMockRequest();
const baseClient = createMockClient();
Expand Down Expand Up @@ -486,21 +349,6 @@ const createSpacesService = async (spaceId: string) => {
).rejects.toThrowErrorMatchingSnapshot();
});

test(`throws error if type is space`, async () => {
const request = createMockRequest();
const baseClient = createMockClient();
const spacesService = await createSpacesService(currentSpace.id);

const client = new SpacesSavedObjectsClient({
request,
baseClient,
spacesService,
types,
});

await expect(client.delete('space', 'foo')).rejects.toThrowErrorMatchingSnapshot();
});

test(`supplements options with undefined namespace`, async () => {
const request = createMockRequest();
const baseClient = createMockClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,6 @@ const throwErrorIfNamespaceSpecified = (options: any) => {
}
};

const throwErrorIfTypeIsSpace = (type: string) => {
if (type === 'space') {
throw new Error('Spaces can not be accessed using the SavedObjectsClient');
}
};

const throwErrorIfTypesContainsSpace = (types: string[]) => {
for (const type of types) {
throwErrorIfTypeIsSpace(type);
}
};

export class SpacesSavedObjectsClient implements SavedObjectsClientContract {
private readonly client: SavedObjectsClientContract;
private readonly spaceId: string;
Expand Down Expand Up @@ -81,7 +69,6 @@ export class SpacesSavedObjectsClient implements SavedObjectsClientContract {
attributes: T = {} as T,
options: SavedObjectsCreateOptions = {}
) {
throwErrorIfTypeIsSpace(type);
throwErrorIfNamespaceSpecified(options);

return await this.client.create(type, attributes, {
Expand All @@ -103,7 +90,6 @@ export class SpacesSavedObjectsClient implements SavedObjectsClientContract {
objects: SavedObjectsBulkCreateObject[],
options: SavedObjectsBaseOptions = {}
) {
throwErrorIfTypesContainsSpace(objects.map(object => object.type));
throwErrorIfNamespaceSpecified(options);

return await this.client.bulkCreate(objects, {
Expand All @@ -122,7 +108,6 @@ export class SpacesSavedObjectsClient implements SavedObjectsClientContract {
* @returns {promise}
*/
public async delete(type: string, id: string, options: SavedObjectsBaseOptions = {}) {
throwErrorIfTypeIsSpace(type);
throwErrorIfNamespaceSpecified(options);

return await this.client.delete(type, id, {
Expand All @@ -148,10 +133,6 @@ export class SpacesSavedObjectsClient implements SavedObjectsClientContract {
* @returns {promise} - { saved_objects: [{ id, type, version, attributes }], total, per_page, page }
*/
public async find(options: SavedObjectsFindOptions = {}) {
if (options.type) {
throwErrorIfTypesContainsSpace(coerceToArray(options.type));
}

throwErrorIfNamespaceSpecified(options);

return await this.client.find({
Expand Down Expand Up @@ -181,7 +162,6 @@ export class SpacesSavedObjectsClient implements SavedObjectsClientContract {
objects: SavedObjectsBulkGetObject[] = [],
options: SavedObjectsBaseOptions = {}
) {
throwErrorIfTypesContainsSpace(objects.map(object => object.type));
throwErrorIfNamespaceSpecified(options);

return await this.client.bulkGet(objects, {
Expand All @@ -200,7 +180,6 @@ export class SpacesSavedObjectsClient implements SavedObjectsClientContract {
* @returns {promise} - { id, type, version, attributes }
*/
public async get(type: string, id: string, options: SavedObjectsBaseOptions = {}) {
throwErrorIfTypeIsSpace(type);
throwErrorIfNamespaceSpecified(options);

return await this.client.get(type, id, {
Expand All @@ -225,7 +204,6 @@ export class SpacesSavedObjectsClient implements SavedObjectsClientContract {
attributes: Partial<T>,
options: SavedObjectsUpdateOptions = {}
) {
throwErrorIfTypeIsSpace(type);
throwErrorIfNamespaceSpecified(options);

return await this.client.update(type, id, attributes, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,16 @@ export class SpacesService {
.pipe(
map(([clusterClient, config]) => {
const internalRepository = savedObjects.getSavedObjectsRepository(
clusterClient.callAsInternalUser
clusterClient.callAsInternalUser,
['space']
);

const callCluster = clusterClient.asScoped(request).callAsCurrentUser;

const callWithRequestRepository = savedObjects.getSavedObjectsRepository(callCluster);
const callWithRequestRepository = savedObjects.getSavedObjectsRepository(
callCluster,
['space']
);

const authorization = security.isEnabled ? security.authorization : null;

Expand Down
1 change: 1 addition & 0 deletions x-pack/test/api_integration/apis/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default function ({ loadTestFile }) {
loadTestFile(require.resolve('./alerting'));
loadTestFile(require.resolve('./es'));
loadTestFile(require.resolve('./security'));
loadTestFile(require.resolve('./spaces'));
loadTestFile(require.resolve('./monitoring'));
loadTestFile(require.resolve('./xpack_main'));
loadTestFile(require.resolve('./telemetry'));
Expand Down
Loading