diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 3474b4f80373..0a6235eaa251 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -2550,7 +2550,7 @@ function canDeleteReportAction(reportAction: OnyxInputOrEntry, rep return false; } - const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN && !isEmptyObject(report) && !isDM(report); + const isAdmin = policy?.type !== CONST.POLICY.TYPE.PERSONAL && policy?.role === CONST.POLICY.ROLE.ADMIN && !isEmptyObject(report); return isActionOwner || isAdmin; } diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index 47884239ae9b..3df0eed44f74 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -3009,6 +3009,33 @@ describe('ReportUtils', () => { expect(canDeleteReportAction(moneyRequestAction, '1', transaction)).toBe(true); }); + + it("should return false for ADD_COMMENT report action the current user (admin of the personal policy) didn't comment", async () => { + const adminPolicy = {...LHNTestUtils.getFakePolicy(), type: CONST.POLICY.TYPE.PERSONAL}; + + const report = {...LHNTestUtils.getFakeReport(), policyID: adminPolicy.id}; + const reportAction: ReportAction = { + ...LHNTestUtils.getFakeReportAction(), + actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT, + actorAccountID: currentUserAccountID + 1, + parentReportID: report.reportID, + message: [ + { + type: 'COMMENT', + html: 'hey', + text: 'hey', + isEdited: false, + whisperedTo: [], + isDeletedParentAction: false, + }, + ], + }; + + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report); + await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${adminPolicy.id}`, adminPolicy); + + expect(canDeleteReportAction(reportAction, report.reportID, undefined)).toBe(false); + }); }); describe('getPolicyExpenseChat', () => {