Skip to content

Commit 20db842

Browse files
authored
Merge pull request Expensify#68030 from FitseTLT/fix-allowing-delete-action-for-admin-of-personal-policy
fix - User can delete MC Tests automated message
2 parents 1f36ec9 + 1f41071 commit 20db842

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/libs/ReportUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2586,7 +2586,7 @@ function canDeleteReportAction(reportAction: OnyxInputOrEntry<ReportAction>, rep
25862586
return false;
25872587
}
25882588

2589-
const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN && !isEmptyObject(report) && !isDM(report);
2589+
const isAdmin = policy?.type !== CONST.POLICY.TYPE.PERSONAL && policy?.role === CONST.POLICY.ROLE.ADMIN && !isEmptyObject(report);
25902590

25912591
return isActionOwner || isAdmin;
25922592
}

tests/unit/ReportUtilsTest.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3010,6 +3010,33 @@ describe('ReportUtils', () => {
30103010

30113011
expect(canDeleteReportAction(moneyRequestAction, '1', transaction)).toBe(true);
30123012
});
3013+
3014+
it("should return false for ADD_COMMENT report action the current user (admin of the personal policy) didn't comment", async () => {
3015+
const adminPolicy = {...LHNTestUtils.getFakePolicy(), type: CONST.POLICY.TYPE.PERSONAL};
3016+
3017+
const report = {...LHNTestUtils.getFakeReport(), policyID: adminPolicy.id};
3018+
const reportAction: ReportAction = {
3019+
...LHNTestUtils.getFakeReportAction(),
3020+
actionName: CONST.REPORT.ACTIONS.TYPE.ADD_COMMENT,
3021+
actorAccountID: currentUserAccountID + 1,
3022+
parentReportID: report.reportID,
3023+
message: [
3024+
{
3025+
type: 'COMMENT',
3026+
html: 'hey',
3027+
text: 'hey',
3028+
isEdited: false,
3029+
whisperedTo: [],
3030+
isDeletedParentAction: false,
3031+
},
3032+
],
3033+
};
3034+
3035+
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, report);
3036+
await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${adminPolicy.id}`, adminPolicy);
3037+
3038+
expect(canDeleteReportAction(reportAction, report.reportID, undefined)).toBe(false);
3039+
});
30133040
});
30143041

30153042
describe('getPolicyExpenseChat', () => {

0 commit comments

Comments
 (0)