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
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion src/libs/PolicyUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ function getClientPolicyMemberEmailsToAccountIDs(policyMembers, personalDetails)
return;
}
memberEmailsToAccountIDs[personalDetail.login] = accountID;

});
return memberEmailsToAccountIDs;
}
Expand Down
49 changes: 24 additions & 25 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,22 +355,35 @@ function getBankAccountRoute(report) {
}

/**
* Returns true if there are any guides accounts (team.expensify.com) in emails
* @param {Array} emails
* Only returns true if this is our main 1:1 DM report with Concierge
*
* @param {Object} report
* @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);
function isConciergeChatReport(report) {
return lodashGet(report, 'participantAccountIDs', []).length === 1 && Number(report.participantAccountIDs[0]) === CONST.ACCOUNT_ID.CONCIERGE;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to make sure that EXPENSIFY_ACCOUNT_ID_CONCIERGE in env is number, not string

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah it's fine actually. It's already wrapped with Number() in CONST.js

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, I did set CONST.ACCOUNT_ID.CONCIERGE like this: CONCIERGE: Number(lodashGet(Config, 'EXPENSIFY_ACCOUNT_ID_CONCIERGE', 8392101)), so I think we're good here, no?

Copy link
Contributor

Choose a reason for hiding this comment

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

All good

}

/**
* Only returns true if this is our main 1:1 DM report with 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 {Object} report
* @param {Array<Number>} 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<Number>} accountIDs
* @returns {Boolean}
*/
function isConciergeChatReport(report) {
return lodashGet(report, 'participantAccountIDs', []).length === 1 && Number(report.participantAccountIDs[0]) === CONST.ACCOUNT_ID.CONCIERGE;
function hasExpensifyGuidesEmails(accountIDs) {
return _.some(accountIDs, (accountID) => Str.extractEmailDomain(lodashGet(allPersonalDetails, [accountID, 'login'], '')) === CONST.EMAIL.GUIDES_DOMAIN);
}

/**
Expand Down Expand Up @@ -400,11 +413,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 @@ -630,16 +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 emails.
*
* @param {Array<String>} emails
* @return {Boolean}
*/
function hasExpensifyEmails(emails) {
return _.some(emails, (email) => Str.extractEmailDomain(email) === CONST.EXPENSIFY_PARTNER_NAME);
}

/**
* Whether the time row should be shown for a report.
* @param {Array<Object>} personalDetails
Expand Down Expand Up @@ -1832,14 +1833,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
4 changes: 2 additions & 2 deletions src/pages/workspace/WorkspaceInvitePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class WorkspaceInvitePage extends React.Component {
return;
}
memberEmailsToExclude.push(memberEmail);
})
});
return memberEmailsToExclude;
}

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