Repository navigation
fix: stop unmerge from leaving ui work history on the primary - #5170
Merged
Merged
Conversation
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
[Medium impact] The PR appears safe to merge; the previous date-matching issue is fixed. SummaryFixes work-history roles left on the primary after an unmerge.
Reviews (2) · Last reviewed commit: "fix: compare unmerge role dates by value" · Reviewed by Greptile |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unmerge cleanup can delete primary role history from coalesced intervals, while strict Date-versus-string comparisons retain secondary-only history on both restored entities.
2 open issues
What changed in this PR
This PR targets duplicated UI-entered work history during member and organization unmerge, including repeated restores through the dissect workflow.
Changes:
- Uses merge backups to identify UI roles belonging only to the secondary entity.
- Extends member cleanup to remove matching secondary UI roles absent from the primary payload.
- Allows organization cleanup to delete UI roles excluded by the shared unmerge logic.
| File | Description |
|---|---|
services/libs/common_services/src/services/member/unmerge.ts |
Reuses role matching and extends stale-role cleanup to selected UI roles. |
services/libs/common_services/src/services/member-organization.ts |
Exports the role comparator and adds backup-based UI-role ownership checks. |
backend/src/services/organizationService.ts |
Removes the blanket UI-role exemption from organization unmerge cleanup. |
Review effort: Balanced
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
When a merge is reverted, work-history roles with source
uithat came from the secondary stay on the primary. The restored secondary also gets them back from its backup, so both end up with the same roles. This affects member and organization unmerge. The dissect workflow reverts a whole merge chain, so one profile'suiroles end up on every member it restores.Example: member B has a
uirole at Acme (acme.com). Merge B into A, then unmerge. Before this PR, A and B both have the Acme role. After it, only B does.Cause
Two
uiexceptions in the unmerge path:unmergeRoleskeeps everyuirole on the primary without checking where it came from.uiroles, so nothing removes them. Dissect posts the raw merge backup and never callsunmergeRoles, so this alone causes the leak there.Changes
unmergeRoles(used by both member and organization unmerge): auirole is removed from the primary only if it matches a role in the secondary backup and none in the primary backup.uiroles the primary had before the merge, or that were added after it, stay. Other sources are unchanged.unmergeMember: the cleanup also deletesuiroles that are missing from the primary payload and are being restored to the secondary.OrganizationService.unmerge: the cleanup no longer skipsuiroles. It already runsunmergeRoleson the organization's live roles, so the rule above decides which ones stay.roleExistsInArraycompares dates by value. It is now used by both cleanups. The backend reads live roles through Sequelize asDateobjects, while backups and payloads hold date strings, so the old===check never matched a dated role.Roles are matched on organization (or member, for organization unmerge), title,
dateStartanddateEnd.Because dated roles never matched before, the cleanup deleted every dated role on the primary, from any source, whenever the secondary had roles. With the date fix, the primary keeps the dated roles it had before the merge.
Type of change
Related issue
Refs linuxfoundation/lfx-cdp-insights-ops#855