Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion src/libs/actions/Policy/Member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,8 @@
failureData.push(...(preferredExporterOnyxData.failureData ?? []));
}

const adminRoom = ReportUtils.getAllPolicyReports(policyID).find(ReportUtils.isAdminRoom);
const policyReports = ReportUtils.getAllPolicyReports(policyID);
const adminRoom = policyReports.find(ReportUtils.isAdminRoom);
if (adminRoom) {
const failureDataParticipants: Record<number, Participant | null> = {...adminRoom.participants};
const optimisticParticipants: Record<number, Participant | null> = {};
Expand Down Expand Up @@ -716,6 +717,48 @@
}
}

if (newRole === CONST.POLICY.ROLE.GUEST) {
for (const report of policyReports) {
if (!ReportUtils.isUserCreatedPolicyRoom(report) || report?.visibility !== CONST.REPORT.VISIBILITY.RESTRICTED) {
continue;
}
const reportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.reportID}`] ?? {};
const invitedAccountIDs = new Set<number>();
for (const action of Object.values(reportActions)) {
if (!ReportActionsUtils.isInviteMemberAction(action)) {

Check failure on line 728 in src/libs/actions/Policy/Member.ts

View workflow job for this annotation

GitHub Actions / typecheck

Property 'isInviteMemberAction' does not exist on type 'typeof import("/home/runner/_work/App/App/src/libs/ReportActionsUtils")'.

Check failure on line 728 in src/libs/actions/Policy/Member.ts

View workflow job for this annotation

GitHub Actions / typecheck

Property 'isInviteMemberAction' does not exist on type 'typeof import("/home/runner/_work/App/App/src/libs/ReportActionsUtils")'.

Check failure on line 728 in src/libs/actions/Policy/Member.ts

View workflow job for this annotation

GitHub Actions / typecheck

Property 'isInviteMemberAction' does not exist on type 'typeof import("/home/runner/_work/App/App/src/libs/ReportActionsUtils")'.
continue;
}
for (const targetAccountID of ReportActionsUtils.getOriginalMessage(action)?.targetAccountIDs ?? []) {

Check failure on line 731 in src/libs/actions/Policy/Member.ts

View workflow job for this annotation

GitHub Actions / typecheck

Property 'targetAccountIDs' does not exist on type 'OriginalMessageActionableMentionInviteToSubmitExpenseConfirmWhisper | OriginalMessageActionableMentionWhisper | ... 67 more ... | (OriginalMessagePolicyChangeLog & OriginalMessageSpendRuleChangeLog)'.

Check failure on line 731 in src/libs/actions/Policy/Member.ts

View workflow job for this annotation

GitHub Actions / typecheck

Property 'targetAccountIDs' does not exist on type 'OriginalMessageActionableMentionInviteToSubmitExpenseConfirmWhisper | OriginalMessageActionableMentionWhisper | ... 67 more ... | (OriginalMessagePolicyChangeLog & OriginalMessageSpendRuleChangeLog)'.

Check failure on line 731 in src/libs/actions/Policy/Member.ts

View workflow job for this annotation

GitHub Actions / typecheck

Property 'targetAccountIDs' does not exist on type 'OriginalMessageActionableMentionInviteToSubmitExpenseConfirmWhisper | OriginalMessageActionableMentionWhisper | ... 67 more ... | (OriginalMessagePolicyChangeLog & OriginalMessageSpendRuleChangeLog)'.
invitedAccountIDs.add(targetAccountID);
}
}
const optimisticParticipants: Record<number, Participant | null> = {};
const failureDataParticipants: Record<number, Participant | null> = {...report.participants};
for (const accountID of selectedMemberAccountIDs) {
if (!report.participants?.[accountID] || invitedAccountIDs.has(accountID)) {
continue;
}
optimisticParticipants[accountID] = null;
}
if (!isEmptyObject(optimisticParticipants)) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`,
value: {
participants: optimisticParticipants,
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`,
value: {
participants: failureDataParticipants,
},
});
}
}
}

return {optimisticData, successData, failureData, memberRoles};
}

Expand Down
35 changes: 35 additions & 0 deletions tests/actions/PolicyMemberTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,36 @@ describe('actions/PolicyMember', () => {
},
};

const selfJoinedRoom: Report = {
...createRandomReport(10, CONST.REPORT.CHAT_TYPE.POLICY_ROOM),
policyID: policy.id,
visibility: CONST.REPORT.VISIBILITY.RESTRICTED,
participants: {
[member.accountID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS},
},
};
const invitedRoom: Report = {
...createRandomReport(11, CONST.REPORT.CHAT_TYPE.POLICY_ROOM),
policyID: policy.id,
visibility: CONST.REPORT.VISIBILITY.RESTRICTED,
participants: {
[member.accountID]: {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS},
},
};

await Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${policy.id}`, policy);
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${selfJoinedRoom.reportID}`, selfJoinedRoom);
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${invitedRoom.reportID}`, invitedRoom);
await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${invitedRoom.reportID}`, {
inviteAction1: {
reportActionID: 'inviteAction1',
actionName: CONST.REPORT.ACTIONS.TYPE.ROOM_CHANGE_LOG.INVITE_TO_ROOM,
created: '2026-01-01 00:00:00.000',
originalMessage: {
targetAccountIDs: [member.accountID],
},
},
});
mockFetch?.pause?.();
Member.updateWorkspaceMembersRole(policy, [memberLogin], [member.accountID], CONST.POLICY.ROLE.GUEST);
await waitForBatchedUpdates();
Expand All @@ -124,6 +153,12 @@ describe('actions/PolicyMember', () => {
expect(optimisticPolicy?.employeeList?.[memberLogin]?.role).toBe(CONST.POLICY.ROLE.GUEST);
expect(optimisticPolicy?.employeeList?.[memberLogin]?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE);

const optimisticSelfJoinedRoom = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT}${selfJoinedRoom.reportID}`);
expect(optimisticSelfJoinedRoom?.participants?.[member.accountID]).toBeUndefined();

const optimisticInvitedRoom = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT}${invitedRoom.reportID}`);
expect(optimisticInvitedRoom?.participants?.[member.accountID]?.notificationPreference).toBe(CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS);

await mockFetch?.resume?.();
});

Expand Down
Loading