diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 1059ece66586..88295446c498 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -81,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 : ''; } @@ -2530,6 +2536,27 @@ function getReportOfflinePendingActionAndErrors(report) { return {addWorkspaceRoomOrChatPendingAction, addWorkspaceRoomOrChatErrors}; } +/** + * @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 !_.keys(loginList).includes(policy.owner) && policy.role !== CONST.POLICY.ROLE.ADMIN; +} + export { getReportParticipantsTitle, isReportMessageAttachment, @@ -2635,4 +2662,5 @@ export { getOriginalReportID, canAccessReport, getReportOfflinePendingActionAndErrors, + shouldDisableRename, }; diff --git a/src/pages/settings/Report/ReportSettingsPage.js b/src/pages/settings/Report/ReportSettingsPage.js index 7f246a346c56..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'; @@ -56,31 +55,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; - } - - // 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) { - 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.isPolicyOwner(linkedWorkspace) && linkedWorkspace.role !== CONST.POLICY.ROLE.ADMIN; - } - /** * We only want policy owners and admins to be able to modify the welcome message. * @@ -94,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 = this.shouldDisableRename(linkedWorkspace) || 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 7b56f6655ecb..ee15a1649261 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, @@ -27,12 +29,20 @@ 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, + }), }; const defaultProps = { reports: {}, + policy: {}, }; function RoomNamePage(props) { + const policy = props.policy; const report = props.report; const reports = props.reports; const translate = props.translate; @@ -69,30 +79,31 @@ function RoomNamePage(props) { return ( roomNameInputRef.current && roomNameInputRef.current.focus()} + includeSafeAreaPaddingBottom={false} > - Navigation.goBack(ROUTES.getReportSettingsRoute(report.reportID))} - /> -
Report.updatePolicyRoomNameAndNavigate(report, values.roomName)} - validate={validate} - submitButtonText={translate('common.save')} - enabledWhenOffline - > - - (roomNameInputRef.current = ref)} - inputID="roomName" - defaultValue={report.reportName} - /> - -
+ + Navigation.goBack(ROUTES.getReportSettingsRoute(report.reportID))} + /> +
Report.updatePolicyRoomNameAndNavigate(report, values.roomName)} + validate={validate} + submitButtonText={translate('common.save')} + enabledWhenOffline + > + + (roomNameInputRef.current = ref)} + inputID="roomName" + defaultValue={report.reportName} + /> + +
+
); } @@ -108,5 +119,8 @@ export default compose( reports: { key: ONYXKEYS.COLLECTION.REPORT, }, + policy: { + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, + }, }), )(RoomNamePage);