From 1e718a557211e1eda5fd1282c171c43daebff3fe Mon Sep 17 00:00:00 2001 From: Matthew Kime Date: Mon, 25 Oct 2021 11:10:16 -0500 Subject: [PATCH] [data views] Make data view saved objects share capable (#114408) --- .../server/saved_objects/data_views.ts | 3 +- .../apis/saved_objects_management/find.ts | 2 +- .../saved_objects_management/relationships.ts | 4 +- .../saved_objects/spaces/data.json | 23 ++++--- .../common/suites/copy_to_space.ts | 15 +++-- .../suites/resolve_copy_to_space_conflicts.ts | 67 ++++++++++--------- .../apis/resolve_copy_to_space_conflicts.ts | 5 +- 7 files changed, 67 insertions(+), 52 deletions(-) diff --git a/src/plugins/data_views/server/saved_objects/data_views.ts b/src/plugins/data_views/server/saved_objects/data_views.ts index 5bb85a9bb6e9..ca7592732c3e 100644 --- a/src/plugins/data_views/server/saved_objects/data_views.ts +++ b/src/plugins/data_views/server/saved_objects/data_views.ts @@ -13,7 +13,8 @@ import { DATA_VIEW_SAVED_OBJECT_TYPE } from '../../common'; export const dataViewSavedObjectType: SavedObjectsType = { name: DATA_VIEW_SAVED_OBJECT_TYPE, hidden: false, - namespaceType: 'single', + namespaceType: 'multiple-isolated', + convertToMultiNamespaceTypeVersion: '8.0.0', management: { displayName: 'Data view', icon: 'indexPatternApp', diff --git a/test/api_integration/apis/saved_objects_management/find.ts b/test/api_integration/apis/saved_objects_management/find.ts index 0b744b7991b3..ea7f297dfeb0 100644 --- a/test/api_integration/apis/saved_objects_management/find.ts +++ b/test/api_integration/apis/saved_objects_management/find.ts @@ -249,7 +249,7 @@ export default function ({ getService }: FtrProviderContext) { path: '/app/management/kibana/dataViews/dataView/8963ca30-3224-11e8-a572-ffca06da1357', uiCapabilitiesPath: 'management.kibana.indexPatterns', }, - namespaceType: 'single', + namespaceType: 'multiple-isolated', }); })); }); diff --git a/test/api_integration/apis/saved_objects_management/relationships.ts b/test/api_integration/apis/saved_objects_management/relationships.ts index 518ec2994701..838bc05346dd 100644 --- a/test/api_integration/apis/saved_objects_management/relationships.ts +++ b/test/api_integration/apis/saved_objects_management/relationships.ts @@ -91,7 +91,7 @@ export default function ({ getService }: FtrProviderContext) { path: '/app/management/kibana/dataViews/dataView/8963ca30-3224-11e8-a572-ffca06da1357', uiCapabilitiesPath: 'management.kibana.indexPatterns', }, - namespaceType: 'single', + namespaceType: 'multiple-isolated', hiddenType: false, }, }, @@ -132,7 +132,7 @@ export default function ({ getService }: FtrProviderContext) { path: '/app/management/kibana/dataViews/dataView/8963ca30-3224-11e8-a572-ffca06da1357', uiCapabilitiesPath: 'management.kibana.indexPatterns', }, - namespaceType: 'single', + namespaceType: 'multiple-isolated', hiddenType: false, }, relationship: 'child', diff --git a/x-pack/test/spaces_api_integration/common/fixtures/es_archiver/saved_objects/spaces/data.json b/x-pack/test/spaces_api_integration/common/fixtures/es_archiver/saved_objects/spaces/data.json index 3b2a87d924e8..c1525409cfa3 100644 --- a/x-pack/test/spaces_api_integration/common/fixtures/es_archiver/saved_objects/spaces/data.json +++ b/x-pack/test/spaces_api_integration/common/fixtures/es_archiver/saved_objects/spaces/data.json @@ -153,7 +153,7 @@ "references": [ { "type": "index-pattern", - "id": "cts_ip_1", + "id": "cts_ip_1_default", "name": "CTS IP 1" } ], @@ -182,7 +182,7 @@ "references": [ { "type": "index-pattern", - "id": "cts_ip_1", + "id": "cts_ip_1_default", "name": "CTS IP 1" } ], @@ -212,7 +212,7 @@ "references": [ { "type": "index-pattern", - "id": "cts_ip_1", + "id": "cts_ip_1_default", "name": "CTS IP 1" } ], @@ -276,7 +276,7 @@ "references": [ { "type": "index-pattern", - "id": "cts_ip_1", + "id": "cts_ip_1_space_1", "name": "CTS IP 1" } ], @@ -305,7 +305,7 @@ "references": [ { "type": "index-pattern", - "id": "cts_ip_1", + "id": "cts_ip_1_space_1", "name": "CTS IP 1" } ], @@ -335,7 +335,7 @@ "references": [ { "type": "index-pattern", - "id": "cts_ip_1", + "id": "cts_ip_1_space_1", "name": "CTS IP 1" } ], @@ -350,15 +350,17 @@ { "type": "_doc", "value": { - "id": "index-pattern:cts_ip_1", + "id": "index-pattern:cts_ip_1_default", "index": ".kibana", "source": { + "originId": "cts_ip_1", "index-pattern": { "title": "Copy to Space index pattern 1 from default space" }, "references": [], "type": "index-pattern", - "updated_at": "2017-09-21T18:49:16.270Z" + "updated_at": "2017-09-21T18:49:16.270Z", + "namespaces": ["default"] }, "type": "_doc" } @@ -367,16 +369,17 @@ { "type": "_doc", "value": { - "id": "space_1:index-pattern:cts_ip_1", + "id": "index-pattern:cts_ip_1_space_1", "index": ".kibana", "source": { + "originId": "cts_ip_1", "index-pattern": { "title": "Copy to Space index pattern 1 from space_1 space" }, "references": [], "type": "index-pattern", "updated_at": "2017-09-21T18:49:16.270Z", - "namespace": "space_1" + "namespaces": ["space_1"] }, "type": "_doc" } diff --git a/x-pack/test/spaces_api_integration/common/suites/copy_to_space.ts b/x-pack/test/spaces_api_integration/common/suites/copy_to_space.ts index 3a3f0f889c91..23136838f300 100644 --- a/x-pack/test/spaces_api_integration/common/suites/copy_to_space.ts +++ b/x-pack/test/spaces_api_integration/common/suites/copy_to_space.ts @@ -183,6 +183,8 @@ export function copyToSpaceTestSuiteFactory( const destination = getDestinationWithoutConflicts(); const result = resp.body as CopyResponse; + const indexPatternDestinationId = result[destination].successResults![0].destinationId; + expect(indexPatternDestinationId).to.match(UUID_PATTERN); // this was copied to space 2 and hit an unresolvable conflict, so the object ID was regenerated silently / the destinationId is a UUID const vis1DestinationId = result[destination].successResults![1].destinationId; expect(vis1DestinationId).to.match(UUID_PATTERN); // this was copied to space 2 and hit an unresolvable conflict, so the object ID was regenerated silently / the destinationId is a UUID const vis2DestinationId = result[destination].successResults![2].destinationId; @@ -196,12 +198,13 @@ export function copyToSpaceTestSuiteFactory( successCount: 5, successResults: [ { - id: 'cts_ip_1', + id: `cts_ip_1_${spaceId}`, type: 'index-pattern', meta: { icon: 'indexPatternApp', title: `Copy to Space index pattern 1 from ${spaceId} space`, }, + destinationId: indexPatternDestinationId, }, { id: `cts_vis_1_${spaceId}`, @@ -321,13 +324,14 @@ export function copyToSpaceTestSuiteFactory( successCount: 5, successResults: [ { - id: 'cts_ip_1', + id: `cts_ip_1_${spaceId}`, type: 'index-pattern', meta: { icon: 'indexPatternApp', title: `Copy to Space index pattern 1 from ${spaceId} space`, }, overwrite: true, + destinationId: `cts_ip_1_${destination}`, // this conflicted with another index pattern in the destination space because of a shared originId }, { id: `cts_vis_1_${spaceId}`, @@ -409,8 +413,11 @@ export function copyToSpaceTestSuiteFactory( }, }, { - error: { type: 'conflict' }, - id: 'cts_ip_1', + error: { + type: 'conflict', + destinationId: `cts_ip_1_${destination}`, // this conflicted with another index pattern in the destination space because of a shared originId + }, + id: `cts_ip_1_${spaceId}`, title: `Copy to Space index pattern 1 from ${spaceId} space`, type: 'index-pattern', meta: { diff --git a/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts b/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts index b190a37965b0..72130743b69d 100644 --- a/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts +++ b/x-pack/test/spaces_api_integration/common/suites/resolve_copy_to_space_conflicts.ts @@ -82,8 +82,18 @@ export function resolveCopyToSpaceConflictsSuite( expect(result).to.eql({ [destination]: { success: true, - successCount: 1, + successCount: 2, successResults: [ + { + id: `cts_ip_1_${sourceSpaceId}`, + type: 'index-pattern', + meta: { + title: `Copy to Space index pattern 1 from ${sourceSpaceId} space`, + icon: 'indexPatternApp', + }, + destinationId: `cts_ip_1_${destination}`, // this conflicted with another index pattern in the destination space because of a shared originId + overwrite: true, + }, { id: `cts_vis_3_${sourceSpaceId}`, type: 'visualization', @@ -146,6 +156,19 @@ export function resolveCopyToSpaceConflictsSuite( success: false, successCount: 0, errors: [ + { + error: { + type: 'conflict', + destinationId: `cts_ip_1_${destination}`, // this conflicted with another index pattern in the destination space because of a shared originId + }, + id: `cts_ip_1_${sourceSpaceId}`, + title: `Copy to Space index pattern 1 from ${sourceSpaceId} space`, + meta: { + title: `Copy to Space index pattern 1 from ${sourceSpaceId} space`, + icon: 'indexPatternApp', + }, + type: 'index-pattern', + }, { error: { type: 'conflict', @@ -231,35 +254,7 @@ export function resolveCopyToSpaceConflictsSuite( { statusCode: 403, error: 'Forbidden', - message: 'Unable to bulk_get index-pattern', - }, - ], - }, - } as CopyResponse); - - // Query ES to ensure that nothing was copied - const [dashboard, visualization] = await getObjectsAtSpace(destination); - expect(dashboard.attributes.title).to.eql( - `This is the ${destination} test space CTS dashboard` - ); - expect(visualization.attributes.title).to.eql(`CTS vis 3 from ${destination} space`); - }; - - const createExpectReadonlyAtSpaceWithReferencesResult = - (spaceId: string = DEFAULT_SPACE_ID) => - async (resp: TestResponse) => { - const destination = getDestinationSpace(spaceId); - - const result = resp.body as CopyResponse; - expect(result).to.eql({ - [destination]: { - success: false, - successCount: 0, - errors: [ - { - statusCode: 403, - error: 'Forbidden', - message: 'Unable to bulk_create visualization', + message: 'Unable to bulk_create index-pattern,visualization', }, ], }, @@ -449,6 +444,7 @@ export function resolveCopyToSpaceConflictsSuite( const dashboardObject = { type: 'dashboard', id: 'cts_dashboard' }; const visualizationObject = { type: 'visualization', id: `cts_vis_3_${spaceId}` }; + const indexPatternObject = { type: 'index-pattern', id: `cts_ip_1_${spaceId}` }; it(`should return ${tests.withReferencesNotOverwriting.statusCode} when not overwriting, with references`, async () => { const destination = getDestinationSpace(spaceId); @@ -462,6 +458,11 @@ export function resolveCopyToSpaceConflictsSuite( createNewCopies: false, retries: { [destination]: [ + { + ...indexPatternObject, + destinationId: `cts_ip_1_${destination}`, + overwrite: false, + }, { ...visualizationObject, destinationId: `cts_vis_3_${destination}`, @@ -486,6 +487,11 @@ export function resolveCopyToSpaceConflictsSuite( createNewCopies: false, retries: { [destination]: [ + { + ...indexPatternObject, + destinationId: `cts_ip_1_${destination}`, + overwrite: true, + }, { ...visualizationObject, destinationId: `cts_vis_3_${destination}`, @@ -589,7 +595,6 @@ export function resolveCopyToSpaceConflictsSuite( createExpectNonOverriddenResponseWithReferences, createExpectNonOverriddenResponseWithoutReferences, createExpectUnauthorizedAtSpaceWithReferencesResult, - createExpectReadonlyAtSpaceWithReferencesResult, createExpectUnauthorizedAtSpaceWithoutReferencesResult, createMultiNamespaceTestCases, originSpaces: ['default', 'space_1'], diff --git a/x-pack/test/spaces_api_integration/security_and_spaces/apis/resolve_copy_to_space_conflicts.ts b/x-pack/test/spaces_api_integration/security_and_spaces/apis/resolve_copy_to_space_conflicts.ts index efc7827cf8b9..1b39cd5d7730 100644 --- a/x-pack/test/spaces_api_integration/security_and_spaces/apis/resolve_copy_to_space_conflicts.ts +++ b/x-pack/test/spaces_api_integration/security_and_spaces/apis/resolve_copy_to_space_conflicts.ts @@ -24,7 +24,6 @@ export default function resolveCopyToSpaceConflictsTestSuite({ getService }: Ftr createExpectOverriddenResponseWithoutReferences, expectRouteForbiddenResponse, createExpectUnauthorizedAtSpaceWithReferencesResult, - createExpectReadonlyAtSpaceWithReferencesResult, createExpectUnauthorizedAtSpaceWithoutReferencesResult, createMultiNamespaceTestCases, NON_EXISTENT_SPACE_ID, @@ -122,11 +121,11 @@ export default function resolveCopyToSpaceConflictsTestSuite({ getService }: Ftr tests: { withReferencesNotOverwriting: { statusCode: 200, - response: createExpectReadonlyAtSpaceWithReferencesResult(spaceId), + response: createExpectUnauthorizedAtSpaceWithReferencesResult(spaceId), }, withReferencesOverwriting: { statusCode: 200, - response: createExpectReadonlyAtSpaceWithReferencesResult(spaceId), + response: createExpectUnauthorizedAtSpaceWithReferencesResult(spaceId), }, withoutReferencesOverwriting: { statusCode: 200,