Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restricted requesting payments to self and splitting bills with self #4015

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
40 changes: 39 additions & 1 deletion src/libs/OptionsListUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ Onyx.connect({
callback: val => currentUserLogin = val && val.email,
});

let currentUser;
Onyx.connect({
key: ONYXKEYS.USER,
callback: val => currentUser = val,
});

let countryCodeByIP;
Onyx.connect({
key: ONYXKEYS.COUNTRY_CODE,
Expand Down Expand Up @@ -217,7 +223,8 @@ function createOption(personalDetailList, report, draftComments, {

// It doesn't make sense to provide a login in the case of a report with multiple participants since
// there isn't any one single login to refer to for a report.
login: !hasMultipleParticipants ? personalDetail.login : null,
// If single login is a mobile number, appending SMS domain
login: !hasMultipleParticipants ? addSMSDomainIfPhoneNumber(personalDetail.login) : null,
reportID: report ? report.reportID : null,
isUnread: report ? report.unreadActionCount > 0 : null,
hasDraftComment: _.size(reportDraftComment) > 0,
Expand Down Expand Up @@ -673,6 +680,36 @@ function getReportIcons(report, personalDetails) {
.map(item => item.avatar);
}

/**
* Returns the given userDetails is currentUser or not.
* @param {Object} userDetails
* @returns {Bool}
*/

function isCurrentUser(userDetails) {
if (!userDetails) {
// If userDetails is null or undefined
return false;
}

// If user login is mobile number, append sms domain if not appended already just a fail safe.
const userDetailsLogin = addSMSDomainIfPhoneNumber(userDetails.login);

// Initial check with currentUserLogin
let result = currentUserLogin.toLowerCase() === userDetailsLogin.toLowerCase();
const {loginList} = currentUser;
let index = 0;

// Checking userDetailsLogin against to current user login options.
while (index < loginList.length && !result) {
if (loginList[index].partnerUserID.toLowerCase() === userDetailsLogin.toLowerCase()) {
result = true;
}
index++;
}
return result;
}

export {
getSearchOptions,
getNewChatOptions,
Expand All @@ -685,4 +722,5 @@ export {
getIOUConfirmationOptionsFromParticipants,
getDefaultAvatar,
getReportIcons,
isCurrentUser,
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import _ from 'underscore';
import {getNewChatOptions} from '../../../../libs/OptionsListUtils';
import {getNewChatOptions, isCurrentUser} from '../../../../libs/OptionsListUtils';
import OptionsSelector from '../../../../components/OptionsSelector';
import ONYXKEYS from '../../../../ONYXKEYS';
import withLocalize, {withLocalizePropTypes} from '../../../../components/withLocalize';
Expand Down Expand Up @@ -90,7 +90,7 @@ class IOUParticipantsRequest extends Component {
indexOffset: 0,
});

if (this.state.userToInvite) {
if (this.state.userToInvite && !isCurrentUser(this.state.userToInvite)) {
sections.push({
undefined,
data: [this.state.userToInvite],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {withOnyx} from 'react-native-onyx';
import ONYXKEYS from '../../../../ONYXKEYS';
import styles from '../../../../styles/styles';
import OptionsSelector from '../../../../components/OptionsSelector';
import {getNewGroupOptions} from '../../../../libs/OptionsListUtils';
import {getNewGroupOptions, isCurrentUser} from '../../../../libs/OptionsListUtils';
import CONST from '../../../../CONST';
import withLocalize, {withLocalizePropTypes} from '../../../../components/withLocalize';
import compose from '../../../../libs/compose';
Expand Down Expand Up @@ -133,7 +133,7 @@ class IOUParticipantsSplit extends Component {
indexOffset: sections.reduce((prev, {data}) => prev + data.length, 0),
});

if (this.state.userToInvite) {
if (this.state.userToInvite && !isCurrentUser(this.state.userToInvite)) {
sections.push(({
undefined,
data: [this.state.userToInvite],
Expand Down