Skip to content

Implement dot notation email validation for gmail #302

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

Merged
merged 4 commits into from
May 10, 2019
Merged

Implement dot notation email validation for gmail #302

merged 4 commits into from
May 10, 2019

Conversation

mfikria
Copy link
Contributor

@mfikria mfikria commented May 8, 2019

No description provided.

Copy link
Contributor

@maxceem maxceem left a comment

Choose a reason for hiding this comment

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

@mfikria there is one moment I'd like to explain more here.

When we invite user by email we first don't know if a user with such email is already registered at Topcoder or no. For users who already registered on Topcoder we would create an invitation record which would include not only email, but also userId. For users who are not yet registered on Topcoder, we would create invitation record only with an email.

Here is how the code works.
First, we are looking in the system if a user with usch email is already registered in this line https://github.com/topcoder-platform/tc-project-service/blob/feature/fix-email-duplicated-invites/src/routes/projectMemberInvites/create.js#L59

And after we filter emails which we are inviting into two groups: emails which belong to users which already registered on Topcoder: https://github.com/topcoder-platform/tc-project-service/blob/feature/fix-email-duplicated-invites/src/routes/projectMemberInvites/create.js#L62-L68 and users who are not yet registered on Topcoder https://github.com/topcoder-platform/tc-project-service/blob/feature/fix-email-duplicated-invites/src/routes/projectMemberInvites/create.js#L70-L72

For users who are already registered, we are creating invites using their userId and email instead of only their emails, here https://github.com/topcoder-platform/tc-project-service/blob/feature/fix-email-duplicated-invites/src/routes/projectMemberInvites/create.js#L76-L83

For users who are not registered yet, we are creating invitation record sonly with email, which is done on these lines: https://github.com/topcoder-platform/tc-project-service/blob/feature/fix-email-duplicated-invites/src/routes/projectMemberInvites/create.js#L88-L94

So there are two separate logics when we filter emails.

  1. In these lines https://github.com/topcoder-platform/tc-project-service/blob/feature/fix-email-duplicated-invites/src/routes/projectMemberInvites/create.js#L70-L72 we are filter emails which we are inviting for users who are not yet registered on Tocpcoder. And here we should apply the same logic: compare emails case-insensitive. Gmail emails should be still treated different event if the difference is dot "." here.

  2. In these lines https://github.com/topcoder-platform/tc-project-service/blob/feature/fix-email-duplicated-invites/src/routes/projectMemberInvites/create.js#L70-L72 we are doing another thing.
    When we already have a list of emails nonExistentUserEmails of users who is not yet registered on Topcoder we should check if they alrady have invitaion record or no. And we would create an invitation for the users who are not yet registered only if they do not yet have invitation record.
    For this case, you've already implemented the fix to ignore letter case, and also now implementing ignoring differences in Gmail emails.

So there are two places which filter emails in different arrays for different reasons. In the latest changed these two places are merged into one, but the logic to filter unregistered users is lost now. So invitations which we put in the code to invitePromises would be duplicated for existent users. I know that code may be confusing here.
Please, let me know if the details from above help or there are any concerns.

@mfikria
Copy link
Contributor Author

mfikria commented May 8, 2019

@maxceem i've update the PR. Please review it again thanks!

Copy link
Contributor

@maxceem maxceem left a comment

Choose a reason for hiding this comment

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

Thank you for a quick update @mfikria

Looks good. But so far emails like WITHOUT-dot@gmail.com, and WITHadot@gmail.com also treated the same. So we can add any characters in between letters.

[recommended] It would be nice if compareEmail would be a pure function and doesn't depend on the global config variable. I mean if it gets all the data from the arguments only.

@maxceem
Copy link
Contributor

maxceem commented May 8, 2019

@mfikria I've also noticed that email with domains like this: WITHadot@gmail.fake.com are also treated the same to WITHadot@gmail.com.

Also, we don't have to disable eslint for the line:

const emailSplit = /(^[\w.+\-]+)@gmail\.(.*.)$/g.exec(email1); // eslint-disable-line

I think the resason for eslint error is that we don't have to escape - inside group [...].

@mfikria
Copy link
Contributor Author

mfikria commented May 9, 2019

@maxceem updated with:

  1. change regex validation
  2. update config for compareEmail function

Copy link
Contributor

@maxceem maxceem left a comment

Choose a reason for hiding this comment

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

Thanks @mfikria.

Email like WITHOUTadot@gmail.com (with a) is still treated the same as WITHOUTdot@gmail.com (without a).

Also, current regexp treats domains like gmail.fake.com as Gmail domains and also tries to apply the same Gmail rules. I've googled a bit, and looks like Gmail can only have two domains:

  • gmail.com
  • googlemail.com

So we should only apply these rules for emails in these two domains.

@maxceem
Copy link
Contributor

maxceem commented May 10, 2019

Noticed one more thing:

  • If we have an invitation with email test@GMAIL.com and try to invite email test@gmail.com - these emails would be treated differently.

The reason for this is that the method compareEmail is not symmetrical:

  • compareEmail(email1, email2) !== compareEmail(email2, email1) - sometimes

@mfikria
Copy link
Contributor Author

mfikria commented May 10, 2019

@maxceem i've updated the function:

  1. fix regex for additional dot with '.?' instead of '.?'
  2. only allow gmail.com and googlemail.com as email domains
  3. make email domain case insensitive

Copy link
Contributor

@maxceem maxceem left a comment

Choose a reason for hiding this comment

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

Works good now.
Thanks, @mfikria.

@maxceem maxceem merged commit 5d29438 into topcoder-platform:feature/fix-email-duplicated-invites May 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants