From df09bafcbfd8cda2fc2f02364eb816cfbb62d103 Mon Sep 17 00:00:00 2001 From: "Linh Vo (via MelvinBot)" Date: Mon, 9 Mar 2026 04:23:39 +0000 Subject: [PATCH 1/6] Hide automatic TAKE_CONTROL actions from OldDot auto-pay workflow When OldDot auto-pays a report, it creates a TAKECONTROL action as a side effect of reassigning the report manager. This action has automaticAction: true in its originalMessage. NewDot was unconditionally rendering it as "changed the approver to [owner name]". Add automaticAction to OriginalMessageTakeControl type and check it in shouldReportActionBeVisible to hide auto-pay TAKE_CONTROL actions while preserving manual take-control messages (which lack automaticAction). Co-authored-by: Linh Vo --- src/libs/ReportActionsUtils.ts | 8 ++++++++ src/types/onyx/OriginalMessage.ts | 2 ++ 2 files changed, 10 insertions(+) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index ddadc8505854..a1409b169012 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1149,6 +1149,14 @@ function shouldReportActionBeVisible(reportAction: OnyxEntry, key: return false; } + // Hide automatic TAKE_CONTROL actions created by OldDot's auto-pay workflow + if (actionName === CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL) { + const takeControlOriginalMessage = getOriginalMessage(reportAction as ReportAction); + if (takeControlOriginalMessage && 'automaticAction' in takeControlOriginalMessage && takeControlOriginalMessage.automaticAction) { + return false; + } + } + if (isWhisperActionTargetedToOthers(reportAction)) { return false; } diff --git a/src/types/onyx/OriginalMessage.ts b/src/types/onyx/OriginalMessage.ts index cc91471cb300..b72a89d1f09c 100644 --- a/src/types/onyx/OriginalMessage.ts +++ b/src/types/onyx/OriginalMessage.ts @@ -1296,6 +1296,8 @@ type OriginalMessageTakeControl = { lastModified: string; /** Tagged account IDs of new approvers */ mentionedAccountIDs: number[]; + /** Whether this action was triggered automatically (e.g., during auto-pay) */ + automaticAction?: boolean; }; /** From 8dc9665a33b917441e67be9a14ac0b948747743a Mon Sep 17 00:00:00 2001 From: "Linh Vo (via MelvinBot)" Date: Mon, 9 Mar 2026 04:24:30 +0000 Subject: [PATCH 2/6] Add fallback check for auto-pay TAKE_CONTROL without automaticAction flag For OldDot TAKE_CONTROL actions that may not have automaticAction set, add a fallback heuristic: hide when the actor is the report owner AND the report is in AUTOREIMBURSED state. This combination indicates the TAKE_CONTROL was a side effect of auto-pay, not a manual approver change. Co-authored-by: Linh Vo --- src/libs/ReportActionsUtils.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index a1409b169012..d412b56c6f94 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1149,12 +1149,20 @@ function shouldReportActionBeVisible(reportAction: OnyxEntry, key: return false; } - // Hide automatic TAKE_CONTROL actions created by OldDot's auto-pay workflow + // Hide automatic TAKE_CONTROL actions created by OldDot's auto-pay workflow. + // Primary check: the automaticAction flag explicitly marks actions from auto-pay. + // Fallback check: if the flag is missing, hide when the actor is the report owner and the report was auto-reimbursed, + // which indicates the TAKE_CONTROL was a side effect of auto-pay rather than a manual approver change. if (actionName === CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL) { const takeControlOriginalMessage = getOriginalMessage(reportAction as ReportAction); if (takeControlOriginalMessage && 'automaticAction' in takeControlOriginalMessage && takeControlOriginalMessage.automaticAction) { return false; } + + const report = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportAction.reportID}`]; + if (report && reportAction.actorAccountID === report.ownerAccountID && report.stateNum === CONST.REPORT.STATE_NUM.AUTOREIMBURSED) { + return false; + } } if (isWhisperActionTargetedToOthers(reportAction)) { From 154e7cfd716f3c9c85f73d8828b050e104e02149 Mon Sep 17 00:00:00 2001 From: "Linh Vo (via MelvinBot)" Date: Mon, 9 Mar 2026 04:45:11 +0000 Subject: [PATCH 3/6] Remove fallback condition and add mentionedAccountIDs check Per review feedback: - Removed the fallback condition that checked report owner and AUTOREIMBURSED state - Added mentionedAccountIDs check to the primary condition alongside automaticAction Co-authored-by: Linh Vo --- src/libs/ReportActionsUtils.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index d412b56c6f94..f00222967ef8 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1150,17 +1150,17 @@ function shouldReportActionBeVisible(reportAction: OnyxEntry, key: } // Hide automatic TAKE_CONTROL actions created by OldDot's auto-pay workflow. - // Primary check: the automaticAction flag explicitly marks actions from auto-pay. - // Fallback check: if the flag is missing, hide when the actor is the report owner and the report was auto-reimbursed, - // which indicates the TAKE_CONTROL was a side effect of auto-pay rather than a manual approver change. + // When automaticAction is true and the actor is in mentionedAccountIDs, this indicates + // the TAKE_CONTROL was a side effect of auto-pay rather than a manual approver change. if (actionName === CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL) { const takeControlOriginalMessage = getOriginalMessage(reportAction as ReportAction); - if (takeControlOriginalMessage && 'automaticAction' in takeControlOriginalMessage && takeControlOriginalMessage.automaticAction) { - return false; - } - - const report = reports?.[`${ONYXKEYS.COLLECTION.REPORT}${reportAction.reportID}`]; - if (report && reportAction.actorAccountID === report.ownerAccountID && report.stateNum === CONST.REPORT.STATE_NUM.AUTOREIMBURSED) { + if ( + takeControlOriginalMessage && + 'automaticAction' in takeControlOriginalMessage && + takeControlOriginalMessage.automaticAction && + reportAction.actorAccountID && + takeControlOriginalMessage.mentionedAccountIDs?.includes(reportAction.actorAccountID) + ) { return false; } } From e327fdb9696006f31b2102385b9976f0c22221e6 Mon Sep 17 00:00:00 2001 From: "Linh Vo (via MelvinBot)" Date: Mon, 9 Mar 2026 04:54:19 +0000 Subject: [PATCH 4/6] Fix: Use Onyx.set in TAKE_CONTROL and REROUTE tests to prevent state leakage The APPROVED action test leaves automaticAction: true in originalMessage via Onyx deep merge. When the TAKE_CONTROL test runs after, this leaked property triggers the new automaticAction visibility check, hiding the action and causing the test to expect non-empty text but receive "". Switch to Onyx.set to replace (not merge) the report actions collection, ensuring each test starts with clean data. Co-authored-by: Linh Vo --- tests/unit/OptionsListUtilsTest.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/OptionsListUtilsTest.tsx b/tests/unit/OptionsListUtilsTest.tsx index 4b04baaefaa0..736217db080c 100644 --- a/tests/unit/OptionsListUtilsTest.tsx +++ b/tests/unit/OptionsListUtilsTest.tsx @@ -4501,7 +4501,7 @@ describe('OptionsListUtils', () => { message: [{type: 'COMMENT', text: ''}], originalMessage: {}, }; - await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, { + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, { [takeControlAction.reportActionID]: takeControlAction, }); const lastMessage = getLastMessageTextForReport({ @@ -4522,7 +4522,7 @@ describe('OptionsListUtils', () => { message: [{type: 'COMMENT', text: ''}], originalMessage: {}, }; - await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, { + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`, { [rerouteAction.reportActionID]: rerouteAction, }); const lastMessage = getLastMessageTextForReport({ From 39ab07f7b3ad292861c31b4581d25ee054fc7743 Mon Sep 17 00:00:00 2001 From: "Linh Vo (via MelvinBot)" Date: Mon, 9 Mar 2026 05:06:08 +0000 Subject: [PATCH 5/6] Apply review suggestion and add TAKE_CONTROL unit tests - Simplified TAKE_CONTROL visibility condition per review suggestion: hide when automaticAction is true and mentionedAccountIDs is empty - Added 4 unit tests covering TAKE_CONTROL visibility scenarios Co-authored-by: Linh Vo --- src/libs/ReportActionsUtils.ts | 12 ++--- tests/unit/ReportActionsUtilsTest.ts | 66 ++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 9 deletions(-) diff --git a/src/libs/ReportActionsUtils.ts b/src/libs/ReportActionsUtils.ts index f00222967ef8..c1c417e730d5 100644 --- a/src/libs/ReportActionsUtils.ts +++ b/src/libs/ReportActionsUtils.ts @@ -1150,17 +1150,11 @@ function shouldReportActionBeVisible(reportAction: OnyxEntry, key: } // Hide automatic TAKE_CONTROL actions created by OldDot's auto-pay workflow. - // When automaticAction is true and the actor is in mentionedAccountIDs, this indicates + // When automaticAction is true and there are no mentionedAccountIDs, this indicates // the TAKE_CONTROL was a side effect of auto-pay rather than a manual approver change. if (actionName === CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL) { - const takeControlOriginalMessage = getOriginalMessage(reportAction as ReportAction); - if ( - takeControlOriginalMessage && - 'automaticAction' in takeControlOriginalMessage && - takeControlOriginalMessage.automaticAction && - reportAction.actorAccountID && - takeControlOriginalMessage.mentionedAccountIDs?.includes(reportAction.actorAccountID) - ) { + const originalMessage = getOriginalMessage(reportAction as ReportAction); + if (originalMessage?.automaticAction && !originalMessage?.mentionedAccountIDs?.length) { return false; } } diff --git a/tests/unit/ReportActionsUtilsTest.ts b/tests/unit/ReportActionsUtilsTest.ts index e82970f2a553..ff7b58987bdd 100644 --- a/tests/unit/ReportActionsUtilsTest.ts +++ b/tests/unit/ReportActionsUtilsTest.ts @@ -1636,6 +1636,72 @@ describe('ReportActionsUtils', () => { const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true); expect(actual).toBe(true); }); + + it('should return false for TAKE_CONTROL when automaticAction is true and mentionedAccountIDs is empty', () => { + const reportAction: ReportAction = { + actionName: CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL, + reportActionID: '1', + created: '2025-09-29', + originalMessage: { + lastModified: '2025-09-29', + mentionedAccountIDs: [], + automaticAction: true, + }, + }; + + const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true); + expect(actual).toBe(false); + }); + + it('should return true for TAKE_CONTROL when automaticAction is true but mentionedAccountIDs has values', () => { + const reportAction: ReportAction = { + actionName: CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL, + reportActionID: '1', + created: '2025-09-29', + message: [{html: 'took control', type: 'COMMENT', text: 'took control'}], + originalMessage: { + lastModified: '2025-09-29', + mentionedAccountIDs: [123], + automaticAction: true, + }, + }; + + const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true); + expect(actual).toBe(true); + }); + + it('should return true for TAKE_CONTROL when automaticAction is false', () => { + const reportAction: ReportAction = { + actionName: CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL, + reportActionID: '1', + created: '2025-09-29', + message: [{html: 'took control', type: 'COMMENT', text: 'took control'}], + originalMessage: { + lastModified: '2025-09-29', + mentionedAccountIDs: [], + automaticAction: false, + }, + }; + + const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true); + expect(actual).toBe(true); + }); + + it('should return true for TAKE_CONTROL when automaticAction is not set', () => { + const reportAction: ReportAction = { + actionName: CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL, + reportActionID: '1', + created: '2025-09-29', + message: [{html: 'took control', type: 'COMMENT', text: 'took control'}], + originalMessage: { + lastModified: '2025-09-29', + mentionedAccountIDs: [456], + }, + }; + + const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true); + expect(actual).toBe(true); + }); }); describe('getPolicyChangeLogUpdateEmployee', () => { From 4fefaf4433c284731bfb0844062dd32988f46bce Mon Sep 17 00:00:00 2001 From: "Linh Vo (via MelvinBot)" Date: Mon, 9 Mar 2026 05:22:37 +0000 Subject: [PATCH 6/6] Fix: Use type assertions for TAKE_CONTROL test objects to resolve typecheck The OriginalMessageTakeControl type is defined in both OriginalMessage.ts and OldDotAction.ts with incompatible structures. Their intersection in OriginalMessageMap requires properties from both types simultaneously. Using type assertions (matching the established test pattern) avoids this type conflict while keeping the test logic intact. Co-authored-by: Linh Vo --- tests/unit/ReportActionsUtilsTest.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/unit/ReportActionsUtilsTest.ts b/tests/unit/ReportActionsUtilsTest.ts index ff7b58987bdd..5eb5f9e4895c 100644 --- a/tests/unit/ReportActionsUtilsTest.ts +++ b/tests/unit/ReportActionsUtilsTest.ts @@ -1638,23 +1638,23 @@ describe('ReportActionsUtils', () => { }); it('should return false for TAKE_CONTROL when automaticAction is true and mentionedAccountIDs is empty', () => { - const reportAction: ReportAction = { + const reportAction = { actionName: CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL, reportActionID: '1', created: '2025-09-29', originalMessage: { lastModified: '2025-09-29', - mentionedAccountIDs: [], + mentionedAccountIDs: [] as number[], automaticAction: true, }, - }; + } as ReportAction; const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true); expect(actual).toBe(false); }); it('should return true for TAKE_CONTROL when automaticAction is true but mentionedAccountIDs has values', () => { - const reportAction: ReportAction = { + const reportAction = { actionName: CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL, reportActionID: '1', created: '2025-09-29', @@ -1664,31 +1664,31 @@ describe('ReportActionsUtils', () => { mentionedAccountIDs: [123], automaticAction: true, }, - }; + } as ReportAction; const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true); expect(actual).toBe(true); }); it('should return true for TAKE_CONTROL when automaticAction is false', () => { - const reportAction: ReportAction = { + const reportAction = { actionName: CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL, reportActionID: '1', created: '2025-09-29', message: [{html: 'took control', type: 'COMMENT', text: 'took control'}], originalMessage: { lastModified: '2025-09-29', - mentionedAccountIDs: [], + mentionedAccountIDs: [] as number[], automaticAction: false, }, - }; + } as ReportAction; const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true); expect(actual).toBe(true); }); it('should return true for TAKE_CONTROL when automaticAction is not set', () => { - const reportAction: ReportAction = { + const reportAction = { actionName: CONST.REPORT.ACTIONS.TYPE.TAKE_CONTROL, reportActionID: '1', created: '2025-09-29', @@ -1697,7 +1697,7 @@ describe('ReportActionsUtils', () => { lastModified: '2025-09-29', mentionedAccountIDs: [456], }, - }; + } as ReportAction; const actual = ReportActionsUtils.shouldReportActionBeVisible(reportAction, reportAction.reportActionID, true); expect(actual).toBe(true);