Skip to content

Commit b27c424

Browse files
committed
when validating if user has been already invited by the email, check emails case-insensetive way
1 parent 5b5567c commit b27c424

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

src/components/TeamManagement/ProjectManagementDialog.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Modal from 'react-modal'
66
import XMarkIcon from '../../assets/icons/icon-x-mark.svg'
77
import Avatar from 'appirio-tech-react-components/components/Avatar/Avatar'
88
import {getAvatarResized} from '../../helpers/tcHelpers'
9+
import { compareEmail } from '../../helpers/utils'
910
import AutocompleteInputContainer from './AutocompleteInputContainer'
1011

1112
class ProjectManagementDialog extends React.Component {
@@ -39,8 +40,8 @@ class ProjectManagementDialog extends React.Component {
3940
const { projectTeamInvites, members, topcoderTeamInvites } = this.props
4041

4142
const present = _.some(selectedMembers, (selectedMember) => (
42-
this.isSelectedMemberAlreadyInvited(members, selectedMember)
43-
|| this.isSelectedMemberAlreadyInvited(topcoderTeamInvites, selectedMember)
43+
this.isSelectedMemberAlreadyInvited(members, selectedMember)
44+
|| this.isSelectedMemberAlreadyInvited(topcoderTeamInvites, selectedMember)
4445
|| this.isSelectedMemberAlreadyInvited(projectTeamInvites, selectedMember)
4546
))
4647

@@ -55,7 +56,7 @@ class ProjectManagementDialog extends React.Component {
5556

5657
isSelectedMemberAlreadyInvited(projectTeamInvites = [], selectedMember) {
5758
return !!projectTeamInvites.find((invite) => (
58-
(invite.email && invite.email === selectedMember.label) ||
59+
(invite.email && compareEmail(invite.email, selectedMember.label)) ||
5960
(invite.userId && this.resolveUserHandle(invite.userId) === selectedMember.label)
6061
))
6162
}

src/components/TeamManagement/TopcoderManagementDialog.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import AutocompleteInputContainer from './AutocompleteInputContainer'
1313
import {PROJECT_MEMBER_INVITE_STATUS_REQUESTED, PROJECT_MEMBER_INVITE_STATUS_PENDING} from '../../config/constants'
1414
import PERMISSIONS from '../../config/permissions'
1515
import {checkPermission} from '../../helpers/permissions'
16+
import { compareEmail } from '../../helpers/utils'
1617

1718
class TopcoderManagementDialog extends React.Component {
1819
constructor(props) {
@@ -67,8 +68,8 @@ class TopcoderManagementDialog extends React.Component {
6768
const { projectTeamInvites, members, topcoderTeamInvites } = this.props
6869

6970
const present = _.some(selectedMembers, (selectedMember) => (
70-
this.isSelectedMemberAlreadyInvited(members, selectedMember)
71-
|| this.isSelectedMemberAlreadyInvited(topcoderTeamInvites, selectedMember)
71+
this.isSelectedMemberAlreadyInvited(members, selectedMember)
72+
|| this.isSelectedMemberAlreadyInvited(topcoderTeamInvites, selectedMember)
7273
|| this.isSelectedMemberAlreadyInvited(projectTeamInvites, selectedMember)
7374
))
7475

@@ -98,7 +99,7 @@ class TopcoderManagementDialog extends React.Component {
9899

99100
isSelectedMemberAlreadyInvited(topcoderTeamInvites = [], selectedMember) {
100101
return !!topcoderTeamInvites.find((invite) => (
101-
(invite.email && invite.email === selectedMember.label) ||
102+
(invite.email && compareEmail(invite.email, selectedMember.label)) ||
102103
(invite.userId && this.resolveUserHandle(invite.userId) === selectedMember.label)
103104
))
104105
}

src/helpers/utils.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,27 @@ export function difference(object, base) {
2020
}
2121
return changes(object, base)
2222
}
23+
24+
/**
25+
* Helper method to check the uniqueness of two emails
26+
*
27+
* @param {String} email1 first email to compare
28+
* @param {String} email2 second email to compare
29+
* @param {Object} options the options
30+
*
31+
* @returns {Boolean} true if two emails are same
32+
*/
33+
export const compareEmail = (email1, email2, options = { UNIQUE_GMAIL_VALIDATION: false }) => {
34+
if (options.UNIQUE_GMAIL_VALIDATION) {
35+
// email is gmail
36+
const emailSplit = /(^[\w.+-]+)(@gmail\.com|@googlemail\.com)$/g.exec(_.toLower(email1))
37+
if (emailSplit) {
38+
const address = emailSplit[1].replace('.', '')
39+
const emailDomain = emailSplit[2].replace('.', '\\.')
40+
const regexAddress = address.split('').join('\\.?')
41+
const regex = new RegExp(`${regexAddress}${emailDomain}`)
42+
return regex.test(_.toLower(email2))
43+
}
44+
}
45+
return _.toLower(email1) === _.toLower(email2)
46+
}

0 commit comments

Comments
 (0)