Skip to content

Commit a8175e0

Browse files
authored
Merge pull request Expensify#67338 from dmkt9/fix/65479
Fix/65479 - Leave option is not shown for IOU invite
2 parents a5e8ba6 + f5a3f30 commit a8175e0

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

src/libs/ReportUtils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9818,6 +9818,10 @@ function canLeaveChat(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>, isRe
98189818
return true;
98199819
}
98209820

9821+
if (isMoneyRequestReport(report) && currentUserAccountID !== report?.managerID && currentUserAccountID !== report?.ownerAccountID && !isPolicyAdminPolicyUtils(policy)) {
9822+
return true;
9823+
}
9824+
98219825
if (isPublicRoom(report) && isAnonymousUserSession()) {
98229826
return false;
98239827
}

tests/unit/ReportUtilsTest.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4550,6 +4550,80 @@ describe('ReportUtils', () => {
45504550

45514551
expect(canLeaveChat(report, reportPolicy)).toBe(true);
45524552
});
4553+
4554+
describe('when the report is a money report', () => {
4555+
it('should return false for the owner of the report', async () => {
4556+
const report: Report = {
4557+
...createRandomReport(1),
4558+
chatType: undefined,
4559+
type: CONST.REPORT.TYPE.IOU,
4560+
ownerAccountID: currentUserAccountID,
4561+
};
4562+
4563+
await Onyx.set(ONYXKEYS.SESSION, {email: currentUserEmail, accountID: currentUserAccountID});
4564+
4565+
const reportPolicy: Policy = {
4566+
...createRandomPolicy(1),
4567+
role: CONST.POLICY.ROLE.USER,
4568+
};
4569+
4570+
expect(canLeaveChat(report, reportPolicy)).toBe(false);
4571+
});
4572+
4573+
it('should return false for the manager of the report', async () => {
4574+
const report: Report = {
4575+
...createRandomReport(1),
4576+
chatType: undefined,
4577+
type: CONST.REPORT.TYPE.IOU,
4578+
managerID: currentUserAccountID,
4579+
};
4580+
4581+
await Onyx.set(ONYXKEYS.SESSION, {email: currentUserEmail, accountID: currentUserAccountID});
4582+
4583+
const reportPolicy: Policy = {
4584+
...createRandomPolicy(1),
4585+
role: CONST.POLICY.ROLE.USER,
4586+
};
4587+
4588+
expect(canLeaveChat(report, reportPolicy)).toBe(false);
4589+
});
4590+
4591+
it('should return false for the admin of the policy', async () => {
4592+
const report: Report = {
4593+
...createRandomReport(1),
4594+
chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT,
4595+
type: CONST.REPORT.TYPE.EXPENSE,
4596+
};
4597+
4598+
await Onyx.set(ONYXKEYS.SESSION, {email: currentUserEmail, accountID: currentUserAccountID});
4599+
4600+
const reportPolicy: Policy = {
4601+
...createRandomPolicy(1),
4602+
role: CONST.POLICY.ROLE.ADMIN,
4603+
};
4604+
4605+
expect(canLeaveChat(report, reportPolicy)).toBe(false);
4606+
});
4607+
4608+
it('should return true for the invited user', async () => {
4609+
const report: Report = {
4610+
...createRandomReport(1),
4611+
chatType: undefined,
4612+
type: CONST.REPORT.TYPE.IOU,
4613+
ownerAccountID: 1,
4614+
managerID: 2,
4615+
};
4616+
4617+
await Onyx.set(ONYXKEYS.SESSION, {email: currentUserEmail, accountID: currentUserAccountID});
4618+
4619+
const reportPolicy: Policy = {
4620+
...createRandomPolicy(1),
4621+
role: CONST.POLICY.ROLE.USER,
4622+
};
4623+
4624+
expect(canLeaveChat(report, reportPolicy)).toBe(true);
4625+
});
4626+
});
45534627
});
45544628

45554629
describe('canJoinChat', () => {

0 commit comments

Comments
 (0)