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

[Workspace] Isolate objects based on workspace when calling get/bulkGet #8888

Merged
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 2 additions & 0 deletions changelogs/fragments/8888.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
refactor:
- [Workspace] Isolate objects based on workspace when calling get/bulkGet ([#8888](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8888))
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ describe('workspace_id_consumer integration test', () => {
let createdBarWorkspace: WorkspaceAttributes = {
id: '',
};
const deleteWorkspace = (workspaceId: string) =>
osdTestServer.request.delete(root, `/api/workspaces/${workspaceId}`);
beforeAll(async () => {
const { startOpenSearch, startOpenSearchDashboards } = osdTestServer.createTestServers({
adjustTimeout: (t: number) => jest.setTimeout(t),
Expand Down Expand Up @@ -75,6 +77,10 @@ describe('workspace_id_consumer integration test', () => {
}).then((resp) => resp.body.result);
}, 30000);
afterAll(async () => {
await Promise.all([
deleteWorkspace(createdFooWorkspace.id),
deleteWorkspace(createdBarWorkspace.id),
]);
await root.shutdown();
await opensearchServer.stop();
});
Expand Down Expand Up @@ -312,5 +318,153 @@ describe('workspace_id_consumer integration test', () => {
expect(importWithWorkspacesResult.body.success).toEqual(true);
expect(findResult.body.saved_objects[0].workspaces).toEqual([createdFooWorkspace.id]);
});

it('get', async () => {
await clearFooAndBar();
await osdTestServer.request.delete(
root,
`/api/saved_objects/${config.type}/${packageInfo.version}`
);
const createResultFoo = await osdTestServer.request
.post(root, `/w/${createdFooWorkspace.id}/api/saved_objects/_bulk_create`)
.send([
{
...dashboard,
id: 'foo',
},
])
.expect(200);

const createResultBar = await osdTestServer.request
.post(root, `/w/${createdBarWorkspace.id}/api/saved_objects/_bulk_create`)
.send([
{
...dashboard,
id: 'bar',
},
])
.expect(200);

await osdTestServer.request
.post(root, `/api/saved_objects/${config.type}/${packageInfo.version}`)
.send({
attributes: {
legacyConfig: 'foo',
},
})
.expect(200);

const getResultWithRequestWorkspace = await osdTestServer.request
.get(root, `/w/${createdFooWorkspace.id}/api/saved_objects/${dashboard.type}/foo`)
.expect(200);
expect(getResultWithRequestWorkspace.body.id).toEqual('foo');
expect(getResultWithRequestWorkspace.body.workspaces).toEqual([createdFooWorkspace.id]);

const getResultWithoutRequestWorkspace = await osdTestServer.request
.get(root, `/api/saved_objects/${dashboard.type}/bar`)
.expect(200);
expect(getResultWithoutRequestWorkspace.body.id).toEqual('bar');

const getGlobalResultWithinWorkspace = await osdTestServer.request
.get(
root,
`/w/${createdFooWorkspace.id}/api/saved_objects/${config.type}/${packageInfo.version}`
)
.expect(200);
expect(getGlobalResultWithinWorkspace.body.id).toEqual(packageInfo.version);

await osdTestServer.request
yubonluo marked this conversation as resolved.
Show resolved Hide resolved
.get(root, `/w/${createdFooWorkspace.id}/api/saved_objects/${dashboard.type}/bar`)
.expect(404);

await Promise.all(
[...createResultFoo.body.saved_objects, ...createResultBar.body.saved_objects].map((item) =>
deleteItem({
type: item.type,
id: item.id,
})
)
);
await osdTestServer.request.delete(
root,
`/api/saved_objects/${config.type}/${packageInfo.version}`
);
});

it('bulk get', async () => {
await clearFooAndBar();
const createResultFoo = await osdTestServer.request
.post(root, `/w/${createdFooWorkspace.id}/api/saved_objects/_bulk_create`)
.send([
{
...dashboard,
id: 'foo',
},
])
.expect(200);

const createResultBar = await osdTestServer.request
.post(root, `/w/${createdBarWorkspace.id}/api/saved_objects/_bulk_create`)
.send([
{
...dashboard,
id: 'bar',
},
])
.expect(200);

const payload = [
{ id: 'foo', type: 'dashboard' },
{ id: 'bar', type: 'dashboard' },
];
const bulkGetResultWithWorkspace = await osdTestServer.request
.post(root, `/w/${createdFooWorkspace.id}/api/saved_objects/_bulk_get`)
.send(payload)
.expect(200);

expect(bulkGetResultWithWorkspace.body.saved_objects.length).toEqual(2);
expect(bulkGetResultWithWorkspace.body.saved_objects[0].id).toEqual('foo');
expect(bulkGetResultWithWorkspace.body.saved_objects[0].workspaces).toEqual([
createdFooWorkspace.id,
]);
expect(bulkGetResultWithWorkspace.body.saved_objects[0]?.error).toBeUndefined();
expect(bulkGetResultWithWorkspace.body.saved_objects[1].id).toEqual('bar');
expect(bulkGetResultWithWorkspace.body.saved_objects[1].workspaces).toEqual([
createdBarWorkspace.id,
]);
expect(bulkGetResultWithWorkspace.body.saved_objects[1]?.error).toMatchInlineSnapshot(`
Object {
"error": "Not Found",
"message": "Saved object [dashboard/bar] not found",
"statusCode": 404,
}
`);

const bulkGetResultWithoutWorkspace = await osdTestServer.request
.post(root, `/api/saved_objects/_bulk_get`)
.send(payload)
.expect(200);

expect(bulkGetResultWithoutWorkspace.body.saved_objects.length).toEqual(2);
expect(bulkGetResultWithoutWorkspace.body.saved_objects[0].id).toEqual('foo');
expect(bulkGetResultWithoutWorkspace.body.saved_objects[0].workspaces).toEqual([
createdFooWorkspace.id,
]);
expect(bulkGetResultWithoutWorkspace.body.saved_objects[0]?.error).toBeUndefined();
expect(bulkGetResultWithoutWorkspace.body.saved_objects[1].id).toEqual('bar');
expect(bulkGetResultWithoutWorkspace.body.saved_objects[1].workspaces).toEqual([
createdBarWorkspace.id,
]);
expect(bulkGetResultWithoutWorkspace.body.saved_objects[1]?.error).toBeUndefined();

await Promise.all(
[...createResultFoo.body.saved_objects, ...createResultBar.body.saved_objects].map((item) =>
deleteItem({
type: item.type,
id: item.id,
})
)
);
});
});
});
Loading
Loading