Skip to content

Commit 550b153

Browse files
committed
update regex validation and function parameters
1 parent 9f87f52 commit 550b153

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/routes/projectMemberInvites/create.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,15 @@ const addMemberValidations = {
3737
*
3838
* @returns {Boolean} true if two emails are same
3939
*/
40-
const compareEmail = (email1, email2, options = {}) => {
41-
const opts = _.assign({
42-
UNIQUE_GMAIL_VALIDATION: config.get('UNIQUE_GMAIL_VALIDATION'),
43-
}, options);
44-
if (opts.UNIQUE_GMAIL_VALIDATION) {
40+
const compareEmail = (email1, email2, options = { UNIQUE_GMAIL_VALIDATION: false }) => {
41+
if (options.UNIQUE_GMAIL_VALIDATION) {
4542
// email is gmail
46-
const emailSplit = /(^[\w.+\-]+)@gmail\.(.*.)$/g.exec(email1); // eslint-disable-line
43+
const emailSplit = /(^[\w.+-]+)(@gmail\..*.)$/g.exec(email1);
4744
if (emailSplit) {
4845
const address = emailSplit[1];
49-
const regex = new RegExp(_.toLower(address).replace('.', '').split('').join('.?'));
46+
const emailDomain = emailSplit[2];
47+
const regexAddress = _.toLower(address).replace('.', '').split('').join('\.?'); // eslint-disable-line no-useless-escape
48+
const regex = new RegExp(`${regexAddress}${emailDomain}`);
5049
return regex.test(_.toLower(email2));
5150
}
5251
}
@@ -110,7 +109,8 @@ const buildCreateInvitePromises = (req, invite, invites, data, failed) => {
110109

111110
// remove invites for users that are invited already
112111
_.remove(nonExistentUserEmails, email =>
113-
_.some(invites, i => compareEmail(i.email, email)));
112+
_.some(invites, i =>
113+
compareEmail(i.email, email, { UNIQUE_GMAIL_VALIDATION: config.get('UNIQUE_GMAIL_VALIDATION') })));
114114
nonExistentUserEmails.forEach((email) => {
115115
const dataNew = _.clone(data);
116116

0 commit comments

Comments
 (0)