Skip to content
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

[NO QA] Migrate Expensify guide & employee emails checks #20474

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

just moved this closer to hasExpensifyEmails which is a very similar function

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
*
Expand Down Expand Up @@ -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'], [])),
);
}

Expand Down Expand Up @@ -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<String>} emails
* @param {Array<Number>} 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<Number>} accountIDs
* @returns {Boolean}
*/
function hasExpensifyGuidesEmails(accountIDs) {
return _.some(accountIDs, (accountID) =>
Str.extractEmailDomain(lodashGet(allPersonalDetails, [accountID, 'login'], '')) === CONST.EMAIL.GUIDES_DOMAIN
);
}

/**
Expand Down Expand Up @@ -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;
}

Expand Down