From 369003b618706708bfa0aa4130dfe919ef5ecb4c Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 2 Sep 2021 17:11:05 -0600 Subject: [PATCH 01/14] refactor getDomainInfo for an array of logins --- src/libs/actions/User.js | 59 ++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index c215f83c9f05..69bc98e05547 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -31,6 +31,14 @@ Onyx.connect({ callback: val => currentlyViewedReportID = val || '', }); +let userLoginList; +Onyx.connect({ + key: ONYXKEYS.USER, + callback: (val) => { + userLoginList = lodashGet(val, 'loginList', []); + }, +}); + /** * Changes a password for a given account * @@ -199,7 +207,7 @@ function isBlockedFromConcierge(expiresAt) { } /** - * Fetch the public domain info for the current user. + * Fetch the public domain info for the current user (including secondary logins). * * This API is a bit weird in that it sometimes depends on information being cached in bedrock. * If the info for the domain is not in bedrock, then it creates an asynchronous bedrock job to gather domain info. @@ -209,36 +217,45 @@ function getDomainInfo() { // If this command fails, we'll retry again in 10 minutes, // arbitrarily chosen giving Bedrock time to resolve the ClearbitCheckPublicEmail job for this email. const RETRY_TIMEOUT = 600000; + let isFromPublicDomain = true; + + _.each(userLoginList, (userLogin) => { + isFromPublicDomain = isFromPublicDomain && _.contains(COMMON_PUBLIC_DOMAINS, userLogin.partnerUserID); + }); // First check list of common public domains - if (_.contains(COMMON_PUBLIC_DOMAINS, sessionEmail)) { + if (isFromPublicDomain) { Onyx.merge(ONYXKEYS.USER, {isFromPublicDomain: true}); return; } // If it is not a common public domain, check the API - API.User_IsFromPublicDomain({email: sessionEmail}) - .then((response) => { - if (response.jsonCode === 200) { - const {isFromPublicDomain} = response; - Onyx.merge(ONYXKEYS.USER, {isFromPublicDomain}); + _.reduce(userLoginList, (promise, userLogin) => { + return promise.then(() => { + API.User_IsFromPublicDomain({email: userLogin.partnerUserID}) + .then((response) => { + if (response.jsonCode === 200) { + isFromPublicDomain = isFromPublicDomain && response.isFromPublicDomain; + Onyx.merge(ONYXKEYS.USER, {isFromPublicDomain}); - // If the user is not on a public domain we'll want to know whether they are on a domain that has - // already provisioned the Expensify card - if (isFromPublicDomain) { - return; - } + // If the user is not on a public domain we'll want to know whether they are on a domain that has + // already provisioned the Expensify card + if (isFromPublicDomain) { + return; + } - API.User_IsUsingExpensifyCard() - .then(({isUsingExpensifyCard}) => { - Onyx.merge(ONYXKEYS.USER, {isUsingExpensifyCard}); - }); - } else { - // eslint-disable-next-line max-len - console.debug(`Command User_IsFromPublicDomain returned error code: ${response.jsonCode}. Most likely, this means that the domain ${Str.extractEmail(sessionEmail)} is not in the bedrock cache. Retrying in ${RETRY_TIMEOUT / 1000 / 60} minutes`); - setTimeout(getDomainInfo, RETRY_TIMEOUT); - } + API.User_IsUsingExpensifyCard() + .then(({isUsingExpensifyCard}) => { + Onyx.merge(ONYXKEYS.USER, {isUsingExpensifyCard}); + }); + } else { + // eslint-disable-next-line max-len + console.debug(`Command User_IsFromPublicDomain returned error code: ${response.jsonCode}. Most likely, this means that the domain ${Str.extractEmail(sessionEmail)} is not in the bedrock cache. Retrying in ${RETRY_TIMEOUT / 1000 / 60} minutes`); + setTimeout(getDomainInfo, RETRY_TIMEOUT); + } + }); }); + }, Promise.resolve()); } /** From 2364a5d1fc0976959d0a03840e7bca8106277f06 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Thu, 2 Sep 2021 17:16:12 -0600 Subject: [PATCH 02/14] fix some styles --- src/libs/actions/User.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 69bc98e05547..bc5e1d82a947 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -230,8 +230,8 @@ function getDomainInfo() { } // If it is not a common public domain, check the API - _.reduce(userLoginList, (promise, userLogin) => { - return promise.then(() => { + _.reduce(userLoginList, (promise, userLogin) => ( + promise.then(() => { API.User_IsFromPublicDomain({email: userLogin.partnerUserID}) .then((response) => { if (response.jsonCode === 200) { @@ -254,8 +254,7 @@ function getDomainInfo() { setTimeout(getDomainInfo, RETRY_TIMEOUT); } }); - }); - }, Promise.resolve()); + })), Promise.resolve()); } /** From 9e3c033a51b65eb4e94bfb683b51c016bfd5c729 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 3 Sep 2021 15:55:31 -0600 Subject: [PATCH 03/14] revert changes --- src/libs/actions/User.js | 54 +++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index bc5e1d82a947..069ae3b47976 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -207,54 +207,46 @@ function isBlockedFromConcierge(expiresAt) { } /** - * Fetch the public domain info for the current user (including secondary logins). + * Fetch the public domain info for the current user. * * This API is a bit weird in that it sometimes depends on information being cached in bedrock. * If the info for the domain is not in bedrock, then it creates an asynchronous bedrock job to gather domain info. * If that happens, this function will automatically retry itself in 10 minutes. */ -function getDomainInfo() { + function getDomainInfo() { // If this command fails, we'll retry again in 10 minutes, // arbitrarily chosen giving Bedrock time to resolve the ClearbitCheckPublicEmail job for this email. const RETRY_TIMEOUT = 600000; - let isFromPublicDomain = true; - - _.each(userLoginList, (userLogin) => { - isFromPublicDomain = isFromPublicDomain && _.contains(COMMON_PUBLIC_DOMAINS, userLogin.partnerUserID); - }); // First check list of common public domains - if (isFromPublicDomain) { + if (_.contains(COMMON_PUBLIC_DOMAINS, sessionEmail)) { Onyx.merge(ONYXKEYS.USER, {isFromPublicDomain: true}); return; } // If it is not a common public domain, check the API - _.reduce(userLoginList, (promise, userLogin) => ( - promise.then(() => { - API.User_IsFromPublicDomain({email: userLogin.partnerUserID}) - .then((response) => { - if (response.jsonCode === 200) { - isFromPublicDomain = isFromPublicDomain && response.isFromPublicDomain; - Onyx.merge(ONYXKEYS.USER, {isFromPublicDomain}); + API.User_IsFromPublicDomain({email: sessionEmail}) + .then((response) => { + if (response.jsonCode === 200) { + const {isFromPublicDomain} = response; + Onyx.merge(ONYXKEYS.USER, {isFromPublicDomain}); - // If the user is not on a public domain we'll want to know whether they are on a domain that has - // already provisioned the Expensify card - if (isFromPublicDomain) { - return; - } + // If the user is not on a public domain we'll want to know whether they are on a domain that has + // already provisioned the Expensify card + if (isFromPublicDomain) { + return; + } - API.User_IsUsingExpensifyCard() - .then(({isUsingExpensifyCard}) => { - Onyx.merge(ONYXKEYS.USER, {isUsingExpensifyCard}); - }); - } else { - // eslint-disable-next-line max-len - console.debug(`Command User_IsFromPublicDomain returned error code: ${response.jsonCode}. Most likely, this means that the domain ${Str.extractEmail(sessionEmail)} is not in the bedrock cache. Retrying in ${RETRY_TIMEOUT / 1000 / 60} minutes`); - setTimeout(getDomainInfo, RETRY_TIMEOUT); - } - }); - })), Promise.resolve()); + API.User_IsUsingExpensifyCard() + .then(({isUsingExpensifyCard}) => { + Onyx.merge(ONYXKEYS.USER, {isUsingExpensifyCard}); + }); + } else { + // eslint-disable-next-line max-len + console.debug(`Command User_IsFromPublicDomain returned error code: ${response.jsonCode}. Most likely, this means that the domain ${Str.extractEmail(sessionEmail)} is not in the bedrock cache. Retrying in ${RETRY_TIMEOUT / 1000 / 60} minutes`); + setTimeout(getDomainInfo, RETRY_TIMEOUT); + } + }); } /** From fc260d9bf81add6ce6fba0e13e87337310f2ccce Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 3 Sep 2021 15:56:23 -0600 Subject: [PATCH 04/14] remove space --- src/libs/actions/User.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 069ae3b47976..3c92891011ea 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -213,7 +213,7 @@ function isBlockedFromConcierge(expiresAt) { * If the info for the domain is not in bedrock, then it creates an asynchronous bedrock job to gather domain info. * If that happens, this function will automatically retry itself in 10 minutes. */ - function getDomainInfo() { +function getDomainInfo() { // If this command fails, we'll retry again in 10 minutes, // arbitrarily chosen giving Bedrock time to resolve the ClearbitCheckPublicEmail job for this email. const RETRY_TIMEOUT = 600000; From 33f5ef4e244e0edac26e308b57ff91067ea84e52 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 3 Sep 2021 16:54:07 -0600 Subject: [PATCH 05/14] filter common domains --- src/libs/actions/User.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 3c92891011ea..c8cac880ac31 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -35,7 +35,7 @@ let userLoginList; Onyx.connect({ key: ONYXKEYS.USER, callback: (val) => { - userLoginList = lodashGet(val, 'loginList', []); + userLoginList = _.map(lodashGet(val, 'loginList', []), userLogin => userLogin.partnerUserID); }, }); @@ -206,8 +206,15 @@ function isBlockedFromConcierge(expiresAt) { return moment().isBefore(moment(expiresAt), 'day'); } +function getDomainFromEmail(email) { + if (_.indexOf(email, '@') > -1) { + return email.split('@')[1]; + } + return ''; +} + /** - * Fetch the public domain info for the current user. + * Fetch the public domain info for the current user (includes secondary logins). * * This API is a bit weird in that it sometimes depends on information being cached in bedrock. * If the info for the domain is not in bedrock, then it creates an asynchronous bedrock job to gather domain info. @@ -218,14 +225,19 @@ function getDomainInfo() { // arbitrarily chosen giving Bedrock time to resolve the ClearbitCheckPublicEmail job for this email. const RETRY_TIMEOUT = 600000; - // First check list of common public domains - if (_.contains(COMMON_PUBLIC_DOMAINS, sessionEmail)) { + // First we filter out any domains that are in the list of common public domains + const emailList = _.filter(userLoginList, email => ( + !_.contains(COMMON_PUBLIC_DOMAINS, getDomainFromEmail(email)) + )); + + // If there are no emails left, we have a public domain + if (!emailList.length) { Onyx.merge(ONYXKEYS.USER, {isFromPublicDomain: true}); return; } // If it is not a common public domain, check the API - API.User_IsFromPublicDomain({email: sessionEmail}) + API.User_IsFromPublicDomain({email: sessionEmail}) // change to emailList .then((response) => { if (response.jsonCode === 200) { const {isFromPublicDomain} = response; From 8b7c1fbb558b743ef3089718c0b55c9f92fe05ab Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 7 Sep 2021 10:28:27 -0600 Subject: [PATCH 06/14] add getDomainFromEmail docs --- src/libs/actions/User.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index c8cac880ac31..5fb36d6cb380 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -206,6 +206,12 @@ function isBlockedFromConcierge(expiresAt) { return moment().isBefore(moment(expiresAt), 'day'); } +/** + * Checks if the expiresAt date of a user's ban is before right now + * + * @param {String} email + * @returns {String} + */ function getDomainFromEmail(email) { if (_.indexOf(email, '@') > -1) { return email.split('@')[1]; From 58ae918e5e775c2715309416dbf278975fe384d1 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Tue, 7 Sep 2021 11:11:31 -0600 Subject: [PATCH 07/14] change comment --- src/libs/actions/User.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 5fb36d6cb380..52e3471bcb40 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -242,7 +242,7 @@ function getDomainInfo() { return; } - // If it is not a common public domain, check the API + // Check the API for the remaining uncommon domains API.User_IsFromPublicDomain({email: sessionEmail}) // change to emailList .then((response) => { if (response.jsonCode === 200) { From 2ca78a02ebebfbfb0b6281445a7e7ebf0fcafd8f Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Wed, 8 Sep 2021 10:07:25 -0600 Subject: [PATCH 08/14] add emailList to API call --- src/libs/API.js | 4 ++-- src/libs/actions/User.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/API.js b/src/libs/API.js index 1f76c5cf9460..3fc72976745c 100644 --- a/src/libs/API.js +++ b/src/libs/API.js @@ -741,13 +741,13 @@ function User_GetBetas() { /** * @param {Object} parameters - * @param {String} parameters.email + * @param {Array} parameters.emailList * @param {Boolean} [parameters.requireCertainty] * @returns {Promise} */ function User_IsFromPublicDomain(parameters) { const commandName = 'User_IsFromPublicDomain'; - requireParameters(['email'], parameters, commandName); + requireParameters(['emailList'], parameters, commandName); return Network.post(commandName, { ...{requireCertainty: true}, ...parameters, diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 52e3471bcb40..fd40b990f9af 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -243,7 +243,7 @@ function getDomainInfo() { } // Check the API for the remaining uncommon domains - API.User_IsFromPublicDomain({email: sessionEmail}) // change to emailList + API.User_IsFromPublicDomain({emailList}) .then((response) => { if (response.jsonCode === 200) { const {isFromPublicDomain} = response; From d780736a4298112717036504242e6667c2b408e3 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 10 Sep 2021 11:00:30 -0600 Subject: [PATCH 09/14] fix race condition in getUserDetails and getDomainInfo --- .../Navigation/AppNavigator/AuthScreens.js | 1 - src/libs/actions/User.js | 136 +++++++++--------- 2 files changed, 67 insertions(+), 70 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 618b99be40b3..03a85becc18b 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -162,7 +162,6 @@ class AuthScreens extends React.Component { PersonalDetails.fetchPersonalDetails(); User.getUserDetails(); User.getBetas(); - User.getDomainInfo(); PersonalDetails.fetchLocalCurrency(); fetchAllReports(true, true); fetchCountryCodeByRequestIP(); diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index fd40b990f9af..8eecf5bc83c7 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -31,14 +31,6 @@ Onyx.connect({ callback: val => currentlyViewedReportID = val || '', }); -let userLoginList; -Onyx.connect({ - key: ONYXKEYS.USER, - callback: (val) => { - userLoginList = _.map(lodashGet(val, 'loginList', []), userLogin => userLogin.partnerUserID); - }, -}); - /** * Changes a password for a given account * @@ -71,6 +63,69 @@ function getBetas() { }); } +/** + * Checks if the expiresAt date of a user's ban is before right now + * + * @param {String} email + * @returns {String} + */ +function getDomainFromEmail(email) { + if (_.indexOf(email, '@') > -1) { + return email.split('@')[1]; + } + return ''; +} + +/** + * Fetch the public domain info for the current user (includes secondary logins). + * + * This API is a bit weird in that it sometimes depends on information being cached in bedrock. + * If the info for the domain is not in bedrock, then it creates an asynchronous bedrock job to gather domain info. + * If that happens, this function will automatically retry itself in 10 minutes. + * + * @param {String} loginList + */ +function getDomainInfo(loginList) { + // If this command fails, we'll retry again in 10 minutes, + // arbitrarily chosen giving Bedrock time to resolve the ClearbitCheckPublicEmail job for this email. + const RETRY_TIMEOUT = 600000; + + // First we filter out any domains that are in the list of common public domains + const emailList = _.filter(loginList, email => ( + !_.contains(COMMON_PUBLIC_DOMAINS, getDomainFromEmail(email)) + )); + + // If there are no emails left, we have a public domain + if (!emailList.length) { + Onyx.merge(ONYXKEYS.USER, {isFromPublicDomain: true}); + return; + } + + // Check the API for the remaining uncommon domains + API.User_IsFromPublicDomain({emailList}) + .then((response) => { + if (response.jsonCode === 200) { + const {isFromPublicDomain} = response; + Onyx.merge(ONYXKEYS.USER, {isFromPublicDomain}); + + // If the user is not on a public domain we'll want to know whether they are on a domain that has + // already provisioned the Expensify card + if (isFromPublicDomain) { + return; + } + + API.User_IsUsingExpensifyCard() + .then(({isUsingExpensifyCard}) => { + Onyx.merge(ONYXKEYS.USER, {isUsingExpensifyCard}); + }); + } else { + // eslint-disable-next-line max-len + console.debug(`Command User_IsFromPublicDomain returned error code: ${response.jsonCode}. Most likely, this means that the domain ${Str.extractEmail(sessionEmail)} is not in the bedrock cache. Retrying in ${RETRY_TIMEOUT / 1000 / 60} minutes`); + setTimeout(() => getDomainInfo(loginList), RETRY_TIMEOUT); + } + }); +} + /** * Fetches the data needed for user settings */ @@ -92,6 +147,10 @@ function getUserDetails() { // Update the blockedFromConcierge NVP const blockedFromConcierge = lodashGet(response, `nameValuePairs.${CONST.NVP.BLOCKED_FROM_CONCIERGE}`, {}); Onyx.merge(ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE, blockedFromConcierge); + + // Get domainInfo for user + const emailList = _.map(loginList, userLogin => userLogin.partnerUserID); + getDomainInfo(emailList); }); } @@ -206,67 +265,6 @@ function isBlockedFromConcierge(expiresAt) { return moment().isBefore(moment(expiresAt), 'day'); } -/** - * Checks if the expiresAt date of a user's ban is before right now - * - * @param {String} email - * @returns {String} - */ -function getDomainFromEmail(email) { - if (_.indexOf(email, '@') > -1) { - return email.split('@')[1]; - } - return ''; -} - -/** - * Fetch the public domain info for the current user (includes secondary logins). - * - * This API is a bit weird in that it sometimes depends on information being cached in bedrock. - * If the info for the domain is not in bedrock, then it creates an asynchronous bedrock job to gather domain info. - * If that happens, this function will automatically retry itself in 10 minutes. - */ -function getDomainInfo() { - // If this command fails, we'll retry again in 10 minutes, - // arbitrarily chosen giving Bedrock time to resolve the ClearbitCheckPublicEmail job for this email. - const RETRY_TIMEOUT = 600000; - - // First we filter out any domains that are in the list of common public domains - const emailList = _.filter(userLoginList, email => ( - !_.contains(COMMON_PUBLIC_DOMAINS, getDomainFromEmail(email)) - )); - - // If there are no emails left, we have a public domain - if (!emailList.length) { - Onyx.merge(ONYXKEYS.USER, {isFromPublicDomain: true}); - return; - } - - // Check the API for the remaining uncommon domains - API.User_IsFromPublicDomain({emailList}) - .then((response) => { - if (response.jsonCode === 200) { - const {isFromPublicDomain} = response; - Onyx.merge(ONYXKEYS.USER, {isFromPublicDomain}); - - // If the user is not on a public domain we'll want to know whether they are on a domain that has - // already provisioned the Expensify card - if (isFromPublicDomain) { - return; - } - - API.User_IsUsingExpensifyCard() - .then(({isUsingExpensifyCard}) => { - Onyx.merge(ONYXKEYS.USER, {isUsingExpensifyCard}); - }); - } else { - // eslint-disable-next-line max-len - console.debug(`Command User_IsFromPublicDomain returned error code: ${response.jsonCode}. Most likely, this means that the domain ${Str.extractEmail(sessionEmail)} is not in the bedrock cache. Retrying in ${RETRY_TIMEOUT / 1000 / 60} minutes`); - setTimeout(getDomainInfo, RETRY_TIMEOUT); - } - }); -} - /** * Initialize our pusher subscription to listen for user changes */ From 24f79f65c3e0290a6aeb2a85701540d4a0c05d85 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 10 Sep 2021 11:11:42 -0600 Subject: [PATCH 10/14] move getDomainFromEmail --- src/libs/actions/User.js | 14 +------------- src/libs/getDomainFromEmail.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 src/libs/getDomainFromEmail.js diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 8eecf5bc83c7..85c8257b13a5 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -12,6 +12,7 @@ import ROUTES from '../../ROUTES'; import * as Pusher from '../Pusher/pusher'; import Log from '../Log'; import NetworkConnection from '../NetworkConnection'; +import getDomainFromEmail from '../getDomainFromEmail'; let sessionAuthToken = ''; let sessionEmail = ''; @@ -63,19 +64,6 @@ function getBetas() { }); } -/** - * Checks if the expiresAt date of a user's ban is before right now - * - * @param {String} email - * @returns {String} - */ -function getDomainFromEmail(email) { - if (_.indexOf(email, '@') > -1) { - return email.split('@')[1]; - } - return ''; -} - /** * Fetch the public domain info for the current user (includes secondary logins). * diff --git a/src/libs/getDomainFromEmail.js b/src/libs/getDomainFromEmail.js new file mode 100644 index 000000000000..f94f59251c65 --- /dev/null +++ b/src/libs/getDomainFromEmail.js @@ -0,0 +1,16 @@ +import _ from 'underscore'; + +/** + * Checks if the expiresAt date of a user's ban is before right now + * + * @param {String} email + * @returns {String} + */ + function getDomainFromEmail(email) { + if (_.indexOf(email, '@') > -1) { + return email.split('@')[1]; + } + return ''; +} + +export default getDomainFromEmail; \ No newline at end of file From 917c4f7ea0ef3be92289521886e251cafa026aa0 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 10 Sep 2021 11:12:08 -0600 Subject: [PATCH 11/14] fix style --- src/libs/getDomainFromEmail.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/getDomainFromEmail.js b/src/libs/getDomainFromEmail.js index f94f59251c65..f061c7029023 100644 --- a/src/libs/getDomainFromEmail.js +++ b/src/libs/getDomainFromEmail.js @@ -6,11 +6,11 @@ import _ from 'underscore'; * @param {String} email * @returns {String} */ - function getDomainFromEmail(email) { +function getDomainFromEmail(email) { if (_.indexOf(email, '@') > -1) { return email.split('@')[1]; } return ''; } -export default getDomainFromEmail; \ No newline at end of file +export default getDomainFromEmail; From 4283ec309344b51714ce3c2c460f5de795e418a3 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 10 Sep 2021 14:12:11 -0600 Subject: [PATCH 12/14] resolve conflicts --- src/libs/actions/User.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index 463ec705934e..fb7687215a51 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -12,12 +12,9 @@ import ROUTES from '../../ROUTES'; import * as Pusher from '../Pusher/pusher'; import Log from '../Log'; import NetworkConnection from '../NetworkConnection'; -<<<<<<< HEAD import getDomainFromEmail from '../getDomainFromEmail'; -======= import NameValuePair from './NameValuePair'; import getSkinToneEmojiFromIndex from '../../pages/home/report/EmojiPickerMenu/getSkinToneEmojiFromIndex'; ->>>>>>> main let sessionAuthToken = ''; let sessionEmail = ''; From a50ab751537a168ed90b0449f2c58e426c173cfe Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Fri, 10 Sep 2021 17:29:46 -0600 Subject: [PATCH 13/14] add pusher event listener for validateAccount --- src/libs/Pusher/EventType.js | 1 + src/libs/actions/Report.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/libs/Pusher/EventType.js b/src/libs/Pusher/EventType.js index 713f69b5c128..357ebd7825a6 100644 --- a/src/libs/Pusher/EventType.js +++ b/src/libs/Pusher/EventType.js @@ -7,4 +7,5 @@ export default { REPORT_COMMENT_EDIT: 'reportCommentEdit', REPORT_TOGGLE_PINNED: 'reportTogglePinned', PREFERRED_LOCALE: 'preferredLocale', + ACCOUNT_VALIDATED: 'accountValidated', }; diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index edaf0f346a2e..7b79dfb517f7 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -660,6 +660,15 @@ function updateReportPinnedState(reportID, isPinned) { Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {isPinned}); } +/** + * Updates isFromPublicDomain in Onyx. + * + * @param {Boolean} isFromPublicDomain + */ +function updateIsFromPublicDomain(isFromPublicDomain) { + Onyx.merge(ONYXKEYS.USER, {isFromPublicDomain}); +} + /** * Get the private pusher channel name for a Report. * @@ -741,6 +750,26 @@ function subscribeToUserEvents() { {error, pusherChannelName, eventName: Pusher.TYPE.REPORT_TOGGLE_PINNED}, ); }); + + // Live-update if a user has private domains listed as primary or secondary logins. + Pusher.subscribe(pusherChannelName, Pusher.TYPE.ACCOUNT_VALIDATED, (pushJSON) => { + Log.info( + `[Report] Handled ${Pusher.TYPE.ACCOUNT_VALIDATED} event sent by Pusher`, + false, + {isFromPublicDomain: pushJSON.isFromPublicDomain}, + ); + updateIsFromPublicDomain(pushJSON.isFromPublicDomain); + }, false, + () => { + NetworkConnection.triggerReconnectionCallbacks('pusher re-subscribed to private user channel'); + }) + .catch((error) => { + Log.info( + '[Report] Failed to subscribe to Pusher channel', + false, + {error, pusherChannelName, eventName: Pusher.TYPE.ACCOUNT_VALIDATED}, + ); + }); } /** From 6b156114e9b1a1871ef58ad34793be03afa3fd02 Mon Sep 17 00:00:00 2001 From: Carlos Martins Date: Mon, 13 Sep 2021 17:30:47 -0600 Subject: [PATCH 14/14] address change requests --- src/libs/API.js | 2 +- src/libs/actions/Report.js | 4 ++-- src/libs/actions/User.js | 5 ++--- src/libs/getDomainFromEmail.js | 16 ---------------- 4 files changed, 5 insertions(+), 22 deletions(-) delete mode 100644 src/libs/getDomainFromEmail.js diff --git a/src/libs/API.js b/src/libs/API.js index 3fc72976745c..1ff70319120c 100644 --- a/src/libs/API.js +++ b/src/libs/API.js @@ -741,7 +741,7 @@ function User_GetBetas() { /** * @param {Object} parameters - * @param {Array} parameters.emailList + * @param {String} parameters.emailList * @param {Boolean} [parameters.requireCertainty] * @returns {Promise} */ diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 7b79dfb517f7..537060d0b8d2 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -665,7 +665,7 @@ function updateReportPinnedState(reportID, isPinned) { * * @param {Boolean} isFromPublicDomain */ -function updateIsFromPublicDomain(isFromPublicDomain) { +function setIsFromPublicDomain(isFromPublicDomain) { Onyx.merge(ONYXKEYS.USER, {isFromPublicDomain}); } @@ -758,7 +758,7 @@ function subscribeToUserEvents() { false, {isFromPublicDomain: pushJSON.isFromPublicDomain}, ); - updateIsFromPublicDomain(pushJSON.isFromPublicDomain); + setIsFromPublicDomain(pushJSON.isFromPublicDomain); }, false, () => { NetworkConnection.triggerReconnectionCallbacks('pusher re-subscribed to private user channel'); diff --git a/src/libs/actions/User.js b/src/libs/actions/User.js index fb7687215a51..14119110d449 100644 --- a/src/libs/actions/User.js +++ b/src/libs/actions/User.js @@ -12,7 +12,6 @@ import ROUTES from '../../ROUTES'; import * as Pusher from '../Pusher/pusher'; import Log from '../Log'; import NetworkConnection from '../NetworkConnection'; -import getDomainFromEmail from '../getDomainFromEmail'; import NameValuePair from './NameValuePair'; import getSkinToneEmojiFromIndex from '../../pages/home/report/EmojiPickerMenu/getSkinToneEmojiFromIndex'; @@ -82,7 +81,7 @@ function getDomainInfo(loginList) { // First we filter out any domains that are in the list of common public domains const emailList = _.filter(loginList, email => ( - !_.contains(COMMON_PUBLIC_DOMAINS, getDomainFromEmail(email)) + !_.contains(COMMON_PUBLIC_DOMAINS, Str.extractEmailDomain(email)) )); // If there are no emails left, we have a public domain @@ -92,7 +91,7 @@ function getDomainInfo(loginList) { } // Check the API for the remaining uncommon domains - API.User_IsFromPublicDomain({emailList}) + API.User_IsFromPublicDomain({emailList: emailList.join(',')}) .then((response) => { if (response.jsonCode === 200) { const {isFromPublicDomain} = response; diff --git a/src/libs/getDomainFromEmail.js b/src/libs/getDomainFromEmail.js deleted file mode 100644 index f061c7029023..000000000000 --- a/src/libs/getDomainFromEmail.js +++ /dev/null @@ -1,16 +0,0 @@ -import _ from 'underscore'; - -/** - * Checks if the expiresAt date of a user's ban is before right now - * - * @param {String} email - * @returns {String} - */ -function getDomainFromEmail(email) { - if (_.indexOf(email, '@') > -1) { - return email.split('@')[1]; - } - return ''; -} - -export default getDomainFromEmail;