Skip to content

Commit 1f41071

Browse files
committed
fix canDeleteReportAction to check user is not admin of personal policy
1 parent c08a31b commit 1f41071

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
@@ -2550,7 +2550,7 @@ function canDeleteReportAction(reportAction: OnyxInputOrEntry<ReportAction>, rep
25502550
return false;
25512551
}
25522552

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

25552555
return isActionOwner || isAdmin;
25562556
}

tests/unit/ReportUtilsTest.ts

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

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

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

0 commit comments

Comments
 (0)