Skip to content

Commit 2937c7d

Browse files
[SOM] Add visibleInManagement option to management metadata (#112073) (#112639)
* implement SavedObjectsTypeManagementDefinition.visibleInManagement * update generated doc * improve FTR tests * fix FTR test Co-authored-by: Pierre Gayvallet <[email protected]>
1 parent 77b0c6a commit 2937c7d

File tree

14 files changed

+737
-0
lines changed

14 files changed

+737
-0
lines changed

docs/development/core/server/kibana-plugin-core-server.deprecationsservicesetup.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ async function getDeprecations({ esClient, savedObjectsClient }: GetDeprecations
2727
const deprecations: DeprecationsDetails[] = [];
2828
const count = await getFooCount(savedObjectsClient);
2929
if (count > 0) {
30+
// Example of a manual correctiveAction
3031
deprecations.push({
3132
title: i18n.translate('xpack.foo.deprecations.title', {
3233
defaultMessage: `Foo's are deprecated`

docs/development/core/server/kibana-plugin-core-server.savedobjectstypemanagementdefinition.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ export interface SavedObjectsTypeManagementDefinition<Attributes = any>
2525
| [isExportable](./kibana-plugin-core-server.savedobjectstypemanagementdefinition.isexportable.md) | <code>SavedObjectsExportablePredicate&lt;Attributes&gt;</code> | Optional hook to specify whether an object should be exportable.<!-- -->If specified, <code>isExportable</code> will be called during export for each of this type's objects in the export, and the ones not matching the predicate will be excluded from the export.<!-- -->When implementing both <code>isExportable</code> and <code>onExport</code>, it is mandatory that <code>isExportable</code> returns the same value for an object before and after going though the export transform. E.g <code>isExportable(objectBeforeTransform) === isExportable(objectAfterTransform)</code> |
2626
| [onExport](./kibana-plugin-core-server.savedobjectstypemanagementdefinition.onexport.md) | <code>SavedObjectsExportTransform&lt;Attributes&gt;</code> | An optional export transform function that can be used transform the objects of the registered type during the export process.<!-- -->It can be used to either mutate the exported objects, or add additional objects (of any type) to the export list.<!-- -->See [the transform type documentation](./kibana-plugin-core-server.savedobjectsexporttransform.md) for more info and examples.<!-- -->When implementing both <code>isExportable</code> and <code>onExport</code>, it is mandatory that <code>isExportable</code> returns the same value for an object before and after going though the export transform. E.g <code>isExportable(objectBeforeTransform) === isExportable(objectAfterTransform)</code> |
2727
| [onImport](./kibana-plugin-core-server.savedobjectstypemanagementdefinition.onimport.md) | <code>SavedObjectsImportHook&lt;Attributes&gt;</code> | An optional [import hook](./kibana-plugin-core-server.savedobjectsimporthook.md) to use when importing given type.<!-- -->Import hooks are executed during the savedObjects import process and allow to interact with the imported objects. See the [hook documentation](./kibana-plugin-core-server.savedobjectsimporthook.md) for more info. |
28+
| [visibleInManagement](./kibana-plugin-core-server.savedobjectstypemanagementdefinition.visibleinmanagement.md) | <code>boolean</code> | When set to false, the type will not be listed or searchable in the SO management section. Main usage of setting this property to false for a type is when objects from the type should be included in the export via references or export hooks, but should not directly appear in the SOM. Defaults to <code>true</code>. |
2829

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-core-server](./kibana-plugin-core-server.md) &gt; [SavedObjectsTypeManagementDefinition](./kibana-plugin-core-server.savedobjectstypemanagementdefinition.md) &gt; [visibleInManagement](./kibana-plugin-core-server.savedobjectstypemanagementdefinition.visibleinmanagement.md)
4+
5+
## SavedObjectsTypeManagementDefinition.visibleInManagement property
6+
7+
When set to false, the type will not be listed or searchable in the SO management section. Main usage of setting this property to false for a type is when objects from the type should be included in the export via references or export hooks, but should not directly appear in the SOM. Defaults to `true`<!-- -->.
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
visibleInManagement?: boolean;
13+
```
14+
15+
## Remarks
16+
17+
`importableAndExportable` must be `true` to specify this property.
18+

src/core/server/saved_objects/saved_objects_type_registry.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,59 @@ describe('SavedObjectTypeRegistry', () => {
4747
}).toThrowErrorMatchingInlineSnapshot(`"Type 'typeA' is already registered"`);
4848
});
4949

50+
it('throws when `management.visibleInManagement` is specified but `management.importableAndExportable` is undefined or false', () => {
51+
expect(() => {
52+
registry.registerType(
53+
createType({
54+
name: 'typeA',
55+
management: {
56+
visibleInManagement: true,
57+
},
58+
})
59+
);
60+
}).toThrowErrorMatchingInlineSnapshot(
61+
`"Type typeA: 'management.importableAndExportable' must be 'true' when specifying 'management.visibleInManagement'"`
62+
);
63+
64+
expect(() => {
65+
registry.registerType(
66+
createType({
67+
name: 'typeA',
68+
management: {
69+
visibleInManagement: false,
70+
},
71+
})
72+
);
73+
}).toThrowErrorMatchingInlineSnapshot(
74+
`"Type typeA: 'management.importableAndExportable' must be 'true' when specifying 'management.visibleInManagement'"`
75+
);
76+
77+
expect(() => {
78+
registry.registerType(
79+
createType({
80+
name: 'typeA',
81+
management: {
82+
importableAndExportable: false,
83+
visibleInManagement: false,
84+
},
85+
})
86+
);
87+
}).toThrowErrorMatchingInlineSnapshot(
88+
`"Type typeA: 'management.importableAndExportable' must be 'true' when specifying 'management.visibleInManagement'"`
89+
);
90+
expect(() => {
91+
registry.registerType(
92+
createType({
93+
name: 'typeA',
94+
management: {
95+
importableAndExportable: true,
96+
visibleInManagement: false,
97+
},
98+
})
99+
);
100+
}).not.toThrow();
101+
});
102+
50103
it('throws when `management.onExport` is specified but `management.importableAndExportable` is undefined or false', () => {
51104
expect(() => {
52105
registry.registerType(

src/core/server/saved_objects/saved_objects_type_registry.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,10 @@ const validateType = ({ name, management }: SavedObjectsType) => {
134134
`Type ${name}: 'management.importableAndExportable' must be 'true' when specifying 'management.onExport'`
135135
);
136136
}
137+
if (management.visibleInManagement !== undefined && !management.importableAndExportable) {
138+
throw new Error(
139+
`Type ${name}: 'management.importableAndExportable' must be 'true' when specifying 'management.visibleInManagement'`
140+
);
141+
}
137142
}
138143
};

src/core/server/saved_objects/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,15 @@ export interface SavedObjectsTypeManagementDefinition<Attributes = any> {
356356
* Is the type importable or exportable. Defaults to `false`.
357357
*/
358358
importableAndExportable?: boolean;
359+
/**
360+
* When set to false, the type will not be listed or searchable in the SO management section.
361+
* Main usage of setting this property to false for a type is when objects from the type should
362+
* be included in the export via references or export hooks, but should not directly appear in the SOM.
363+
* Defaults to `true`.
364+
*
365+
* @remarks `importableAndExportable` must be `true` to specify this property.
366+
*/
367+
visibleInManagement?: boolean;
359368
/**
360369
* The default search field to use for this type. Defaults to `id`.
361370
*/

src/core/server/server.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,6 +2728,7 @@ export interface SavedObjectsTypeManagementDefinition<Attributes = any> {
27282728
isExportable?: SavedObjectsExportablePredicate<Attributes>;
27292729
onExport?: SavedObjectsExportTransform<Attributes>;
27302730
onImport?: SavedObjectsImportHook<Attributes>;
2731+
visibleInManagement?: boolean;
27312732
}
27322733

27332734
// @public

src/plugins/saved_objects_management/server/routes/get_allowed_types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export const registerGetAllowedTypesRoute = (router: IRouter) => {
1717
async (context, req, res) => {
1818
const allowedTypes = context.core.savedObjects.typeRegistry
1919
.getImportableAndExportableTypes()
20+
.filter((type) => type.management!.visibleInManagement ?? true)
2021
.map((type) => type.name);
2122

2223
return res.ok({
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"type": "doc",
3+
"value": {
4+
"id": "test-not-visible-in-management:vim-1",
5+
"index": ".kibana",
6+
"source": {
7+
"coreMigrationVersion": "7.14.0",
8+
"references": [
9+
],
10+
"test-not-visible-in-management": {
11+
"enabled": true,
12+
"title": "vim-1"
13+
},
14+
"type": "test-not-visible-in-management",
15+
"updated_at": "2018-12-21T00:43:07.096Z"
16+
},
17+
"type": "_doc"
18+
}
19+
}
20+

0 commit comments

Comments
 (0)