Skip to content

Commit

Permalink
[Workspace]Following pr for opensearch-project#5949 (opensearch-proje…
Browse files Browse the repository at this point in the history
…ct#6012) (#276)

* feat: temp save



* fix: unit test



* feat: add some comment



---------

Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
Co-authored-by: Ashwin P Chandran <ashwinpc@amazon.com>
  • Loading branch information
SuZhou-Joe and ashwin-pc authored Mar 5, 2024
1 parent 3a4bcd5 commit b14060a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 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,
SavedObjectsFieldMapping,
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 @@ -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 b14060a

Please sign in to comment.