Skip to content

Commit

Permalink
Merge pull request #31010 from DylanDylann/fix/30190-room-can-invite-…
Browse files Browse the repository at this point in the history
…valid-phone-account-multiple-times

Fix/30190: Duplicate phone number can be invited to room
  • Loading branch information
Beamanator authored Dec 15, 2023
2 parents e23eebe + 974f7dc commit f5696ff
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ function getOptions(
if (includePersonalDetails) {
// Next loop over all personal details removing any that are selectedUsers or recentChats
_.each(allPersonalDetailsOptions, (personalDetailOption) => {
if (_.some(optionsToExclude, (optionToExclude) => optionToExclude.login === personalDetailOption.login)) {
if (_.some(optionsToExclude, (optionToExclude) => optionToExclude.login === addSMSDomainIfPhoneNumber(personalDetailOption.login))) {
return;
}
const {searchText, participantsList, isChatRoom} = personalDetailOption;
Expand Down
10 changes: 8 additions & 2 deletions src/pages/RoomInvitePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ function RoomInvitePage(props) {
const [userToInvite, setUserToInvite] = useState(null);

// Any existing participants and Expensify emails should not be eligible for invitation
const excludedUsers = useMemo(() => [...PersonalDetailsUtils.getLoginsByAccountIDs(lodashGet(props.report, 'participantAccountIDs', [])), ...CONST.EXPENSIFY_EMAILS], [props.report]);
const excludedUsers = useMemo(
() =>
_.map([...PersonalDetailsUtils.getLoginsByAccountIDs(lodashGet(props.report, 'participantAccountIDs', [])), ...CONST.EXPENSIFY_EMAILS], (participant) =>
OptionsListUtils.addSMSDomainIfPhoneNumber(participant),
),
[props.report],
);

useEffect(() => {
const inviteOptions = OptionsListUtils.getMemberInviteOptions(props.personalDetails, props.betas, searchTerm, excludedUsers);
Expand Down Expand Up @@ -179,7 +185,7 @@ function RoomInvitePage(props) {
if (!userToInvite && CONST.EXPENSIFY_EMAILS.includes(searchValue)) {
return translate('messages.errorMessageInvalidEmail');
}
if (!userToInvite && excludedUsers.includes(searchValue)) {
if (!userToInvite && excludedUsers.includes(OptionsListUtils.addSMSDomainIfPhoneNumber(searchValue).toLowerCase())) {
return translate('messages.userIsAlreadyMember', {login: searchValue, name: reportName});
}
return OptionsListUtils.getHeaderMessage(personalDetails.length !== 0, Boolean(userToInvite), searchValue);
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceInvitePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function WorkspaceInvitePage(props) {
if (usersToInvite.length === 0 && CONST.EXPENSIFY_EMAILS.includes(searchValue)) {
return translate('messages.errorMessageInvalidEmail');
}
if (usersToInvite.length === 0 && excludedUsers.includes(searchValue)) {
if (usersToInvite.length === 0 && excludedUsers.includes(OptionsListUtils.addSMSDomainIfPhoneNumber(searchValue))) {
return translate('messages.userIsAlreadyMember', {login: searchValue, name: policyName});
}
return OptionsListUtils.getHeaderMessage(personalDetails.length !== 0, usersToInvite.length > 0, searchValue);
Expand Down

0 comments on commit f5696ff

Please sign in to comment.