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 4 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 Phones',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
enterEmailOrPhone: 'Emails or Phones',
enterEmailOrPhone: 'Emails or phone numbers',

EmailOrPhonePlaceholder: 'Enter comma-separated emails or phones',
roryabraham marked this conversation as resolved.
Show resolved Hide resolved
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: 'Please ensure email or phone number is not a system User.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming back from the linked issue, the copy we landed on here is:

Sorry, you cannot invite chronos@expensify.com to a workspace.

Using whichever invalid email was found first.

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 sus colegas a tu espacio de trabajo.',
personalMessagePrompt: 'Agregar un mensaje personal (Opcional)',
enterEmailOrPhone: 'Email o teléfono',
enterEmailOrPhone: 'Correos electrónicos o teléfonos',
EmailOrPhonePlaceholder: 'Ingrese correos electrónicos o teléfonos separados 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: 'Asegúrese de que el correo electrónico o el número de teléfono no sea un usuario del sistema.',
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
15 changes: 15 additions & 0 deletions src/libs/reportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,20 @@ function isConciergeChatReport(report) {
&& report.participants[0] === CONST.EMAIL.CONCIERGE;
}

/**
* Whether a login is system email
*
* @param {String} login - user email
* @return {Boolean}
*/
function isSystemUser(login) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB but reportUtils feels like a weird place for this. Not sure I have a better suggestion for now unless we create userUtils or something?

return [
CONST.EMAIL.CONCIERGE,
CONST.EMAIL.CHRONOS,
CONST.EMAIL.RECEIPTS,
].includes(login);
}

export {
getReportParticipantsTitle,
isReportMessageAttachment,
Expand All @@ -163,4 +177,5 @@ export {
getDefaultRoomSubtitle,
isArchivedRoom,
isConciergeChatReport,
isSystemUser,
};
14 changes: 12 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/reportUtils';
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 isEnteredLoginSystemLogin = _.some(logins, login => isSystemUser(login));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const isEnteredLoginSystemLogin = _.some(logins, login => isSystemUser(login));
const didEnterSystemLogin = _.some(logins, login => isSystemUser(login));

if (isEnteredLoginSystemLogin) {
Growl.error(this.props.translate('workspace.invite.systemUserError'), 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,6 +125,7 @@ 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"
Expand Down