Skip to content

Commit

Permalink
Merge pull request #14585 from Expensify/yuwen-domainRoomsForApproved
Browse files Browse the repository at this point in the history
Show Domain Rooms to Domains that have at least one Approved! Accountant
  • Loading branch information
yuwenmemon authored Feb 2, 2023
2 parents e6ece3e + e15397d commit aea38c5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 21 deletions.
64 changes: 55 additions & 9 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ Onyx.connect({
callback: val => allReports = val,
});

let doesDomainHaveApprovedAccountant;
Onyx.connect({
key: ONYXKEYS.ACCOUNT,
waitForCollectionCallback: true,
callback: val => doesDomainHaveApprovedAccountant = val.doesDomainHaveApprovedAccountant,
});

function getChatType(report) {
return report ? report.chatType : '';
}
Expand Down Expand Up @@ -370,10 +377,20 @@ function chatIncludesConcierge(report) {
* @param {Array} emails
* @returns {Boolean}
*/
function hasExpensifyEmails(emails) {
function hasAutomatedExpensifyEmails(emails) {
return _.intersection(emails, CONST.EXPENSIFY_EMAILS).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 @@ -1194,6 +1211,40 @@ function isIOUOwnedByCurrentUser(report, currentUserLogin, iouReports = {}) {
return false;
}

/**
* Assuming the passed in report is a default room, lets us know whether we can see it or not, based on permissions and
* the various subsets of users we've allowed to use default rooms.
*
* @param {Object} report
* @param {Array<Object>} policies
* @param {Array<String>} betas
* @return {Boolean}
*/
function canSeeDefaultRoom(report, policies, betas) {
// Include archived rooms
if (isArchivedRoom(report)) {
return true;
}

// Include default rooms for free plan policies (domain rooms aren't included in here because they do not belong to a policy)
if (getPolicyType(report, policies) === CONST.POLICY.TYPE.FREE) {
return true;
}

// Include domain rooms with Partner Managers (Expensify accounts) in them for accounts that are on a domain with an Approved Accountant
if (isDomainRoom(report) && doesDomainHaveApprovedAccountant && hasExpensifyEmails(lodashGet(report, ['participants'], []))) {
return true;
}

// If the room has an assigned guide, it can be seen.
if (hasExpensifyGuidesEmails(lodashGet(report, ['participants'], []))) {
return true;
}

// For all other cases, just check that the user belongs to the default rooms beta
return Permissions.canUseDefaultRooms(betas);
}

/**
* Takes several pieces of data from Onyx and evaluates if a report should be shown in the option list (either when searching
* for reports or the reports shown in the LHN).
Expand Down Expand Up @@ -1248,13 +1299,7 @@ function shouldReportBeInOptionList(report, reportIDFromRoute, isInGSDMode, curr
return true;
}

// Include default rooms for free plan policies
if (isDefaultRoom(report) && getPolicyType(report, policies) === CONST.POLICY.TYPE.FREE) {
return true;
}

// Include default rooms unless you're on the default room beta, unless you have an assigned guide
if (isDefaultRoom(report) && !Permissions.canUseDefaultRooms(betas) && !hasExpensifyGuidesEmails(lodashGet(report, ['participants'], []))) {
if (isDefaultRoom(report) && !canSeeDefaultRoom(report, policies, betas)) {
return false;
}

Expand Down Expand Up @@ -1343,7 +1388,7 @@ export {
getPolicyType,
isArchivedRoom,
isConciergeChatReport,
hasExpensifyEmails,
hasAutomatedExpensifyEmails,
hasExpensifyGuidesEmails,
hasOutstandingIOU,
isIOUOwnedByCurrentUser,
Expand Down Expand Up @@ -1379,4 +1424,5 @@ export {
isDefaultAvatar,
getOldDotDefaultAvatar,
getNewMarkerReportActionID,
canSeeDefaultRoom,
};
2 changes: 1 addition & 1 deletion src/pages/DetailsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class DetailsPage extends React.PureComponent {
// If we have a reportID param this means that we
// arrived here via the ParticipantsPage and should be allowed to navigate back to it
const shouldShowBackButton = Boolean(this.props.route.params.reportID);
const shouldShowLocalTime = !ReportUtils.hasExpensifyEmails([details.login]) && details.timezone;
const shouldShowLocalTime = !ReportUtils.hasAutomatedExpensifyEmails([details.login]) && details.timezone;
let pronouns = details.pronouns;

if (pronouns && pronouns.startsWith(CONST.PRONOUNS.PREFIX)) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const HeaderView = (props) => {

const subtitle = ReportUtils.getChatRoomSubtitle(props.report, props.policies);
const isConcierge = participants.length === 1 && _.contains(participants, CONST.EMAIL.CONCIERGE);
const isAutomatedExpensifyAccount = (participants.length === 1 && ReportUtils.hasExpensifyEmails(participants));
const isAutomatedExpensifyAccount = (participants.length === 1 && ReportUtils.hasAutomatedExpensifyEmails(participants));
const guideCalendarLink = lodashGet(props.account, 'guideCalendarLink');

// We hide the button when we are chatting with an automated Expensify account since it's not possible to contact
Expand Down
11 changes: 1 addition & 10 deletions src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,7 @@ class ReportScreen extends React.Component {
return null;
}

// We create policy rooms for all policies, however we don't show them unless
// - It's a free plan workspace
// - The report includes guides participants (@team.expensify.com) for 1:1 Assigned
// - It's an archived room
if (!Permissions.canUseDefaultRooms(this.props.betas)
&& ReportUtils.isDefaultRoom(this.props.report)
&& ReportUtils.getPolicyType(this.props.report, this.props.policies) !== CONST.POLICY.TYPE.FREE
&& !ReportUtils.hasExpensifyGuidesEmails(lodashGet(this.props.report, ['participants'], []))
&& !ReportUtils.isArchivedRoom(this.props.report)
) {
if (ReportUtils.isDefaultRoom(this.props.report) && !ReportUtils.canSeeDefaultRoom(this.props.report, this.props.policies, this.props.betas)) {
return null;
}

Expand Down

0 comments on commit aea38c5

Please sign in to comment.