Skip to content

Commit

Permalink
[data views] Make data view saved objects share capable (#114408)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkime authored and cqliu1 committed Oct 25, 2021
1 parent 12c2aae commit 92d22c6
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 52 deletions.
3 changes: 2 additions & 1 deletion src/plugins/data_views/server/saved_objects/data_views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion test/api_integration/apis/saved_objects_management/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
}));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
"references": [
{
"type": "index-pattern",
"id": "cts_ip_1",
"id": "cts_ip_1_default",
"name": "CTS IP 1"
}
],
Expand Down Expand Up @@ -182,7 +182,7 @@
"references": [
{
"type": "index-pattern",
"id": "cts_ip_1",
"id": "cts_ip_1_default",
"name": "CTS IP 1"
}
],
Expand Down Expand Up @@ -212,7 +212,7 @@
"references": [
{
"type": "index-pattern",
"id": "cts_ip_1",
"id": "cts_ip_1_default",
"name": "CTS IP 1"
}
],
Expand Down Expand Up @@ -276,7 +276,7 @@
"references": [
{
"type": "index-pattern",
"id": "cts_ip_1",
"id": "cts_ip_1_space_1",
"name": "CTS IP 1"
}
],
Expand Down Expand Up @@ -305,7 +305,7 @@
"references": [
{
"type": "index-pattern",
"id": "cts_ip_1",
"id": "cts_ip_1_space_1",
"name": "CTS IP 1"
}
],
Expand Down Expand Up @@ -335,7 +335,7 @@
"references": [
{
"type": "index-pattern",
"id": "cts_ip_1",
"id": "cts_ip_1_space_1",
"name": "CTS IP 1"
}
],
Expand All @@ -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"
}
Expand All @@ -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"
}
Expand Down
15 changes: 11 additions & 4 deletions x-pack/test/spaces_api_integration/common/suites/copy_to_space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}`,
Expand Down Expand Up @@ -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}`,
Expand Down Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
},
],
},
Expand Down Expand Up @@ -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);
Expand All @@ -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}`,
Expand All @@ -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}`,
Expand Down Expand Up @@ -589,7 +595,6 @@ export function resolveCopyToSpaceConflictsSuite(
createExpectNonOverriddenResponseWithReferences,
createExpectNonOverriddenResponseWithoutReferences,
createExpectUnauthorizedAtSpaceWithReferencesResult,
createExpectReadonlyAtSpaceWithReferencesResult,
createExpectUnauthorizedAtSpaceWithoutReferencesResult,
createMultiNamespaceTestCases,
originSpaces: ['default', 'space_1'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export default function resolveCopyToSpaceConflictsTestSuite({ getService }: Ftr
createExpectOverriddenResponseWithoutReferences,
expectRouteForbiddenResponse,
createExpectUnauthorizedAtSpaceWithReferencesResult,
createExpectReadonlyAtSpaceWithReferencesResult,
createExpectUnauthorizedAtSpaceWithoutReferencesResult,
createMultiNamespaceTestCases,
NON_EXISTENT_SPACE_ID,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 92d22c6

Please sign in to comment.