Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaHeiligers committed Apr 25, 2023
1 parent 0669c42 commit 4eeb530
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ export class SavedObjectsRepository implements ISavedObjectsRepository {
typeMigrationVersion: object.typeMigrationVersion,
...(savedObjectNamespace && { namespace: savedObjectNamespace }),
...(savedObjectNamespaces && { namespaces: savedObjectNamespaces }),
managed: setManaged({ optionsManaged, objectManaged: object.managed }), // managed: optionsManaged ?? object.managed ?? false,
managed: setManaged({ optionsManaged, objectManaged: object.managed }),
updated_at: time,
created_at: time,
references: object.references || [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('#importSavedObjectsFromStream', () => {
const createObject = ({
type = 'foo-type',
title = 'some-title',
managed = undefined, // yea, explicitly declare this as not set to test against existing objects
managed = undefined, // explicitly declare undefined so as not set to test against existing objects
}: { type?: string; title?: string; managed?: boolean } = {}): SavedObject<{
title: string;
managed?: boolean;
Expand Down Expand Up @@ -506,7 +506,7 @@ describe('#importSavedObjectsFromStream', () => {
});

const result = await importSavedObjectsFromStream(options);
// successResults only includes the imported object's type, id, and destinationId (if a new one was generated)
// successResults only includes the imported object's type, id, managed, and destinationId (if a new one was generated)
const successResults = [
{
type: obj1.type,
Expand Down Expand Up @@ -560,11 +560,11 @@ describe('#importSavedObjectsFromStream', () => {
createdObjects: [
{ ...obj1, managed: true },
{ ...obj2, managed: true },
], // default applied in createSavedObjects
], // make sure the default isn't applied in createSavedObjects
});

const result = await importSavedObjectsFromStream(options);
// successResults only includes the imported object's type, id, and destinationId (if a new one was generated)
// successResults only includes the imported object's type, id, managed and destinationId (if a new one was generated)
const successResults = [
{
type: obj1.type,
Expand Down Expand Up @@ -622,7 +622,7 @@ describe('#importSavedObjectsFromStream', () => {
});

const result = await importSavedObjectsFromStream(options);
// successResults only includes the imported object's type, id, destinationId (if a new one was generated) and managed
// successResults only includes the imported object's type, id, managed and destinationId (if a new one was generated)
const successResults = [
{
type: obj1.type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ export async function collectSavedObjects({
}
}
// Ensure migrations execute on every saved object
// Managed prop handling: // we don't make any assumptions about how to handle defaults for overwriting all abjects' managed flag if there isn't a `managed` option passed to the call. This allows us to retain the flag on objects being imported, if it's already present on the object.
// We fall back to false if managed isn't declared as an option and the object being imported doesn't already have the prop set. We do this to avoid having to run the core transform for backfilling.
return {
...obj,
...(!obj.migrationVersion && !obj.typeMigrationVersion ? { typeMigrationVersion: '' } : {}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface CreateSavedObjectsResult<T> {
* the objects we create, and the create results should be mapped to the original IDs that consumers will be able to understand.
*/
export const createSavedObjects = async <T>({
objects, // these already have the managed flag set
objects,
accumulatedErrors,
savedObjectsClient,
importStateMap,
Expand Down Expand Up @@ -109,7 +109,7 @@ export const createSavedObjects = async <T>({
...object,
...(references && { references }),
...(originId && { originId }),
...{ managed: managed ?? object.managed ?? false }, // trictly speaking this shouldn't be needed since the objects passed in should already have the flag set
...{ managed: managed ?? object.managed ?? false },
};
});

Expand Down Expand Up @@ -178,7 +178,7 @@ export const createSavedObjects = async <T>({
overwrite,
refresh,
})
).saved_objects // already have managed specified
).saved_objects
: [];
return {
createdObjects: remappedResults.filter((obj) => !obj.error),
Expand Down
4 changes: 2 additions & 2 deletions test/api_integration/apis/saved_objects/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,13 +588,13 @@ export default function ({ getService }: FtrProviderContext) {
{ space: SPACE_ID }
);
await kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/managedObjects.json',
'test/api_integration/fixtures/kbn_archiver/saved_objects/managed_objects.json',
{ space: SPACE_ID }
);
});
after(async () => {
await kibanaServer.importExport.unload(
'test/api_integration/fixtures/kbn_archiver/saved_objects/managedObjects.json',
'test/api_integration/fixtures/kbn_archiver/saved_objects/managed_objects.json',
{ space: SPACE_ID }
);
});
Expand Down
6 changes: 0 additions & 6 deletions test/api_integration/apis/saved_objects/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,11 @@ export default function ({ getService }: FtrProviderContext) {
await kibanaServer.importExport.load(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
);
// await kibanaServer.importExport.load(
// 'test/api_integration/fixtures/kbn_archiver/saved_objects/managed_basic.json'
// );
});
after(async () => {
await kibanaServer.importExport.unload(
'test/api_integration/fixtures/kbn_archiver/saved_objects/basic.json'
);
// await kibanaServer.importExport.unload(
// 'test/api_integration/fixtures/kbn_archiver/saved_objects/managed_basic.json'
// );
});

it('should return 415 when no file passed in', async () => {
Expand Down

0 comments on commit 4eeb530

Please sign in to comment.