-
Notifications
You must be signed in to change notification settings - Fork 800
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] Fix: keep disallowed types when importing with overwrite #6668
Merged
SuZhou-Joe
merged 4 commits into
opensearch-project:main
from
SuZhou-Joe:fix/import-with-overwrite
Apr 29, 2024
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
20daeed
fix: keep disallowed types when importing with overwrite
SuZhou-Joe fb89f0e
Changeset file for PR #6668 created/updated
opensearch-changeset-bot[bot] 7f2fe36
feat: update comment
SuZhou-Joe 1df34d1
feat: address some minor concern
SuZhou-Joe File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
fix: | ||
- Keep disallowed types when importing with overwrite ([#6668](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6668)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -289,11 +289,33 @@ export class WorkspaceConflictSavedObjectsClientWrapper { | |
return { errors: [] }; | ||
} | ||
|
||
const { workspaces } = options; | ||
|
||
const disallowedSavedObjects: SavedObjectsCheckConflictsObject[] = []; | ||
const allowedSavedObjects: SavedObjectsCheckConflictsObject[] = []; | ||
objects.forEach((item) => { | ||
const isImportIntoWorkspace = !!workspaces?.length; | ||
// config can not be created inside a workspace | ||
if (this.isConfigType(item.type) && isImportIntoWorkspace) { | ||
disallowedSavedObjects.push(item); | ||
return; | ||
} | ||
|
||
// For 2.14, data source can only be created without workspace info | ||
if (this.isDataSourceType(item.type) && isImportIntoWorkspace) { | ||
disallowedSavedObjects.push(item); | ||
return; | ||
} | ||
|
||
allowedSavedObjects.push(item); | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: return is not needed here |
||
}); | ||
|
||
/** | ||
* Workspace conflict only happens when target workspaces params present. | ||
*/ | ||
if (options.workspaces) { | ||
const bulkGetDocs: any[] = objects.map((object) => { | ||
const bulkGetDocs: any[] = allowedSavedObjects.map((object) => { | ||
const { type, id } = object; | ||
|
||
return { | ||
|
@@ -335,7 +357,7 @@ export class WorkspaceConflictSavedObjectsClientWrapper { | |
} | ||
} | ||
|
||
const objectsNoWorkspaceConflictError = objects.filter( | ||
const objectsNoWorkspaceConflictError = allowedSavedObjects.filter( | ||
(item) => | ||
!objectsConflictWithWorkspace.find( | ||
(errorItems) => | ||
|
@@ -355,7 +377,7 @@ export class WorkspaceConflictSavedObjectsClientWrapper { | |
/** | ||
* Bypass those objects that are not conflict on workspaces | ||
*/ | ||
const realBulkCreateResult = await wrapperOptions.client.checkConflicts( | ||
const realCheckConflictsResult = await wrapperOptions.client.checkConflicts( | ||
objectsNoWorkspaceConflictError, | ||
options | ||
); | ||
|
@@ -364,8 +386,21 @@ export class WorkspaceConflictSavedObjectsClientWrapper { | |
* Merge results from two conflict check. | ||
*/ | ||
const result: SavedObjectsCheckConflictsResponse = { | ||
...realBulkCreateResult, | ||
errors: [...objectsConflictWithWorkspace, ...realBulkCreateResult.errors], | ||
...realCheckConflictsResult, | ||
errors: [ | ||
...objectsConflictWithWorkspace, | ||
...disallowedSavedObjects.map((item) => ({ | ||
...item, | ||
error: { | ||
...SavedObjectsErrorHelpers.decorateBadRequestError( | ||
new Error(`'${item.type}' is not allowed to be imported in workspace.`), | ||
'Unsupported type in workspace' | ||
).output.payload, | ||
metadata: { isNotOverwritable: true }, | ||
}, | ||
})), | ||
...(realCheckConflictsResult?.errors || []), | ||
], | ||
}; | ||
|
||
return result; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this line could move out the forEach loop