-
Notifications
You must be signed in to change notification settings - Fork 916
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] Delete saved objects by workspace #6013
Changes from 6 commits
afb3701
15b93b3
c82eae2
f1fcfd4
606a933
c833954
bf8023f
99ea718
a2d1e52
2f3418c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,6 +68,7 @@ import { | |
SavedObjectsAddToNamespacesResponse, | ||
SavedObjectsDeleteFromNamespacesOptions, | ||
SavedObjectsDeleteFromNamespacesResponse, | ||
SavedObjectsDeleteByWorkspaceOptions, | ||
} from '../saved_objects_client'; | ||
import { | ||
SavedObject, | ||
|
@@ -714,6 +715,55 @@ export class SavedObjectsRepository { | |
return body; | ||
} | ||
|
||
/** | ||
* Deletes all objects from the provided workspace. It used when deleting a workspace. | ||
Hailong-am marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* @param {string} workspace | ||
* @param options SavedObjectsDeleteByWorkspaceOptions | ||
* @returns {promise} - { took, timed_out, total, deleted, batches, version_conflicts, noops, retries, failures } | ||
*/ | ||
async deleteByWorkspace( | ||
workspace: string, | ||
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. Is it taking the workspace name or id as the param ? 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. if it's actually taking the id maybe let's try to name like 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. make sense. As we are using workspace everywhere to reference as its id, to make the name consistent, let me add this to parameter comment. |
||
options: SavedObjectsDeleteByWorkspaceOptions = {} | ||
): Promise<any> { | ||
if (!workspace || typeof workspace !== 'string' || workspace === '*') { | ||
throw new TypeError(`workspace is required, and must be a string that is not equal to '*'`); | ||
} | ||
|
||
const allTypes = Object.keys(getRootPropertiesObjects(this._mappings)); | ||
|
||
const { body } = await this.client.updateByQuery( | ||
{ | ||
index: this.getIndicesForTypes(allTypes), | ||
refresh: options.refresh, | ||
body: { | ||
script: { | ||
source: ` | ||
if (!ctx._source.containsKey('workspaces')) { | ||
ctx.op = "delete"; | ||
} else { | ||
ctx._source['workspaces'].removeAll(Collections.singleton(params['workspace'])); | ||
if (ctx._source['workspaces'].empty) { | ||
ctx.op = "delete"; | ||
} | ||
} | ||
`, | ||
lang: 'painless', | ||
params: { workspace }, | ||
}, | ||
conflicts: 'proceed', | ||
...getSearchDsl(this._mappings, this._registry, { | ||
workspaces: [workspace], | ||
type: allTypes, | ||
}), | ||
}, | ||
}, | ||
{ ignore: [404] } | ||
); | ||
|
||
return body; | ||
} | ||
|
||
/** | ||
* @param {object} [options={}] | ||
* @property {(string|Array<string>)} [options.type] | ||
|
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: useless empty line