From c7d73a95ccda9ee40dbce535614289bf80fbd14b Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Wed, 7 Sep 2022 10:00:24 +0100 Subject: [PATCH 1/6] add method / constant --- src/CONST.js | 1 + src/libs/ReportUtils.js | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/CONST.js b/src/CONST.js index 903f70bdaa56..b217d5f7d6fd 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -512,6 +512,7 @@ const CONST = { SVFG: 'svfg@expensify.com', INTEGRATION_TESTING_CREDS: 'integrationtestingcreds@expensify.com', ADMIN: 'admin@expensify.com', + GUIDES_DOMAIN: 'team.expensify.com', }, ENVIRONMENT: { diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 8fd7ec3af880..dd2eb810e524 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -215,7 +215,7 @@ function findLastAccessedReport(reports, ignoreDefaultRooms, policies) { let sortedReports = sortReportsByLastVisited(reports); if (ignoreDefaultRooms) { - sortedReports = _.filter(sortedReports, report => !isDefaultRoom(report) || getPolicyType(report, policies) === CONST.POLICY.TYPE.FREE); + sortedReports = _.filter(sortedReports, report => !isDefaultRoom(report) || getPolicyType(report, policies) === CONST.POLICY.TYPE.FREE || hasExpensifyGuidesEmails(lodashGet(report, ['participants'], []))); } return _.last(sortedReports); @@ -335,6 +335,13 @@ function hasExpensifyEmails(emails) { return _.intersection(emails, CONST.EXPENSIFY_EMAILS).length > 0; } +/** + * Returns true if there are any guides accounts (team.expensify.com) in emails + */ +function hasExpensifyGuidesEmails(emails) { + return _.some(emails, email => Str.extractEmailDomain(email) === CONST.EMAIL.GUIDES_DOMAIN); +} + /** * Whether the time row should be shown for a report. * @param {Array} personalDetails @@ -648,6 +655,7 @@ export { isArchivedRoom, isConciergeChatReport, hasExpensifyEmails, + hasExpensifyGuidesEmails, canShowReportRecipientLocalTime, formatReportLastMessageText, chatIncludesConcierge, From fdb6b402d2bbd1d9a0c249a52eac576dc37bdc73 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Wed, 7 Sep 2022 10:00:39 +0100 Subject: [PATCH 2/6] update locations where this is used --- src/libs/OptionsListUtils.js | 2 +- src/pages/home/ReportScreen.js | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 186e54ef8e49..494208900ecd 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -444,7 +444,7 @@ function getOptions(reports, personalDetails, activeReportID, { } // We let Free Plan default rooms to be shown in the App - it's the one exception to the beta, otherwise do not show policy rooms in product - if (ReportUtils.isDefaultRoom(report) && !Permissions.canUseDefaultRooms(betas) && ReportUtils.getPolicyType(report, policies) !== CONST.POLICY.TYPE.FREE) { + if (ReportUtils.isDefaultRoom(report) && !ReportUtils.hasExpensifyGuidesEmails(logins) && !Permissions.canUseDefaultRooms(betas) && ReportUtils.getPolicyType(report, policies) !== CONST.POLICY.TYPE.FREE) { return; } diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 0ae86f2fed5a..4a818e4efce1 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -204,7 +204,9 @@ class ReportScreen extends React.Component { // We let Free Plan default rooms to be shown in the App - it's the one exception to the beta, otherwise do not show policy rooms in product if (!Permissions.canUseDefaultRooms(this.props.betas) && ReportUtils.isDefaultRoom(this.props.report) - && ReportUtils.getPolicyType(this.props.report, this.props.policies) !== CONST.POLICY.TYPE.FREE) { + && ReportUtils.getPolicyType(this.props.report, this.props.policies) !== CONST.POLICY.TYPE.FREE + && ReportUtils.hasExpensifyGuidesEmails(lodashGet(this.props.report, ['participants'], [])) + ) { return null; } From 0cd8ddbea30c540792dce9ee07897ddc48ed6368 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Wed, 7 Sep 2022 10:15:33 +0100 Subject: [PATCH 3/6] style --- src/libs/OptionsListUtils.js | 6 +++++- src/libs/ReportUtils.js | 20 ++++++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 494208900ecd..62d3d98a680d 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -444,7 +444,11 @@ function getOptions(reports, personalDetails, activeReportID, { } // We let Free Plan default rooms to be shown in the App - it's the one exception to the beta, otherwise do not show policy rooms in product - if (ReportUtils.isDefaultRoom(report) && !ReportUtils.hasExpensifyGuidesEmails(logins) && !Permissions.canUseDefaultRooms(betas) && ReportUtils.getPolicyType(report, policies) !== CONST.POLICY.TYPE.FREE) { + if (ReportUtils.isDefaultRoom(report) + && !ReportUtils.hasExpensifyGuidesEmails(logins) + && !Permissions.canUseDefaultRooms(betas) + && ReportUtils.getPolicyType(report, policies) !== CONST.POLICY.TYPE.FREE + ) { return; } diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index dd2eb810e524..d884c770e419 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -203,6 +203,15 @@ function getPolicyType(report, policies) { return lodashGet(policies, [`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, 'type'], ''); } +/** + * 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); +} + /** * Given a collection of reports returns the most recently accessed one * @@ -215,7 +224,9 @@ function findLastAccessedReport(reports, ignoreDefaultRooms, policies) { let sortedReports = sortReportsByLastVisited(reports); if (ignoreDefaultRooms) { - sortedReports = _.filter(sortedReports, report => !isDefaultRoom(report) || getPolicyType(report, policies) === CONST.POLICY.TYPE.FREE || hasExpensifyGuidesEmails(lodashGet(report, ['participants'], []))); + sortedReports = _.filter(sortedReports, report => !isDefaultRoom(report) + || getPolicyType(report, policies) === CONST.POLICY.TYPE.FREE + || hasExpensifyGuidesEmails(lodashGet(report, ['participants'], []))); } return _.last(sortedReports); @@ -335,13 +346,6 @@ function hasExpensifyEmails(emails) { return _.intersection(emails, CONST.EXPENSIFY_EMAILS).length > 0; } -/** - * Returns true if there are any guides accounts (team.expensify.com) in emails - */ -function hasExpensifyGuidesEmails(emails) { - return _.some(emails, email => Str.extractEmailDomain(email) === CONST.EMAIL.GUIDES_DOMAIN); -} - /** * Whether the time row should be shown for a report. * @param {Array} personalDetails From 0881d3419cccdafd800518c0c74b30bb3cf14c7a Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Wed, 7 Sep 2022 20:44:48 +0100 Subject: [PATCH 4/6] update comment and hasExpensifyGuidesEmails check --- src/pages/home/ReportScreen.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 4a818e4efce1..f852dfb2626f 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -201,11 +201,13 @@ class ReportScreen extends React.Component { return null; } - // We let Free Plan default rooms to be shown in the App - it's the one exception to the beta, otherwise do not show policy rooms in product + // 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 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.hasExpensifyGuidesEmails(lodashGet(this.props.report, ['participants'], [])) ) { return null; } From 44dd0e724591a722902cc60cdcadda16a95a0635 Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Wed, 7 Sep 2022 20:48:25 +0100 Subject: [PATCH 5/6] update other comment --- src/libs/OptionsListUtils.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 62d3d98a680d..f98e18761778 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -443,7 +443,9 @@ function getOptions(reports, personalDetails, activeReportID, { return; } - // We let Free Plan default rooms to be shown in the App - it's the one exception to the beta, otherwise do not show policy rooms in product + // 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 if (ReportUtils.isDefaultRoom(report) && !ReportUtils.hasExpensifyGuidesEmails(logins) && !Permissions.canUseDefaultRooms(betas) From 3eeca550607cdb8bf292c308b8afbc480b085a0c Mon Sep 17 00:00:00 2001 From: Jack Nam Date: Thu, 8 Sep 2022 09:21:46 +0100 Subject: [PATCH 6/6] reorder --- src/libs/OptionsListUtils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index f98e18761778..c54690403d85 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -446,10 +446,10 @@ function getOptions(reports, personalDetails, activeReportID, { // 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 - if (ReportUtils.isDefaultRoom(report) - && !ReportUtils.hasExpensifyGuidesEmails(logins) - && !Permissions.canUseDefaultRooms(betas) + if (!Permissions.canUseDefaultRooms(betas) + && ReportUtils.isDefaultRoom(report) && ReportUtils.getPolicyType(report, policies) !== CONST.POLICY.TYPE.FREE + && !ReportUtils.hasExpensifyGuidesEmails(logins) ) { return; }