Skip to content

Commit

Permalink
feat: remove non essential user data from sync payload
Browse files Browse the repository at this point in the history
  • Loading branch information
deeonwuli committed Aug 6, 2024
1 parent 554f19b commit ca36f5d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
4 changes: 2 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand Down
7 changes: 6 additions & 1 deletion src/domain/metadata/usecases/MetadataSyncUseCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -56,7 +57,8 @@ export class MetadataSyncUseCase extends GenericSyncUseCase {
excludeRules,
includeSharingSettings,
removeOrgUnitReferences,
removeUserObjectsAndReferences
removeUserObjectsAndReferences,
removeUserNonEssentialObjects
);

result[collectionName] = result[collectionName] || [];
Expand All @@ -75,6 +77,7 @@ export class MetadataSyncUseCase extends GenericSyncUseCase {
includeSharingSettings,
removeOrgUnitReferences,
removeUserObjectsAndReferences,
removeUserNonEssentialObjects,
});
});

Expand All @@ -93,6 +96,7 @@ export class MetadataSyncUseCase extends GenericSyncUseCase {
includeSharingSettings = true,
removeOrgUnitReferences = false,
removeUserObjectsAndReferences = false,
removeUserNonEssentialObjects = false,
metadataIncludeExcludeRules = {},
useDefaultIncludeExclude = {},
} = syncParams ?? {};
Expand Down Expand Up @@ -132,6 +136,7 @@ export class MetadataSyncUseCase extends GenericSyncUseCase {
includeSharingSettings,
removeOrgUnitReferences,
removeUserObjectsAndReferences,
removeUserNonEssentialObjects,
});
});

Expand Down
29 changes: 26 additions & 3 deletions src/domain/metadata/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<string, any>, propsToRemove: string[]): Record<string, any> {
return _.pick(element, _.difference(_.keys(element), propsToRemove));
}

export function cleanReferences(references: Record<string, string[]>, includeRules: string[][] = []): string[] {
Expand Down
1 change: 1 addition & 0 deletions src/types/synchronization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface ExportBuilder {
includeSharingSettings: boolean;
removeOrgUnitReferences: boolean;
removeUserObjectsAndReferences: boolean;
removeUserNonEssentialObjects: boolean;
}

export interface SynchronizationState {
Expand Down

0 comments on commit ca36f5d

Please sign in to comment.