From 57b8d5de6484651b26643624f2e3078127923377 Mon Sep 17 00:00:00 2001 From: Ali Toshmatov Date: Tue, 16 May 2023 22:55:28 +0500 Subject: [PATCH 01/13] Added isPolicyAdmin function which takes report and checks if user is admin in report's policy --- src/libs/ReportUtils.js | 12 ++++++++++++ src/pages/ReportDetailsPage.js | 31 ++++++++++++++++++++++++------- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 7252d12cdffc..4d51c9b3c6f6 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2152,6 +2152,17 @@ function isReportDataReady() { return !_.isEmpty(allReports) && _.some(_.keys(allReports), (key) => allReports[key].reportID); } +/** + * Return true if user is an admin of the report's policy + * {Object} report + * @returns {boolean} + */ +const isPolicyAdmin = (report) => { + const policyRole = lodashGet(allPolicies, [`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, 'role']); + + return policyRole === CONST.POLICY.ROLE.ADMIN; +}; + export { getReportParticipantsTitle, isReportMessageAttachment, @@ -2241,4 +2252,5 @@ export { isReportDataReady, isSettled, getMoneyRequestAction, + isPolicyAdmin, }; diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index 9ed7bfa86092..c8672b98d42f 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -2,7 +2,7 @@ import React, {Component} from 'react'; import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; -import {View, ScrollView} from 'react-native'; +import {View, ScrollView, Pressable} from 'react-native'; import lodashGet from 'lodash/get'; import RoomHeaderAvatars from '../components/RoomHeaderAvatars'; import compose from '../libs/compose'; @@ -117,6 +117,15 @@ class ReportDetailsPage extends Component { isMultipleParticipant, ); const menuItems = this.getMenuItems(); + const isPolicyAdmin = ReportUtils.isPolicyAdmin(this.props.report); + const chatRoomSubtitleText = ( + + {chatRoomSubtitle} + + ); return ( @@ -142,12 +151,20 @@ class ReportDetailsPage extends Component { shouldUseFullTitle={isChatRoom || isPolicyExpenseChat} /> - - {chatRoomSubtitle} - + {isPolicyAdmin ? ( + { + if (!isPolicyAdmin) { + return; + } + Navigation.navigate(ROUTES.getWorkspaceInitialRoute(this.props.report.policyID)); + }} + > + {chatRoomSubtitleText} + + ) : ( + chatRoomSubtitleText + )} From 7404324d0e81ba2578f13e676b3819a2d07722c5 Mon Sep 17 00:00:00 2001 From: Ali Toshmatov Date: Wed, 17 May 2023 00:40:55 +0500 Subject: [PATCH 02/13] Fixed lint error --- ios/Podfile.lock | 2 +- src/libs/ReportUtils.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index f0d6720080e8..067974992f16 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -1135,4 +1135,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 5feaab251246f42f41e69c8a28fa331b4899e814 -COCOAPODS: 1.12.0 +COCOAPODS: 1.11.3 diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 4d51c9b3c6f6..ae917dd66e37 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2154,7 +2154,8 @@ function isReportDataReady() { /** * Return true if user is an admin of the report's policy - * {Object} report + * + * @param {Object} report * @returns {boolean} */ const isPolicyAdmin = (report) => { From f3db63700aef6eeef7773bb50af3ea31acafed45 Mon Sep 17 00:00:00 2001 From: Ali Toshmatov Date: Wed, 17 May 2023 00:50:49 +0500 Subject: [PATCH 03/13] Fixed unexpected podfile.lock change --- ios/Podfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 067974992f16..f0d6720080e8 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -1135,4 +1135,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 5feaab251246f42f41e69c8a28fa331b4899e814 -COCOAPODS: 1.11.3 +COCOAPODS: 1.12.0 From 1b376a302076ff6a7d4cdb3005a33d9abddad414 Mon Sep 17 00:00:00 2001 From: Ali Toshmatov <59907218+alitoshmatov@users.noreply.github.com> Date: Fri, 19 May 2023 01:07:53 +0500 Subject: [PATCH 04/13] Update src/libs/ReportUtils.js Co-authored-by: Miroslav Stevanovic <97473779+0xmiroslav@users.noreply.github.com> --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index ae917dd66e37..1bd7a66fe403 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2153,7 +2153,7 @@ function isReportDataReady() { } /** - * Return true if user is an admin of the report's policy + * Checks if the current user is the admin of the policy. * * @param {Object} report * @returns {boolean} From ac24c10759eec800072c57d07fa339a944149741 Mon Sep 17 00:00:00 2001 From: Ali Toshmatov <59907218+alitoshmatov@users.noreply.github.com> Date: Fri, 19 May 2023 01:08:07 +0500 Subject: [PATCH 05/13] Update src/libs/ReportUtils.js Co-authored-by: Miroslav Stevanovic <97473779+0xmiroslav@users.noreply.github.com> --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 1bd7a66fe403..89e14415d6d7 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2156,7 +2156,7 @@ function isReportDataReady() { * Checks if the current user is the admin of the policy. * * @param {Object} report - * @returns {boolean} + * @returns {Boolean} */ const isPolicyAdmin = (report) => { const policyRole = lodashGet(allPolicies, [`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, 'role']); From 50c5e3b7df0eb675e2106655338efe2ebe183119 Mon Sep 17 00:00:00 2001 From: Ali Toshmatov <59907218+alitoshmatov@users.noreply.github.com> Date: Fri, 19 May 2023 01:09:34 +0500 Subject: [PATCH 06/13] Fixed route to go to workspace settings page Co-authored-by: Miroslav Stevanovic <97473779+0xmiroslav@users.noreply.github.com> --- src/pages/ReportDetailsPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index c8672b98d42f..116e6b211383 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -157,7 +157,7 @@ class ReportDetailsPage extends Component { if (!isPolicyAdmin) { return; } - Navigation.navigate(ROUTES.getWorkspaceInitialRoute(this.props.report.policyID)); + Navigation.navigate(ROUTES.getWorkspaceSettingsRoute(this.props.report.policyID)); }} > {chatRoomSubtitleText} From ec99524142a2d7c8da432bf5f49cbf9677b373e5 Mon Sep 17 00:00:00 2001 From: Ali Toshmatov Date: Fri, 19 May 2023 02:00:56 +0500 Subject: [PATCH 07/13] Removed reduntant condition --- src/pages/ReportDetailsPage.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index 116e6b211383..08f81ed857f1 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -154,9 +154,6 @@ class ReportDetailsPage extends Component { {isPolicyAdmin ? ( { - if (!isPolicyAdmin) { - return; - } Navigation.navigate(ROUTES.getWorkspaceSettingsRoute(this.props.report.policyID)); }} > From fd69abdf704fa7946303256b32d862043669397e Mon Sep 17 00:00:00 2001 From: Ali Toshmatov Date: Fri, 19 May 2023 02:16:47 +0500 Subject: [PATCH 08/13] Placed isPolicyAdmin to policyUtils --- src/libs/PolicyUtils.js | 10 +++++++++- src/libs/ReportUtils.js | 13 ------------- src/pages/ReportDetailsPage.js | 4 +++- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js index f19420a2b38a..e8ea9e7357eb 100644 --- a/src/libs/PolicyUtils.js +++ b/src/libs/PolicyUtils.js @@ -92,4 +92,12 @@ function isExpensifyTeam(email) { return emailDomain === CONST.EXPENSIFY_PARTNER_NAME || emailDomain === CONST.EMAIL.GUIDES_DOMAIN; } -export {hasPolicyMemberError, hasPolicyError, hasPolicyErrorFields, hasCustomUnitsError, getPolicyBrickRoadIndicatorStatus, shouldShowPolicy, isExpensifyTeam}; +/** + * Checks if the current user is the admin of the policy. + * + * @param {Object} policy + * @returns {Boolean} + */ +const isPolicyAdmin = (policy) => policy.role === CONST.POLICY.ROLE.ADMIN; + +export {hasPolicyMemberError, hasPolicyError, hasPolicyErrorFields, hasCustomUnitsError, getPolicyBrickRoadIndicatorStatus, shouldShowPolicy, isExpensifyTeam, isPolicyAdmin}; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 89e14415d6d7..7252d12cdffc 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2152,18 +2152,6 @@ function isReportDataReady() { return !_.isEmpty(allReports) && _.some(_.keys(allReports), (key) => allReports[key].reportID); } -/** - * Checks if the current user is the admin of the policy. - * - * @param {Object} report - * @returns {Boolean} - */ -const isPolicyAdmin = (report) => { - const policyRole = lodashGet(allPolicies, [`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, 'role']); - - return policyRole === CONST.POLICY.ROLE.ADMIN; -}; - export { getReportParticipantsTitle, isReportMessageAttachment, @@ -2253,5 +2241,4 @@ export { isReportDataReady, isSettled, getMoneyRequestAction, - isPolicyAdmin, }; diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index 08f81ed857f1..59512a3aa770 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -16,6 +16,7 @@ import DisplayNames from '../components/DisplayNames'; import * as OptionsListUtils from '../libs/OptionsListUtils'; import * as ReportUtils from '../libs/ReportUtils'; import * as Policy from '../libs/actions/Policy'; +import * as PolicyUtils from '../libs/PolicyUtils'; import participantPropTypes from '../components/participantPropTypes'; import * as Expensicons from '../components/Icon/Expensicons'; import ROUTES from '../ROUTES'; @@ -117,7 +118,8 @@ class ReportDetailsPage extends Component { isMultipleParticipant, ); const menuItems = this.getMenuItems(); - const isPolicyAdmin = ReportUtils.isPolicyAdmin(this.props.report); + const policy = this.props.policies[`${ONYXKEYS.COLLECTION.POLICY}${this.props.report.policyID}`]; + const isPolicyAdmin = PolicyUtils.isPolicyAdmin(policy); const chatRoomSubtitleText = ( Date: Fri, 19 May 2023 02:35:09 +0500 Subject: [PATCH 09/13] Extracted getPolicy method --- src/pages/ReportDetailsPage.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index 59512a3aa770..4ecb278a153e 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -57,6 +57,10 @@ const defaultProps = { }; class ReportDetailsPage extends Component { + getPolicy() { + return this.props.policies[`${ONYXKEYS.COLLECTION.POLICY}${this.props.report.policyID}`]; + } + getMenuItems() { const menuItems = [ { @@ -94,7 +98,7 @@ class ReportDetailsPage extends Component { }); } - const policy = this.props.policies[`${ONYXKEYS.COLLECTION.POLICY}${this.props.report.policyID}`]; + const policy = this.getPolicy(); if (ReportUtils.isUserCreatedPolicyRoom(this.props.report) || ReportUtils.canLeaveRoom(this.props.report, !_.isEmpty(policy))) { menuItems.push({ key: CONST.REPORT_DETAILS_MENU_ITEM.LEAVE_ROOM, @@ -118,8 +122,7 @@ class ReportDetailsPage extends Component { isMultipleParticipant, ); const menuItems = this.getMenuItems(); - const policy = this.props.policies[`${ONYXKEYS.COLLECTION.POLICY}${this.props.report.policyID}`]; - const isPolicyAdmin = PolicyUtils.isPolicyAdmin(policy); + const isPolicyAdmin = PolicyUtils.isPolicyAdmin(this.getPolicy()); const chatRoomSubtitleText = ( Date: Fri, 19 May 2023 02:43:01 +0500 Subject: [PATCH 10/13] Removed lint error --- src/pages/ReportDetailsPage.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index fc15678cc5e0..db2407f67583 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -15,7 +15,6 @@ import styles from '../styles/styles'; import DisplayNames from '../components/DisplayNames'; import * as OptionsListUtils from '../libs/OptionsListUtils'; import * as ReportUtils from '../libs/ReportUtils'; -import * as Policy from '../libs/actions/Policy'; import * as PolicyUtils from '../libs/PolicyUtils'; import * as Report from '../libs/actions/Report'; import participantPropTypes from '../components/participantPropTypes'; From 962355c9daf8d5ae147ce60489b914f15a13e966 Mon Sep 17 00:00:00 2001 From: Ali Toshmatov <59907218+alitoshmatov@users.noreply.github.com> Date: Fri, 19 May 2023 02:45:43 +0500 Subject: [PATCH 11/13] Updated comment Co-authored-by: Puneet Lath --- src/libs/PolicyUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js index e8ea9e7357eb..dcc37451ced5 100644 --- a/src/libs/PolicyUtils.js +++ b/src/libs/PolicyUtils.js @@ -93,7 +93,7 @@ function isExpensifyTeam(email) { } /** - * Checks if the current user is the admin of the policy. + * Checks if the current user is an admin of the policy. * * @param {Object} policy * @returns {Boolean} From ef3975d45c3d582ade0da23e8e9c4cddaeff5a1e Mon Sep 17 00:00:00 2001 From: Ali Toshmatov <59907218+alitoshmatov@users.noreply.github.com> Date: Fri, 19 May 2023 03:11:07 +0500 Subject: [PATCH 12/13] Update src/libs/PolicyUtils.js Co-authored-by: Miroslav Stevanovic <97473779+0xmiroslav@users.noreply.github.com> --- src/libs/PolicyUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js index dcc37451ced5..91396be628a3 100644 --- a/src/libs/PolicyUtils.js +++ b/src/libs/PolicyUtils.js @@ -98,6 +98,6 @@ function isExpensifyTeam(email) { * @param {Object} policy * @returns {Boolean} */ -const isPolicyAdmin = (policy) => policy.role === CONST.POLICY.ROLE.ADMIN; +const isPolicyAdmin = (policy) => lodashGet(policy, 'role') === CONST.POLICY.ROLE.ADMIN; export {hasPolicyMemberError, hasPolicyError, hasPolicyErrorFields, hasCustomUnitsError, getPolicyBrickRoadIndicatorStatus, shouldShowPolicy, isExpensifyTeam, isPolicyAdmin}; From 3da475d2c303604c768c888f4106169edb28d622 Mon Sep 17 00:00:00 2001 From: Ali Toshmatov <59907218+alitoshmatov@users.noreply.github.com> Date: Fri, 19 May 2023 18:44:05 +0500 Subject: [PATCH 13/13] Changing back to go to workspace initial page Co-authored-by: Puneet Lath --- src/pages/ReportDetailsPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/ReportDetailsPage.js b/src/pages/ReportDetailsPage.js index db2407f67583..f073abbb2616 100644 --- a/src/pages/ReportDetailsPage.js +++ b/src/pages/ReportDetailsPage.js @@ -161,7 +161,7 @@ class ReportDetailsPage extends Component { {isPolicyAdmin ? ( { - Navigation.navigate(ROUTES.getWorkspaceSettingsRoute(this.props.report.policyID)); + Navigation.navigate(ROUTES.getWorkspaceInitialRoute(this.props.report.policyID)); }} > {chatRoomSubtitleText}