diff --git a/i18n/en.pot b/i18n/en.pot index e64b25d92..8a055491e 100644 --- a/i18n/en.pot +++ b/i18n/en.pot @@ -5,8 +5,8 @@ msgstr "" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1)\n" -"POT-Creation-Date: 2024-08-05T19:23:59.881Z\n" -"PO-Revision-Date: 2024-08-05T19:23:59.881Z\n" +"POT-Creation-Date: 2024-08-06T07:39:27.037Z\n" +"PO-Revision-Date: 2024-08-06T07:39:27.037Z\n" msgid "" "THIS NEW RELEASE INCLUDES SHARING SETTINGS PER INSTANCES. FOR THIS VERSION " diff --git a/src/domain/metadata/usecases/MetadataSyncUseCase.ts b/src/domain/metadata/usecases/MetadataSyncUseCase.ts index 5d61f7c49..81d8962f1 100644 --- a/src/domain/metadata/usecases/MetadataSyncUseCase.ts +++ b/src/domain/metadata/usecases/MetadataSyncUseCase.ts @@ -26,6 +26,7 @@ export class MetadataSyncUseCase extends GenericSyncUseCase { includeSharingSettings, removeOrgUnitReferences, removeUserObjectsAndReferences, + removeUserNonEssentialObjects, } = builder; //TODO: when metadata entities schema exists on domain, move this factory to domain @@ -56,7 +57,8 @@ export class MetadataSyncUseCase extends GenericSyncUseCase { excludeRules, includeSharingSettings, removeOrgUnitReferences, - removeUserObjectsAndReferences + removeUserObjectsAndReferences, + removeUserNonEssentialObjects ); result[collectionName] = result[collectionName] || []; @@ -75,6 +77,7 @@ export class MetadataSyncUseCase extends GenericSyncUseCase { includeSharingSettings, removeOrgUnitReferences, removeUserObjectsAndReferences, + removeUserNonEssentialObjects, }); }); @@ -93,6 +96,7 @@ export class MetadataSyncUseCase extends GenericSyncUseCase { includeSharingSettings = true, removeOrgUnitReferences = false, removeUserObjectsAndReferences = false, + removeUserNonEssentialObjects = false, metadataIncludeExcludeRules = {}, useDefaultIncludeExclude = {}, } = syncParams ?? {}; @@ -132,6 +136,7 @@ export class MetadataSyncUseCase extends GenericSyncUseCase { includeSharingSettings, removeOrgUnitReferences, removeUserObjectsAndReferences, + removeUserNonEssentialObjects, }); }); diff --git a/src/domain/metadata/utils.ts b/src/domain/metadata/utils.ts index 6cea35378..d66cb84bb 100644 --- a/src/domain/metadata/utils.ts +++ b/src/domain/metadata/utils.ts @@ -27,7 +27,8 @@ export function cleanObject( excludeRules: string[][] = [], includeSharingSettings: boolean, removeOrgUnitReferences: boolean, - removeUserObjectsAndReferences: boolean + removeUserObjectsAndReferences: boolean, + removeNonEssentialObjects: boolean ): any { const leafRules: string[] = _(excludeRules) .filter(path => path.length === 1) @@ -46,9 +47,31 @@ export function cleanObject( const sharingSettingsFilter = includeSharingSettings ? [] : userProperties; const organisationUnitFilter = removeOrgUnitReferences ? ["organisationUnits"] : []; const userFilter = removeUserObjectsAndReferences ? ["createdBy", "lastUpdatedBy", "user"] : []; - const propsToRemove = [...sharingSettingsFilter, ...organisationUnitFilter, ...userFilter]; + const userNonEssentialObjectsFilter = removeNonEssentialObjects + ? ["lastUpdated", "created", "lastUpdatedBy", "createdBy"] + : []; + const propsToRemove = _.uniq([ + ...sharingSettingsFilter, + ...organisationUnitFilter, + ...userFilter, + ...userNonEssentialObjectsFilter, + ...cleanLeafRules, + ...blacklistedProperties, + ]); + + const elementWithCleanedChildrenProperties = _(element) + .mapValues(children => + _.isArray(children) + ? children.map(childElement => cleanPropertiesToSync(childElement, propsToRemove)) + : children + ) + .value(); + + return cleanPropertiesToSync(elementWithCleanedChildrenProperties, propsToRemove); +} - return _.pick(element, _.difference(_.keys(element), cleanLeafRules, blacklistedProperties, propsToRemove)); +function cleanPropertiesToSync(element: Record, propsToRemove: string[]): Record { + return _.pick(element, _.difference(_.keys(element), propsToRemove)); } export function cleanReferences(references: Record, includeRules: string[][] = []): string[] { diff --git a/src/types/synchronization.ts b/src/types/synchronization.ts index 837664407..961401a32 100644 --- a/src/types/synchronization.ts +++ b/src/types/synchronization.ts @@ -9,6 +9,7 @@ export interface ExportBuilder { includeSharingSettings: boolean; removeOrgUnitReferences: boolean; removeUserObjectsAndReferences: boolean; + removeUserNonEssentialObjects: boolean; } export interface SynchronizationState {