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]Following pr for #5949 (#6012) #276

Merged
merged 1 commit into from
Mar 5, 2024
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
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
Loading