Skip to content

Commit

Permalink
Disable checking for conflicts by default when importing objects
Browse files Browse the repository at this point in the history
Made this change on the client side and the server side.
  • Loading branch information
jportner committed Nov 19, 2020
1 parent 81427b2 commit 5f1d254
Show file tree
Hide file tree
Showing 20 changed files with 165 additions and 75 deletions.
14 changes: 7 additions & 7 deletions docs/api/saved-objects/import.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ experimental[] Create sets of {kib} saved objects from a file created by the exp
==== Query parameters

`createNewCopies`::
(Optional, boolean) Creates copies of saved objects, regenerates each object ID, and resets the origin. When used, potential conflict
errors are avoided.
(Optional, boolean) Creates new copies of saved objects, regenerates each object ID, and resets the origin. When used, potential conflict
errors are avoided. The default value is `true`.
+
NOTE: This cannot be used with the `overwrite` option.

`overwrite`::
(Optional, boolean) Overwrites saved objects when they already exist. When used, potential conflict errors are automatically resolved by
overwriting the destination object.
overwriting the destination object. The default value is `false`.
+
NOTE: This cannot be used with the `createNewCopies` option.

Expand Down Expand Up @@ -80,7 +80,7 @@ Import an index pattern and dashboard:

[source,sh]
--------------------------------------------------
$ curl -X POST api/saved_objects/_import?createNewCopies=true -H "kbn-xsrf: true" --form file=@file.ndjson
$ curl -X POST api/saved_objects/_import -H "kbn-xsrf: true" --form file=@file.ndjson
--------------------------------------------------
// KIBANA

Expand Down Expand Up @@ -132,7 +132,7 @@ Import an index pattern and dashboard:

[source,sh]
--------------------------------------------------
$ curl -X POST api/saved_objects/_import -H "kbn-xsrf: true" --form file=@file.ndjson
$ curl -X POST api/saved_objects/_import?createNewCopies=false -H "kbn-xsrf: true" --form file=@file.ndjson
--------------------------------------------------
// KIBANA

Expand Down Expand Up @@ -181,7 +181,7 @@ Import an index pattern, visualization, *Canvas* workpad, and dashboard that inc

[source,sh]
--------------------------------------------------
$ curl -X POST api/saved_objects/_import -H "kbn-xsrf: true" --form file=@file.ndjson
$ curl -X POST api/saved_objects/_import?createNewCopies=false -H "kbn-xsrf: true" --form file=@file.ndjson
--------------------------------------------------
// KIBANA

Expand Down Expand Up @@ -292,7 +292,7 @@ Import a visualization and dashboard when the index pattern for the visualizatio

[source,sh]
--------------------------------------------------
$ curl -X POST api/saved_objects/_import -H "kbn-xsrf: true" --form file=@file.ndjson
$ curl -X POST api/saved_objects/_import?createNewCopies=false -H "kbn-xsrf: true" --form file=@file.ndjson
--------------------------------------------------
// KIBANA

Expand Down
8 changes: 4 additions & 4 deletions docs/api/saved-objects/resolve_import_errors.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ To resolve errors, you can:
==== Query parameters

`createNewCopies`::
(Optional, boolean) Creates copies of the saved objects, regenerates each object ID, and resets the origin. When enabled during the
initial import, also enable when resolving import errors.
(Optional, boolean) Creates new copies of the saved objects, regenerates each object ID, and resets the origin. When enabled during the
initial import, also enable when resolving import errors. The default value is `true`.

[[saved-objects-api-resolve-import-errors-request-body]]
==== Request body
Expand Down Expand Up @@ -103,7 +103,7 @@ Resolve conflict errors for an index pattern, visualization, and *Canvas* workpa

[source,sh]
--------------------------------------------------
$ curl -X POST api/saved_objects/_resolve_import_errors -H "kbn-xsrf: true" --form file=@file.ndjson --form retries='[{"type":"index-pattern","id":"my-pattern","overwrite":true},{"type":"visualization","id":"my-vis","overwrite":true,"destinationId":"another-vis"},{"type":"canvas","id":"my-canvas","overwrite":true,"destinationId":"yet-another-canvas"},{"type":"dashboard","id":"my-dashboard"}]'
$ curl -X POST api/saved_objects/_resolve_import_errors?createNewCopies=false -H "kbn-xsrf: true" --form file=@file.ndjson --form retries='[{"type":"index-pattern","id":"my-pattern","overwrite":true},{"type":"visualization","id":"my-vis","overwrite":true,"destinationId":"another-vis"},{"type":"canvas","id":"my-canvas","overwrite":true,"destinationId":"yet-another-canvas"},{"type":"dashboard","id":"my-dashboard"}]'
--------------------------------------------------
// KIBANA

Expand Down Expand Up @@ -178,7 +178,7 @@ a search by ignoring it:

[source,sh]
--------------------------------------------------
$ curl -X POST api/saved_objects/_resolve_import_errors -H "kbn-xsrf: true" --form file=@file.ndjson --form retries='[{"type":"visualization","id":"my-vis","replaceReferences":[{"type":"index-pattern","from":"my-pattern-*","to":"existing-pattern"}]},{"type":"search","id":"my-search","ignoreMissingReferences":true},{"type":"dashboard","id":"my-dashboard"}]'
$ curl -X POST api/saved_objects/_resolve_import_errors?createNewCopies=false -H "kbn-xsrf: true" --form file=@file.ndjson --form retries='[{"type":"visualization","id":"my-vis","replaceReferences":[{"type":"index-pattern","from":"my-pattern-*","to":"existing-pattern"}]},{"type":"search","id":"my-search","ignoreMissingReferences":true},{"type":"dashboard","id":"my-dashboard"}]'
--------------------------------------------------
// KIBANA

Expand Down
2 changes: 1 addition & 1 deletion src/core/server/saved_objects/routes/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const registerImportRoute = (router: IRouter, deps: RouteDependencies) =>
query: schema.object(
{
overwrite: schema.boolean({ defaultValue: false }),
createNewCopies: schema.boolean({ defaultValue: false }),
createNewCopies: schema.boolean({ defaultValue: true }),
},
{
validate: (object) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ describe(`POST ${URL}`, () => {
it('formats successful response and records telemetry data', async () => {
const result = await supertest(httpSetup.server.listener)
.post(URL)
.query({ createNewCopies: false })
.set('content-Type', 'multipart/form-data; boundary=BOUNDARY')
.send(
[
Expand All @@ -115,6 +116,7 @@ describe(`POST ${URL}`, () => {

const result = await supertest(httpSetup.server.listener)
.post(URL)
.query({ createNewCopies: false })
.set('content-Type', 'multipart/form-data; boundary=EXAMPLE')
.send(
[
Expand Down Expand Up @@ -155,6 +157,7 @@ describe(`POST ${URL}`, () => {

const result = await supertest(httpSetup.server.listener)
.post(URL)
.query({ createNewCopies: false })
.set('content-Type', 'multipart/form-data; boundary=EXAMPLE')
.send(
[
Expand Down Expand Up @@ -202,6 +205,7 @@ describe(`POST ${URL}`, () => {

const result = await supertest(httpSetup.server.listener)
.post(URL)
.query({ createNewCopies: false })
.set('content-Type', 'multipart/form-data; boundary=EXAMPLE')
.send(
[
Expand Down Expand Up @@ -252,7 +256,8 @@ describe(`POST ${URL}`, () => {
});

const result = await supertest(httpSetup.server.listener)
.post(`${URL}?overwrite=true`)
.post(URL)
.query({ createNewCopies: false, overwrite: true })
.set('content-Type', 'multipart/form-data; boundary=EXAMPLE')
.send(
[
Expand Down Expand Up @@ -300,6 +305,7 @@ describe(`POST ${URL}`, () => {

const result = await supertest(httpSetup.server.listener)
.post(URL)
.query({ createNewCopies: false })
.set('content-Type', 'multipart/form-data; boundary=EXAMPLE')
.send(
[
Expand Down Expand Up @@ -363,6 +369,7 @@ describe(`POST ${URL}`, () => {

const result = await supertest(httpSetup.server.listener)
.post(URL)
.query({ createNewCopies: false })
.set('content-Type', 'multipart/form-data; boundary=EXAMPLE')
.send(
[
Expand Down Expand Up @@ -432,7 +439,8 @@ describe(`POST ${URL}`, () => {
});

const result = await supertest(httpSetup.server.listener)
.post(`${URL}?overwrite=true`)
.post(URL)
.query({ createNewCopies: false, overwrite: true })
.set('content-Type', 'multipart/form-data; boundary=EXAMPLE')
.send(
[
Expand Down Expand Up @@ -502,7 +510,8 @@ describe(`POST ${URL}`, () => {
savedObjectsClient.bulkCreate.mockResolvedValueOnce({ saved_objects: [obj1, obj2] });

const result = await supertest(httpSetup.server.listener)
.post(`${URL}?createNewCopies=true`)
.post(URL)
.query({ createNewCopies: true })
.set('content-Type', 'multipart/form-data; boundary=EXAMPLE')
.send(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ describe(`POST ${URL}`, () => {
it('formats successful response and records telemetry data', async () => {
const result = await supertest(httpSetup.server.listener)
.post(URL)
.query({ createNewCopies: false })
.set('content-Type', 'multipart/form-data; boundary=BOUNDARY')
.send(
[
Expand Down Expand Up @@ -123,6 +124,7 @@ describe(`POST ${URL}`, () => {

const result = await supertest(httpSetup.server.listener)
.post(URL)
.query({ createNewCopies: false })
.set('content-Type', 'multipart/form-data; boundary=EXAMPLE')
.send(
[
Expand Down Expand Up @@ -164,6 +166,7 @@ describe(`POST ${URL}`, () => {

const result = await supertest(httpSetup.server.listener)
.post(URL)
.query({ createNewCopies: false })
.set('content-Type', 'multipart/form-data; boundary=EXAMPLE')
.send(
[
Expand Down Expand Up @@ -201,6 +204,7 @@ describe(`POST ${URL}`, () => {

const result = await supertest(httpSetup.server.listener)
.post(URL)
.query({ createNewCopies: false })
.set('content-Type', 'multipart/form-data; boundary=EXAMPLE')
.send(
[
Expand Down Expand Up @@ -240,6 +244,7 @@ describe(`POST ${URL}`, () => {

const result = await supertest(httpSetup.server.listener)
.post(URL)
.query({ createNewCopies: false })
.set('content-Type', 'multipart/form-data; boundary=EXAMPLE')
.send(
[
Expand Down Expand Up @@ -287,6 +292,7 @@ describe(`POST ${URL}`, () => {

const result = await supertest(httpSetup.server.listener)
.post(URL)
.query({ createNewCopies: false })
.set('content-Type', 'multipart/form-data; boundary=EXAMPLE')
.send(
[
Expand Down Expand Up @@ -344,7 +350,8 @@ describe(`POST ${URL}`, () => {
savedObjectsClient.bulkCreate.mockResolvedValueOnce({ saved_objects: [obj1, obj2] });

const result = await supertest(httpSetup.server.listener)
.post(`${URL}?createNewCopies=true`)
.post(URL)
.query({ createNewCopies: true })
.set('content-Type', 'multipart/form-data; boundary=EXAMPLE')
.send(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const registerResolveImportErrorsRoute = (router: IRouter, deps: RouteDep
},
validate: {
query: schema.object({
createNewCopies: schema.boolean({ defaultValue: false }),
createNewCopies: schema.boolean({ defaultValue: true }),
}),
body: schema.object({
file: schema.stream(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export async function importFile(
) {
const formData = new FormData();
formData.append('file', file);
const query = createNewCopies ? { createNewCopies } : { overwrite };
const query = {
createNewCopies,
...(createNewCopies ? { overwrite: false } : { overwrite }),
};
return await http.post<ImportResponse>('/api/saved_objects/_import', {
body: formData,
headers: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async function callResolveImportErrorsApi(
const formData = new FormData();
formData.append('file', file);
formData.append('retries', JSON.stringify(retries));
const query = createNewCopies ? { createNewCopies } : {};
const query = { createNewCopies };
return http.post<any>('/api/saved_objects/_resolve_import_errors', {
headers: {
// Important to be undefined, it forces proper headers to be set for FormData
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ describe('Flyout', () => {
}));
});

it('should figure out unmatchedReferences', async () => {
it('should display missing references', async () => {
const component = shallowRender(defaultProps);

// Ensure all promises resolve
Expand All @@ -182,7 +182,7 @@ describe('Flyout', () => {
await component.instance().import();

expect(importFileMock).toHaveBeenCalledWith(defaultProps.http, mockFile, {
createNewCopies: false,
createNewCopies: true,
overwrite: true,
});
expect(component.state()).toMatchObject({
Expand All @@ -208,7 +208,7 @@ describe('Flyout', () => {
});
});

it('should allow conflict resolution', async () => {
it('should allow resolution of missing references', async () => {
const component = shallowRender(defaultProps);

// Ensure all promises resolve
Expand Down Expand Up @@ -334,7 +334,7 @@ describe('Flyout', () => {
}));
});

it('should figure out unmatchedReferences', async () => {
it('should display missing references', async () => {
const component = shallowRender(defaultProps);

// Ensure all promises resolve
Expand Down Expand Up @@ -389,7 +389,7 @@ describe('Flyout', () => {
});
});

it('should allow conflict resolution', async () => {
it('should allow resolution of missing references', async () => {
const component = shallowRender(defaultProps);

// Ensure all promises resolve
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import { OverwriteModal } from './overwrite_modal';
import { ImportModeControl, ImportMode } from './import_mode_control';
import { ImportSummary } from './import_summary';

const CREATE_NEW_COPIES_DEFAULT = false;
const CREATE_NEW_COPIES_DEFAULT = true;
const OVERWRITE_ALL_DEFAULT = true;

export interface FlyoutProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const ImportModeControl = ({
options={[overwriteEnabled, overwriteDisabled]}
idSelected={overwrite ? overwriteEnabled.id : overwriteDisabled.id}
onChange={(id: string) => onChange({ overwrite: id === overwriteEnabled.id })}
disabled={createNewCopies}
disabled={createNewCopies && !isLegacyFile}
data-test-subj={'savedObjectsManagement-importModeControl-overwriteRadioGroup'}
/>
);
Expand All @@ -138,6 +138,7 @@ export const ImportModeControl = ({
</EuiTitle>
),
}}
data-test-subj="savedObjectsManagement-importModeControl"
>
<EuiCheckableCard
id={createNewCopiesDisabled.id}
Expand Down
Loading

0 comments on commit 5f1d254

Please sign in to comment.