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

Block system user from Inviting into Workspace #4781

Merged
merged 8 commits into from
Aug 26, 2021
Merged
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
6 changes: 4 additions & 2 deletions src/languages/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -588,12 +588,14 @@ export default {
},
invite: {
invitePeople: 'Invite People',
invitePeoplePrompt: 'Invite a colleague to your workspace.',
invitePeoplePrompt: 'Invite colleagues to your workspace.',
personalMessagePrompt: 'Add a Personal Message (Optional)',
enterEmailOrPhone: 'Email or Phone',
enterEmailOrPhone: 'Emails or Phone Numbers',
EmailOrPhonePlaceholder: 'Enter comma-separated list of emails or phone numbers',
pleaseEnterValidLogin: 'Please ensure the email or phone number is valid (e.g. +15005550006).',
pleaseEnterUniqueLogin: 'That user is already a member of this workspace.',
genericFailureMessage: 'An error occurred inviting the user to the workspace, please try again.',
systemUserError: ({email}) => `Sorry, you cannot invite ${email} to a workspace.`,
welcomeNote: ({workspaceName}) => `You have been invited to the ${workspaceName} Workspace! Download the Expensify mobile App to start tracking your expenses.`,
},
editor: {
Expand Down
6 changes: 4 additions & 2 deletions src/languages/es.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,12 +590,14 @@ export default {
},
invite: {
invitePeople: 'Invitar a la gente',
invitePeoplePrompt: 'Invita a un colega a tu espacio de trabajo.',
invitePeoplePrompt: 'Invita a tus compañeros a tu espacio de trabajo.',
personalMessagePrompt: 'Agregar un mensaje personal (Opcional)',
enterEmailOrPhone: 'Email o teléfono',
enterEmailOrPhone: 'Correos electrónicos o números de teléfono',
EmailOrPhonePlaceholder: 'Introduce una lista de correos electrónicos o números de teléfono separado por comas',
pleaseEnterValidLogin: 'Asegúrese de que el correo electrónico o el número de teléfono sean válidos (e.g. +15005550006).',
pleaseEnterUniqueLogin: 'Ese usuario ya es miembro de este espacio de trabajo.',
genericFailureMessage: 'Se produjo un error al invitar al usuario al espacio de trabajo. Vuelva a intentarlo..',
systemUserError: ({email}) => `Lo sentimos, no puedes invitar a ${email} a un espacio de trabajo.`,
welcomeNote: ({workspaceName}) => `¡Has sido invitado a la ${workspaceName} Espacio de trabajo! Descargue la aplicación móvil Expensify para comenzar a rastrear sus gastos.`,
},
editor: {
Expand Down
20 changes: 20 additions & 0 deletions src/libs/userUtils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import CONST from '../CONST';

/**
* Whether a login is system email
*
* @param {String} login - user email
* @return {Boolean}
*/
function isSystemUser(login) {
return [
CONST.EMAIL.CONCIERGE,
CONST.EMAIL.CHRONOS,
CONST.EMAIL.RECEIPTS,
].includes(login);
}

export {
// eslint-disable-next-line import/prefer-default-export
isSystemUser,
};
16 changes: 14 additions & 2 deletions src/pages/workspace/WorkspaceInvitePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import Growl from '../../libs/Growl';
import ExpensiTextInput from '../../components/ExpensiTextInput';
import FixedFooter from '../../components/FixedFooter';
import KeyboardAvoidingView from '../../components/KeyboardAvoidingView';
import {isSystemUser} from '../../libs/userUtils';
import {addSMSDomainIfPhoneNumber} from '../../libs/OptionsListUtils';

const propTypes = {
...withLocalizePropTypes,
Expand Down Expand Up @@ -88,9 +90,16 @@ class WorkspaceInvitePage extends React.Component {
Growl.error(this.props.translate('workspace.invite.pleaseEnterValidLogin'), 5000);
return;
}

const foundSystemLogin = _.find(logins, login => isSystemUser(login));
if (foundSystemLogin) {
Growl.error(this.props.translate('workspace.invite.systemUserError', {email: foundSystemLogin}), 5000);
return;
}

const policyEmployeeList = lodashGet(this.props, 'policy.employeeList', []);
const AreLoginsDuplicate = _.every(logins, login => _.contains(policyEmployeeList, login));
if (AreLoginsDuplicate) {
const areLoginsDuplicate = _.some(logins, login => _.contains(policyEmployeeList, addSMSDomainIfPhoneNumber(login)));
if (areLoginsDuplicate) {
Growl.error(this.props.translate('workspace.invite.pleaseEnterUniqueLogin'), 5000);
return;
}
Expand All @@ -116,9 +125,12 @@ class WorkspaceInvitePage extends React.Component {
<ExpensiTextInput
ref={el => this.emailOrPhoneInputRef = el}
label={this.props.translate('workspace.invite.enterEmailOrPhone')}
placeholder={this.props.translate('workspace.invite.EmailOrPhonePlaceholder')}
autoCompleteType="email"
autoCorrect={false}
autoCapitalize="none"
multiline
numberOfLines={2}
value={this.state.userLogins}
onChangeText={text => this.setState({userLogins: text})}
/>
Expand Down