Skip to content

Commit

Permalink
[Workspace]Following pr for #5949 (#6012)
Browse files Browse the repository at this point in the history
* feat: temp save

Signed-off-by: SuZhou-Joe <[email protected]>

* fix: unit test

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: add some comment

Signed-off-by: SuZhou-Joe <[email protected]>

---------

Signed-off-by: SuZhou-Joe <[email protected]>
Co-authored-by: Ashwin P Chandran <[email protected]>
  • Loading branch information
SuZhou-Joe and ashwin-pc authored Mar 4, 2024
1 parent 4943f06 commit 9901bea
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

import crypto from 'crypto';
import { cloneDeep, mapValues } from 'lodash';
import { Config } from 'packages/osd-config/target';
import { Config } from '@osd/config';
import {
IndexMapping,
SavedObjectsMappingProperties,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*/

import { Logger } from 'src/core/server/logging';
import { Config } from 'packages/osd-config/target';
import { Config } from '@osd/config';
import { MigrationOpenSearchClient } from './migration_opensearch_client';
import { SavedObjectsSerializer } from '../../serialization';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@

import { OpenSearchDashboardsConfigType } from 'src/core/server/opensearch_dashboards_config';
import { BehaviorSubject } from 'rxjs';

import { Config } from 'packages/osd-config/target';
import { Config } from '@osd/config';
import { Logger } from '../../../logging';
import { IndexMapping, SavedObjectsTypeMappingDefinitions } from '../../mappings';
import { SavedObjectUnsanitizedDoc, SavedObjectsSerializer } from '../../serialization';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,11 @@ describe('WorkspaceConflictSavedObjectsClientWrapper', () => {
});

it(`Should use options.workspaces when get throws error`, async () => {
mockedClient.get.mockRejectedValueOnce(
getSavedObject({
id: 'dashboard:foo',
workspaces: ['foo'],
error: {
statusCode: 404,
error: 'Not found',
message: 'Not found',
},
})
);
mockedClient.get.mockRejectedValueOnce({
output: {
statusCode: 404,
},
});

await wrapperClient.create(
'dashboard',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ export class WorkspaceConflictSavedObjectsClientWrapper {
`${props.type}:${props.id}`
);
}

/**
* Workspace is a concept to manage saved objects and the `workspaces` field of each object indicates workspaces the object belongs to.
* When user tries to update an existing object's attribute, workspaces field should be preserved. Below are some cases that this conflict wrapper will take effect:
* 1. Overwrite a object belonging to workspace A with parameter workspace B, in this case we should deny the request as it conflicts with workspaces check.
* 2. Overwrite a object belonging to workspace [A, B] with parameters workspace B, we need to preserved the workspaces fields to [A, B].
*/
public wrapperFactory: SavedObjectsClientWrapperFactory = (wrapperOptions) => {
const createWithWorkspaceConflictCheck = async <T = unknown>(
type: string,
Expand Down Expand Up @@ -90,10 +97,11 @@ export class WorkspaceConflictSavedObjectsClientWrapper {
? objects
.filter((object) => !!object.id)
.map((object) => {
const { type, id } = object;
/**
* It requires a check when overwriting objects to target workspaces
* If the object waiting to import has id and type,
* Add it to the buldGetDocs to fetch the latest metadata.
*/
const { type, id } = object;
return {
type,
id: id as string,
Expand Down

0 comments on commit 9901bea

Please sign in to comment.