From e300fe463dc27e80dc830aa2c2eb4ddb5b8f773b Mon Sep 17 00:00:00 2001 From: Hans Date: Thu, 6 Jul 2023 06:13:38 +0700 Subject: [PATCH 01/14] fix rename room permission --- .../settings/Report/ReportSettingsPage.js | 5 --- src/pages/settings/Report/RoomNamePage.js | 44 ++++++++++--------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/pages/settings/Report/ReportSettingsPage.js b/src/pages/settings/Report/ReportSettingsPage.js index 7f246a346c56..965d57925c96 100644 --- a/src/pages/settings/Report/ReportSettingsPage.js +++ b/src/pages/settings/Report/ReportSettingsPage.js @@ -65,11 +65,6 @@ class ReportSettingsPage extends Component { return true; } - // The remaining checks only apply to public rooms - if (!ReportUtils.isPublicRoom(this.props.report)) { - return false; - } - // if the linked workspace is null, that means the person isn't a member of the workspace the report is in // which means this has to be a public room we want to disable renaming for if (!linkedWorkspace) { diff --git a/src/pages/settings/Report/RoomNamePage.js b/src/pages/settings/Report/RoomNamePage.js index 011a65d4cb76..f3248200ace3 100644 --- a/src/pages/settings/Report/RoomNamePage.js +++ b/src/pages/settings/Report/RoomNamePage.js @@ -18,6 +18,8 @@ import reportPropTypes from '../../reportPropTypes'; import ROUTES from '../../../ROUTES'; import * as Report from '../../../libs/actions/Report'; import RoomNameInput from '../../../components/RoomNameInput'; +import * as ReportUtils from '../../../libs/ReportUtils'; +import FullPageNotFoundView from '../../../components/BlockingViews/FullPageNotFoundView'; const propTypes = { ...withLocalizePropTypes, @@ -67,26 +69,28 @@ function RoomNamePage(props) { return ( - Navigation.goBack(ROUTES.getReportSettingsRoute(report.reportID))} - /> -
Report.updatePolicyRoomNameAndNavigate(report, values.roomName)} - validate={validate} - submitButtonText={translate('common.save')} - enabledWhenOffline - > - - - -
+ + Navigation.goBack(ROUTES.getReportSettingsRoute(report.reportID))} + /> +
Report.updatePolicyRoomNameAndNavigate(report, values.roomName)} + validate={validate} + submitButtonText={translate('common.save')} + enabledWhenOffline + > + + + +
+
); } From fc84f5e8aa48b7ae20f7acc6be59abf6c07b6d95 Mon Sep 17 00:00:00 2001 From: Hans Date: Thu, 6 Jul 2023 12:09:51 +0700 Subject: [PATCH 02/14] update condition of rename page --- src/pages/settings/Report/RoomNamePage.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/pages/settings/Report/RoomNamePage.js b/src/pages/settings/Report/RoomNamePage.js index f3248200ace3..0f578a4693d8 100644 --- a/src/pages/settings/Report/RoomNamePage.js +++ b/src/pages/settings/Report/RoomNamePage.js @@ -18,7 +18,7 @@ import reportPropTypes from '../../reportPropTypes'; import ROUTES from '../../../ROUTES'; import * as Report from '../../../libs/actions/Report'; import RoomNameInput from '../../../components/RoomNameInput'; -import * as ReportUtils from '../../../libs/ReportUtils'; +import * as Policy from '../../../libs/actions/Policy'; import FullPageNotFoundView from '../../../components/BlockingViews/FullPageNotFoundView'; const propTypes = { @@ -29,12 +29,20 @@ const propTypes = { /** All reports shared with the user */ reports: PropTypes.objectOf(reportPropTypes), + + /** */ + policy: { + role: PropTypes.string, + owner: PropTypes.string, + } }; const defaultProps = { reports: {}, + policy: {}, }; function RoomNamePage(props) { + const policy = props.policy; const report = props.report; const reports = props.reports; const translate = props.translate; @@ -69,7 +77,7 @@ function RoomNamePage(props) { return ( - + Navigation.goBack(ROUTES.getReportSettingsRoute(report.reportID))} @@ -106,5 +114,8 @@ export default compose( reports: { key: ONYXKEYS.COLLECTION.REPORT, }, + policy : { + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, + }, }), )(RoomNamePage); From 346f13c8bb627805a438572c8f682c724bceb1e7 Mon Sep 17 00:00:00 2001 From: Hans Date: Thu, 6 Jul 2023 12:32:15 +0700 Subject: [PATCH 03/14] fix linting --- src/pages/settings/Report/RoomNamePage.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/settings/Report/RoomNamePage.js b/src/pages/settings/Report/RoomNamePage.js index 0f578a4693d8..12b1a756ed25 100644 --- a/src/pages/settings/Report/RoomNamePage.js +++ b/src/pages/settings/Report/RoomNamePage.js @@ -31,10 +31,10 @@ const propTypes = { reports: PropTypes.objectOf(reportPropTypes), /** */ - policy: { + policy: PropTypes.shape({ role: PropTypes.string, owner: PropTypes.string, - } + }) }; const defaultProps = { reports: {}, From 9823d69a484a560a189880e402e9b1c1dbf1a3ee Mon Sep 17 00:00:00 2001 From: Hans Date: Thu, 6 Jul 2023 12:43:02 +0700 Subject: [PATCH 04/14] fix linting stuff --- src/pages/settings/Report/RoomNamePage.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/settings/Report/RoomNamePage.js b/src/pages/settings/Report/RoomNamePage.js index 12b1a756ed25..026cea376920 100644 --- a/src/pages/settings/Report/RoomNamePage.js +++ b/src/pages/settings/Report/RoomNamePage.js @@ -34,7 +34,7 @@ const propTypes = { policy: PropTypes.shape({ role: PropTypes.string, owner: PropTypes.string, - }) + }), }; const defaultProps = { reports: {}, @@ -114,7 +114,7 @@ export default compose( reports: { key: ONYXKEYS.COLLECTION.REPORT, }, - policy : { + policy: { key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, }, }), From 3fec021d6b0de1aeaac55bdb390beb00710155fe Mon Sep 17 00:00:00 2001 From: Hans Date: Fri, 7 Jul 2023 09:41:28 +0700 Subject: [PATCH 05/14] remove dupe code --- src/libs/actions/Policy.js | 11 +++++++++++ src/pages/settings/Report/ReportSettingsPage.js | 2 +- src/pages/settings/Report/RoomNamePage.js | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index bad48978b0e1..eec76f0c0771 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -166,6 +166,16 @@ function isPolicyOwner(policy) { return _.keys(loginList).includes(policy.owner); } +/** + * Is the user the member of the given policy? + * + * @param {Object} policy + * @returns {Boolean} + */ +function isPolicyMember(policy) { + return !isPolicyOwner(policy) && policy.role !== CONST.POLICY.ROLE.ADMIN; +} + /** * Check if the user has any active free policies (aka workspaces) * @@ -1142,4 +1152,5 @@ export { removeWorkspace, setWorkspaceInviteMembersDraft, isPolicyOwner, + isPolicyMember }; diff --git a/src/pages/settings/Report/ReportSettingsPage.js b/src/pages/settings/Report/ReportSettingsPage.js index 965d57925c96..ddb394bd402b 100644 --- a/src/pages/settings/Report/ReportSettingsPage.js +++ b/src/pages/settings/Report/ReportSettingsPage.js @@ -73,7 +73,7 @@ class ReportSettingsPage extends Component { // If there is a linked workspace, that means the user is a member of the workspace the report is in. // Still, we only want policy owners and admins to be able to modify the name. - return !Policy.isPolicyOwner(linkedWorkspace) && linkedWorkspace.role !== CONST.POLICY.ROLE.ADMIN; + return Policy.isPolicyMember(linkedWorkspace) } /** diff --git a/src/pages/settings/Report/RoomNamePage.js b/src/pages/settings/Report/RoomNamePage.js index 026cea376920..e025a93d7e76 100644 --- a/src/pages/settings/Report/RoomNamePage.js +++ b/src/pages/settings/Report/RoomNamePage.js @@ -77,7 +77,7 @@ function RoomNamePage(props) { return ( - + Navigation.goBack(ROUTES.getReportSettingsRoute(report.reportID))} From eae6abaaf437fe0433ad1e74e35b466dfc18b9e4 Mon Sep 17 00:00:00 2001 From: Hans Date: Fri, 7 Jul 2023 09:52:07 +0700 Subject: [PATCH 06/14] fix linting --- src/libs/actions/Policy.js | 2 +- src/pages/settings/Report/ReportSettingsPage.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index eec76f0c0771..e7b74adeee86 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -1152,5 +1152,5 @@ export { removeWorkspace, setWorkspaceInviteMembersDraft, isPolicyOwner, - isPolicyMember + isPolicyMember, }; diff --git a/src/pages/settings/Report/ReportSettingsPage.js b/src/pages/settings/Report/ReportSettingsPage.js index ddb394bd402b..f7f8e5a479e0 100644 --- a/src/pages/settings/Report/ReportSettingsPage.js +++ b/src/pages/settings/Report/ReportSettingsPage.js @@ -73,7 +73,7 @@ class ReportSettingsPage extends Component { // If there is a linked workspace, that means the user is a member of the workspace the report is in. // Still, we only want policy owners and admins to be able to modify the name. - return Policy.isPolicyMember(linkedWorkspace) + return Policy.isPolicyMember(linkedWorkspace); } /** From 17c1ae9c14aa9bf2c2a44b8cfce927adb20b32ac Mon Sep 17 00:00:00 2001 From: Hans Date: Fri, 7 Jul 2023 23:44:43 +0700 Subject: [PATCH 07/14] move shouldrename to Policy --- src/libs/actions/Policy.js | 22 +++++++++++++++++++ .../settings/Report/ReportSettingsPage.js | 22 +------------------ src/pages/settings/Report/RoomNamePage.js | 2 +- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index e7b74adeee86..2613045622c4 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -176,6 +176,27 @@ function isPolicyMember(policy) { return !isPolicyOwner(policy) && policy.role !== CONST.POLICY.ROLE.ADMIN; } +/** + * @param {Object|null} linkedWorkspace - the workspace the report is on, null if the user isn't a member of the workspace + * @param {Object|null} report + * @returns {Boolean} + */ +function shouldDisableRename(linkedWorkspace, report) { + if (ReportUtils.isDefaultRoom(report) || ReportUtils.isArchivedRoom(report)) { + return true; + } + + // if the linked workspace is null, that means the person isn't a member of the workspace the report is in + // which means this has to be a public room we want to disable renaming for + if (!linkedWorkspace) { + return true; + } + + // If there is a linked workspace, that means the user is a member of the workspace the report is in. + // Still, we only want policy owners and admins to be able to modify the name. + return isPolicyMember(linkedWorkspace); +} + /** * Check if the user has any active free policies (aka workspaces) * @@ -1153,4 +1174,5 @@ export { setWorkspaceInviteMembersDraft, isPolicyOwner, isPolicyMember, + shouldDisableRename, }; diff --git a/src/pages/settings/Report/ReportSettingsPage.js b/src/pages/settings/Report/ReportSettingsPage.js index f7f8e5a479e0..ab42852dc9ed 100644 --- a/src/pages/settings/Report/ReportSettingsPage.js +++ b/src/pages/settings/Report/ReportSettingsPage.js @@ -56,26 +56,6 @@ const defaultProps = { }; class ReportSettingsPage extends Component { - /** - * @param {Object|null} linkedWorkspace - the workspace the report is on, null if the user isn't a member of the workspace - * @returns {Boolean} - */ - shouldDisableRename(linkedWorkspace) { - if (ReportUtils.isDefaultRoom(this.props.report) || ReportUtils.isArchivedRoom(this.props.report)) { - return true; - } - - // if the linked workspace is null, that means the person isn't a member of the workspace the report is in - // which means this has to be a public room we want to disable renaming for - if (!linkedWorkspace) { - return true; - } - - // If there is a linked workspace, that means the user is a member of the workspace the report is in. - // Still, we only want policy owners and admins to be able to modify the name. - return Policy.isPolicyMember(linkedWorkspace); - } - /** * We only want policy owners and admins to be able to modify the welcome message. * @@ -89,7 +69,7 @@ class ReportSettingsPage extends Component { render() { const shouldShowRoomName = !ReportUtils.isPolicyExpenseChat(this.props.report) && !ReportUtils.isChatThread(this.props.report); const linkedWorkspace = _.find(this.props.policies, (policy) => policy && policy.id === this.props.report.policyID); - const shouldDisableRename = this.shouldDisableRename(linkedWorkspace) || ReportUtils.isChatThread(this.props.report); + const shouldDisableRename = Policy.shouldDisableRename(linkedWorkspace, this.props.report) || ReportUtils.isChatThread(this.props.report); const notificationPreference = this.props.translate(`notificationPreferencesPage.notificationPreferences.${this.props.report.notificationPreference}`); const shouldDisableWelcomeMessage = this.shouldDisableWelcomeMessage(linkedWorkspace); const writeCapability = ReportUtils.isAdminRoom(this.props.report) diff --git a/src/pages/settings/Report/RoomNamePage.js b/src/pages/settings/Report/RoomNamePage.js index e025a93d7e76..f1e4685521c3 100644 --- a/src/pages/settings/Report/RoomNamePage.js +++ b/src/pages/settings/Report/RoomNamePage.js @@ -77,7 +77,7 @@ function RoomNamePage(props) { return ( - + Navigation.goBack(ROUTES.getReportSettingsRoute(report.reportID))} From 277dcd12c0984b14cc8e70280b207ef8d6f59b80 Mon Sep 17 00:00:00 2001 From: Hans Date: Mon, 10 Jul 2023 09:00:49 +0700 Subject: [PATCH 08/14] add comment for policy prop type --- src/pages/settings/Report/RoomNamePage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/settings/Report/RoomNamePage.js b/src/pages/settings/Report/RoomNamePage.js index e025a93d7e76..05ac991cd069 100644 --- a/src/pages/settings/Report/RoomNamePage.js +++ b/src/pages/settings/Report/RoomNamePage.js @@ -30,7 +30,7 @@ const propTypes = { /** All reports shared with the user */ reports: PropTypes.objectOf(reportPropTypes), - /** */ + /** Policy of the report for which the name is being edited */ policy: PropTypes.shape({ role: PropTypes.string, owner: PropTypes.string, From bf510dd52624844fcdf9bd16c8cf0a568310d03e Mon Sep 17 00:00:00 2001 From: Hans Date: Thu, 13 Jul 2023 16:07:28 +0700 Subject: [PATCH 09/14] move shouldDisableRename to ReportUtils --- src/libs/PolicyUtils.js | 12 ++++++++++ src/libs/ReportUtils.js | 23 +++++++++++++++++++ src/libs/actions/Policy.js | 23 ------------------- .../settings/Report/ReportSettingsPage.js | 3 +-- src/pages/settings/Report/RoomNamePage.js | 10 +++----- 5 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js index 22b5d8635f72..22dfb1a357b5 100644 --- a/src/libs/PolicyUtils.js +++ b/src/libs/PolicyUtils.js @@ -3,6 +3,7 @@ import lodashGet from 'lodash/get'; import Str from 'expensify-common/lib/str'; import CONST from '../CONST'; import ONYXKEYS from '../ONYXKEYS'; +import * as Policy from "../libs/actions/Policy" /** * Checks if we have any errors stored within the POLICY_MEMBERS. Determines whether we should show a red brick road error or not. @@ -124,6 +125,16 @@ function getClientPolicyMemberEmailsToAccountIDs(policyMembers, personalDetails) return memberEmailsToAccountIDs; } +/** + * Is the user the member of the given policy? + * + * @param {Object} policy + * @returns {Boolean} + */ +function isPolicyMember(policy) { + return !Policy.isPolicyOwner(policy) && policy.role !== CONST.POLICY.ROLE.ADMIN; +} + export { hasPolicyMemberError, hasPolicyError, @@ -134,4 +145,5 @@ export { isExpensifyTeam, isPolicyAdmin, getClientPolicyMemberEmailsToAccountIDs, + isPolicyMember, }; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 831806f7fb89..e7026331760b 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -20,6 +20,7 @@ import isReportMessageAttachment from './isReportMessageAttachment'; import * as defaultWorkspaceAvatars from '../components/Icon/WorkspaceDefaultAvatars'; import * as CurrencyUtils from './CurrencyUtils'; import * as UserUtils from './UserUtils'; +import * as PolicyUtils from "./PolicyUtils" let currentUserEmail; let currentUserAccountID; @@ -2489,6 +2490,27 @@ function getOriginalReportID(reportID, reportAction) { return isThreadFirstChat(reportAction, reportID) ? lodashGet(allReports, [`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, 'parentReportID']) : reportID; } +/** + * @param {Object|null} report + * @param {Object|null} policy - the workspace the report is on, null if the user isn't a member of the workspace + * @returns {Boolean} + */ +function shouldDisableRename(report, policy) { + if (isDefaultRoom(report) || isArchivedRoom(report)) { + return true; + } + + // if the linked workspace is null, that means the person isn't a member of the workspace the report is in + // which means this has to be a public room we want to disable renaming for + if (!policy) { + return true; + } + + // If there is a linked workspace, that means the user is a member of the workspace the report is in. + // Still, we only want policy owners and admins to be able to modify the name. + return PolicyUtils.isPolicyMember(policy); +} + export { getReportParticipantsTitle, isReportMessageAttachment, @@ -2592,4 +2614,5 @@ export { shouldHideComposer, getOriginalReportID, canAccessReport, + shouldDisableRename, }; diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 76331fcec9e9..50761f7cb77d 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -176,27 +176,6 @@ function isPolicyMember(policy) { return !isPolicyOwner(policy) && policy.role !== CONST.POLICY.ROLE.ADMIN; } -/** - * @param {Object|null} linkedWorkspace - the workspace the report is on, null if the user isn't a member of the workspace - * @param {Object|null} report - * @returns {Boolean} - */ -function shouldDisableRename(linkedWorkspace, report) { - if (ReportUtils.isDefaultRoom(report) || ReportUtils.isArchivedRoom(report)) { - return true; - } - - // if the linked workspace is null, that means the person isn't a member of the workspace the report is in - // which means this has to be a public room we want to disable renaming for - if (!linkedWorkspace) { - return true; - } - - // If there is a linked workspace, that means the user is a member of the workspace the report is in. - // Still, we only want policy owners and admins to be able to modify the name. - return isPolicyMember(linkedWorkspace); -} - /** * Check if the user has any active free policies (aka workspaces) * @@ -1174,6 +1153,4 @@ export { removeWorkspace, setWorkspaceInviteMembersDraft, isPolicyOwner, - isPolicyMember, - shouldDisableRename, }; diff --git a/src/pages/settings/Report/ReportSettingsPage.js b/src/pages/settings/Report/ReportSettingsPage.js index ab42852dc9ed..c1eaaeed5e26 100644 --- a/src/pages/settings/Report/ReportSettingsPage.js +++ b/src/pages/settings/Report/ReportSettingsPage.js @@ -10,7 +10,6 @@ import styles from '../../../styles/styles'; import compose from '../../../libs/compose'; import Navigation from '../../../libs/Navigation/Navigation'; import * as Report from '../../../libs/actions/Report'; -import * as Policy from '../../../libs/actions/Policy'; import * as ReportUtils from '../../../libs/ReportUtils'; import HeaderWithBackButton from '../../../components/HeaderWithBackButton'; import ScreenWrapper from '../../../components/ScreenWrapper'; @@ -69,7 +68,7 @@ class ReportSettingsPage extends Component { render() { const shouldShowRoomName = !ReportUtils.isPolicyExpenseChat(this.props.report) && !ReportUtils.isChatThread(this.props.report); const linkedWorkspace = _.find(this.props.policies, (policy) => policy && policy.id === this.props.report.policyID); - const shouldDisableRename = Policy.shouldDisableRename(linkedWorkspace, this.props.report) || ReportUtils.isChatThread(this.props.report); + const shouldDisableRename = ReportUtils.shouldDisableRename(this.props.report, linkedWorkspace) || ReportUtils.isChatThread(this.props.report); const notificationPreference = this.props.translate(`notificationPreferencesPage.notificationPreferences.${this.props.report.notificationPreference}`); const shouldDisableWelcomeMessage = this.shouldDisableWelcomeMessage(linkedWorkspace); const writeCapability = ReportUtils.isAdminRoom(this.props.report) diff --git a/src/pages/settings/Report/RoomNamePage.js b/src/pages/settings/Report/RoomNamePage.js index 033f4406acd4..e9aa76635b08 100644 --- a/src/pages/settings/Report/RoomNamePage.js +++ b/src/pages/settings/Report/RoomNamePage.js @@ -18,7 +18,7 @@ import reportPropTypes from '../../reportPropTypes'; import ROUTES from '../../../ROUTES'; import * as Report from '../../../libs/actions/Report'; import RoomNameInput from '../../../components/RoomNameInput'; -import * as Policy from '../../../libs/actions/Policy'; +import * as ReportUtils from '../../../libs/ReportUtils'; import FullPageNotFoundView from '../../../components/BlockingViews/FullPageNotFoundView'; const propTypes = { @@ -78,12 +78,8 @@ function RoomNamePage(props) { ); return ( - roomNameInputRef.current && roomNameInputRef.current.focus()} - > - + + Navigation.goBack(ROUTES.getReportSettingsRoute(report.reportID))} From 45857408e8819aa20e8d0c8ca052b2d3417228fb Mon Sep 17 00:00:00 2001 From: Hans Date: Thu, 13 Jul 2023 16:13:57 +0700 Subject: [PATCH 10/14] fix linting --- src/libs/actions/Policy.js | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 50761f7cb77d..5b0afa1caf69 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -166,16 +166,6 @@ function isPolicyOwner(policy) { return _.keys(loginList).includes(policy.owner); } -/** - * Is the user the member of the given policy? - * - * @param {Object} policy - * @returns {Boolean} - */ -function isPolicyMember(policy) { - return !isPolicyOwner(policy) && policy.role !== CONST.POLICY.ROLE.ADMIN; -} - /** * Check if the user has any active free policies (aka workspaces) * From 229b7a835639c44d2fd5c15d6b9276eb931f97f7 Mon Sep 17 00:00:00 2001 From: Hans Date: Thu, 13 Jul 2023 16:32:11 +0700 Subject: [PATCH 11/14] remove dependency circle --- src/libs/PolicyUtils.js | 11 ----------- src/libs/ReportUtils.js | 9 +++++++-- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js index 22dfb1a357b5..0ea31763ccd0 100644 --- a/src/libs/PolicyUtils.js +++ b/src/libs/PolicyUtils.js @@ -3,7 +3,6 @@ import lodashGet from 'lodash/get'; import Str from 'expensify-common/lib/str'; import CONST from '../CONST'; import ONYXKEYS from '../ONYXKEYS'; -import * as Policy from "../libs/actions/Policy" /** * Checks if we have any errors stored within the POLICY_MEMBERS. Determines whether we should show a red brick road error or not. @@ -125,15 +124,6 @@ function getClientPolicyMemberEmailsToAccountIDs(policyMembers, personalDetails) return memberEmailsToAccountIDs; } -/** - * Is the user the member of the given policy? - * - * @param {Object} policy - * @returns {Boolean} - */ -function isPolicyMember(policy) { - return !Policy.isPolicyOwner(policy) && policy.role !== CONST.POLICY.ROLE.ADMIN; -} export { hasPolicyMemberError, @@ -145,5 +135,4 @@ export { isExpensifyTeam, isPolicyAdmin, getClientPolicyMemberEmailsToAccountIDs, - isPolicyMember, }; diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index e7026331760b..6e93d2c6cd01 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -20,7 +20,6 @@ import isReportMessageAttachment from './isReportMessageAttachment'; import * as defaultWorkspaceAvatars from '../components/Icon/WorkspaceDefaultAvatars'; import * as CurrencyUtils from './CurrencyUtils'; import * as UserUtils from './UserUtils'; -import * as PolicyUtils from "./PolicyUtils" let currentUserEmail; let currentUserAccountID; @@ -82,6 +81,12 @@ Onyx.connect({ callback: (val) => (allPolicies = val), }); +let loginList; +Onyx.connect({ + key: ONYXKEYS.LOGIN_LIST, + callback: (val) => (loginList = val), +}); + function getChatType(report) { return report ? report.chatType : ''; } @@ -2508,7 +2513,7 @@ function shouldDisableRename(report, policy) { // If there is a linked workspace, that means the user is a member of the workspace the report is in. // Still, we only want policy owners and admins to be able to modify the name. - return PolicyUtils.isPolicyMember(policy); + return !_.keys(loginList).includes(policy.owner) && policy.role !== CONST.POLICY.ROLE.ADMIN;; } export { From dd3d99f04e5044fc834a652dd3842c0cdd86e9f1 Mon Sep 17 00:00:00 2001 From: Hans Date: Thu, 13 Jul 2023 16:44:43 +0700 Subject: [PATCH 12/14] fix linting --- src/libs/PolicyUtils.js | 1 - src/libs/ReportUtils.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js index 0ea31763ccd0..22b5d8635f72 100644 --- a/src/libs/PolicyUtils.js +++ b/src/libs/PolicyUtils.js @@ -124,7 +124,6 @@ function getClientPolicyMemberEmailsToAccountIDs(policyMembers, personalDetails) return memberEmailsToAccountIDs; } - export { hasPolicyMemberError, hasPolicyError, diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 6e93d2c6cd01..d2d1a58f4575 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2513,7 +2513,7 @@ function shouldDisableRename(report, policy) { // If there is a linked workspace, that means the user is a member of the workspace the report is in. // Still, we only want policy owners and admins to be able to modify the name. - return !_.keys(loginList).includes(policy.owner) && policy.role !== CONST.POLICY.ROLE.ADMIN;; + return !_.keys(loginList).includes(policy.owner) && policy.role !== CONST.POLICY.ROLE.ADMIN; } export { From 4e02c35343a1f76716eb83c19493ac952352d240 Mon Sep 17 00:00:00 2001 From: Hans Date: Mon, 17 Jul 2023 20:12:04 +0700 Subject: [PATCH 13/14] fix lint --- src/pages/settings/Report/RoomNamePage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/settings/Report/RoomNamePage.js b/src/pages/settings/Report/RoomNamePage.js index 367d635307cc..a38edca4f110 100644 --- a/src/pages/settings/Report/RoomNamePage.js +++ b/src/pages/settings/Report/RoomNamePage.js @@ -82,7 +82,7 @@ function RoomNamePage(props) { onEntryTransitionEnd={() => roomNameInputRef.current && roomNameInputRef.current.focus()} includeSafeAreaPaddingBottom={false} > - + Navigation.goBack(ROUTES.getReportSettingsRoute(report.reportID))} From 00e18fcec1425c3bcfe1fe42e9cf36d1a208daa6 Mon Sep 17 00:00:00 2001 From: Hans Date: Tue, 18 Jul 2023 06:40:54 +0700 Subject: [PATCH 14/14] fix merge issue --- src/pages/settings/Report/RoomNamePage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/settings/Report/RoomNamePage.js b/src/pages/settings/Report/RoomNamePage.js index a38edca4f110..ee15a1649261 100644 --- a/src/pages/settings/Report/RoomNamePage.js +++ b/src/pages/settings/Report/RoomNamePage.js @@ -82,7 +82,7 @@ function RoomNamePage(props) { onEntryTransitionEnd={() => roomNameInputRef.current && roomNameInputRef.current.focus()} includeSafeAreaPaddingBottom={false} > - + Navigation.goBack(ROUTES.getReportSettingsRoute(report.reportID))}