From 8a480fcb13478a4c98afd0977aa285e89e261085 Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Thu, 8 Jun 2023 14:05:18 -0400 Subject: [PATCH 1/2] Get email domains from personalDetails --- src/libs/ReportUtils.js | 43 ++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 46ed72d37f23..4c02e877dfe1 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -354,15 +354,6 @@ function getBankAccountRoute(report) { return isPolicyExpenseChat(report) ? ROUTES.getBankAccountRoute('', report.policyID) : ROUTES.SETTINGS_ADD_BANK_ACCOUNT; } -/** - * Returns true if there are any guides accounts (team.expensify.com) in emails - * @param {Array} emails - * @returns {Boolean} - */ -function hasExpensifyGuidesEmails(emails) { - return _.some(emails, (email) => Str.extractEmailDomain(email) === CONST.EMAIL.GUIDES_DOMAIN); -} - /** * Only returns true if this is our main 1:1 DM report with Concierge * @@ -400,11 +391,9 @@ function findLastAccessedReport(reports, ignoreDomainRooms, policies, isFirstTim // We allow public announce rooms, admins, and announce rooms through since we bypass the default rooms beta for them. // Check where ReportUtils.findLastAccessedReport is called in MainDrawerNavigator.js for more context. // Domain rooms are now the only type of default room that are on the defaultRooms beta. - // TODO: migrate to report.participantAccountIDs later - not sure how we'll determine if a list of account IDs - // includes an expensify guide account ID :O sortedReports = _.filter( sortedReports, - (report) => !isDomainRoom(report) || getPolicyType(report, policies) === CONST.POLICY.TYPE.FREE || hasExpensifyGuidesEmails(lodashGet(report, ['participants'], [])), + (report) => !isDomainRoom(report) || getPolicyType(report, policies) === CONST.POLICY.TYPE.FREE || hasExpensifyGuidesEmails(lodashGet(report, ['participantAccountIDs'], [])), ); } @@ -631,13 +620,29 @@ function hasAutomatedExpensifyAccountIDs(accountIDs) { } /** - * Returns true if there are any Expensify accounts (i.e. with domain 'expensify.com') in the set of emails. + * Returns true if there are any Expensify accounts (i.e. with domain 'expensify.com') in the set of accountIDs + * by cross-referencing the accountIDs with personalDetails. * - * @param {Array} emails + * @param {Array} accountIDs * @return {Boolean} */ -function hasExpensifyEmails(emails) { - return _.some(emails, (email) => Str.extractEmailDomain(email) === CONST.EXPENSIFY_PARTNER_NAME); +function hasExpensifyEmails(accountIDs) { + return _.some(accountIDs, (accountID) => + Str.extractEmailDomain(lodashGet(allPersonalDetails, [accountID, 'login'], '')) === CONST.EXPENSIFY_PARTNER_NAME + ); +} + +/** + * Returns true if there are any guides accounts (team.expensify.com) in a list of accountIDs + * by cross-referencing the accountIDs with personalDetails since guides that are participants + * of the user's chats should have their personal details in Onyx. + * @param {Array} accountIDs + * @returns {Boolean} + */ +function hasExpensifyGuidesEmails(accountIDs) { + return _.some(accountIDs, (accountID) => + Str.extractEmailDomain(lodashGet(allPersonalDetails, [accountID, 'login'], '')) === CONST.EMAIL.GUIDES_DOMAIN + ); } /** @@ -1813,14 +1818,12 @@ function canSeeDefaultRoom(report, policies, betas) { } // Include domain rooms with Partner Managers (Expensify accounts) in them for accounts that are on a domain with an Approved Accountant - // TODO: figure out how we can determine accountIDs of "expensify emails" - if (isDomainRoom(report) && doesDomainHaveApprovedAccountant && hasExpensifyEmails(lodashGet(report, ['participants'], []))) { + if (isDomainRoom(report) && doesDomainHaveApprovedAccountant && hasExpensifyEmails(lodashGet(report, ['participantAccountIDs'], []))) { return true; } // If the room has an assigned guide, it can be seen. - // TODO: figure out how we can determine accountIDs of "expensify emails" - if (hasExpensifyGuidesEmails(lodashGet(report, ['participants'], []))) { + if (hasExpensifyGuidesEmails(lodashGet(report, ['participantAccountIDs'], []))) { return true; } From b376e23e4e17cba976707ec8c21f66fed8e3f96a Mon Sep 17 00:00:00 2001 From: Alex Beaman Date: Mon, 12 Jun 2023 13:50:17 +0300 Subject: [PATCH 2/2] lint & prettier updates --- src/libs/PolicyUtils.js | 1 - src/libs/ReportUtils.js | 48 ++++++++++------------ src/pages/workspace/WorkspaceInvitePage.js | 4 +- 3 files changed, 24 insertions(+), 29 deletions(-) diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js index 9af087232037..22b5d8635f72 100644 --- a/src/libs/PolicyUtils.js +++ b/src/libs/PolicyUtils.js @@ -120,7 +120,6 @@ function getClientPolicyMemberEmailsToAccountIDs(policyMembers, personalDetails) return; } memberEmailsToAccountIDs[personalDetail.login] = accountID; - }); return memberEmailsToAccountIDs; } diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index b71d61c6cfda..d778a267a42e 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -364,6 +364,28 @@ function isConciergeChatReport(report) { return lodashGet(report, 'participantAccountIDs', []).length === 1 && Number(report.participantAccountIDs[0]) === CONST.ACCOUNT_ID.CONCIERGE; } +/** + * Returns true if there are any Expensify accounts (i.e. with domain 'expensify.com') in the set of accountIDs + * by cross-referencing the accountIDs with personalDetails. + * + * @param {Array} accountIDs + * @return {Boolean} + */ +function hasExpensifyEmails(accountIDs) { + return _.some(accountIDs, (accountID) => Str.extractEmailDomain(lodashGet(allPersonalDetails, [accountID, 'login'], '')) === CONST.EXPENSIFY_PARTNER_NAME); +} + +/** + * Returns true if there are any guides accounts (team.expensify.com) in a list of accountIDs + * by cross-referencing the accountIDs with personalDetails since guides that are participants + * of the user's chats should have their personal details in Onyx. + * @param {Array} accountIDs + * @returns {Boolean} + */ +function hasExpensifyGuidesEmails(accountIDs) { + return _.some(accountIDs, (accountID) => Str.extractEmailDomain(lodashGet(allPersonalDetails, [accountID, 'login'], '')) === CONST.EMAIL.GUIDES_DOMAIN); +} + /** * @param {Record|Array<{lastReadTime, reportID}>} reports * @param {Boolean} [ignoreDomainRooms] @@ -619,32 +641,6 @@ function hasAutomatedExpensifyAccountIDs(accountIDs) { return _.intersection(accountIDs, CONST.EXPENSIFY_ACCOUNT_IDS).length > 0; } -/** - * Returns true if there are any Expensify accounts (i.e. with domain 'expensify.com') in the set of accountIDs - * by cross-referencing the accountIDs with personalDetails. - * - * @param {Array} accountIDs - * @return {Boolean} - */ -function hasExpensifyEmails(accountIDs) { - return _.some(accountIDs, (accountID) => - Str.extractEmailDomain(lodashGet(allPersonalDetails, [accountID, 'login'], '')) === CONST.EXPENSIFY_PARTNER_NAME - ); -} - -/** - * Returns true if there are any guides accounts (team.expensify.com) in a list of accountIDs - * by cross-referencing the accountIDs with personalDetails since guides that are participants - * of the user's chats should have their personal details in Onyx. - * @param {Array} accountIDs - * @returns {Boolean} - */ -function hasExpensifyGuidesEmails(accountIDs) { - return _.some(accountIDs, (accountID) => - Str.extractEmailDomain(lodashGet(allPersonalDetails, [accountID, 'login'], '')) === CONST.EMAIL.GUIDES_DOMAIN - ); -} - /** * Whether the time row should be shown for a report. * @param {Array} personalDetails diff --git a/src/pages/workspace/WorkspaceInvitePage.js b/src/pages/workspace/WorkspaceInvitePage.js index dd16406811df..f3d5d559fc55 100644 --- a/src/pages/workspace/WorkspaceInvitePage.js +++ b/src/pages/workspace/WorkspaceInvitePage.js @@ -121,7 +121,7 @@ class WorkspaceInvitePage extends React.Component { return; } memberEmailsToExclude.push(memberEmail); - }) + }); return memberEmailsToExclude; } @@ -237,7 +237,7 @@ class WorkspaceInvitePage extends React.Component { return; } invitedEmailsToAccountIDs[login] = accountID; - }) + }); Policy.setWorkspaceInviteMembersDraft(this.props.route.params.policyID, invitedEmailsToAccountIDs); Navigation.navigate(ROUTES.getWorkspaceInviteMessageRoute(this.props.route.params.policyID)); }