From 48f0ad2549312516c2169b00eef45c4edc5b9043 Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Tue, 16 May 2023 08:08:52 -0700 Subject: [PATCH 01/20] Scaffold field for restricting commenting capabilities --- src/languages/en.js | 7 +++++++ src/pages/ReportSettingsPage.js | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/languages/en.js b/src/languages/en.js index c3543cd926e1..c2406cd823f9 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -296,6 +296,13 @@ export default { `This workspace chat is no longer active because ${displayName} is no longer a member of the ${policyName} workspace.`, [CONST.REPORT.ARCHIVE_REASON.POLICY_DELETED]: ({policyName}) => `This workspace chat is no longer active because ${policyName} is no longer an active workspace.`, }, + reportSettings: { + writeCapability: { + label: 'Who can post', + all: 'All members', + admins: 'Admins only', + }, + }, sidebarScreen: { fabAction: 'New chat', newChat: 'New chat', diff --git a/src/pages/ReportSettingsPage.js b/src/pages/ReportSettingsPage.js index cee26f37714b..8966bcf0859b 100644 --- a/src/pages/ReportSettingsPage.js +++ b/src/pages/ReportSettingsPage.js @@ -75,6 +75,13 @@ class ReportSettingsPage extends Component { ]; } + getWriteCapabilityOptions() { + return [ + {value: 'all', label: this.props.translate('reportSettings.writeCapability.all')}, + {value: 'admins', label: this.props.translate('reportSettings.writeCapability.admins')}, + ]; + } + /** * @param {Object|null} linkedWorkspace - the workspace the report is on, null if the user isn't a member of the workspace * @returns {Boolean} @@ -217,6 +224,23 @@ class ReportSettingsPage extends Component { )} + + + { + if (this.props.report.writeCapability === writeCapability) { + return; + } + + console.log(writeCapability); + // Report.updateWriteCapability(this.props.report.reportID, this.props.report.writeCapability, writeCapability); + }} + items={this.getWriteCapabilityOptions()} + value={this.props.report.writeCapability} + /> + + {Boolean(linkedWorkspace) && ( Date: Tue, 16 May 2023 13:40:51 -0700 Subject: [PATCH 02/20] Call API to update write capability setting --- src/libs/actions/Report.js | 24 ++++++++++++++++++++++++ src/pages/ReportSettingsPage.js | 3 +-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 6e8e5e0f962b..4dea100025d8 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1104,6 +1104,29 @@ function updateNotificationPreference(reportID, previousValue, newValue) { API.write('UpdateReportNotificationPreference', {reportID, notificationPreference: newValue}, {optimisticData, failureData}); } +/** + * @param {String} reportID + * @param {String} previousValue + * @param {String} newValue + */ +function updateWriteCapability(reportID, previousValue, newValue) { + const optimisticData = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: {writeCapability: newValue}, + }, + ]; + const failureData = [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + value: {writeCapability: previousValue}, + }, + ]; + API.write('UpdateReportWriteCapability', {reportID, writeCapability: newValue}, {optimisticData, failureData}); +} + /** * Navigates to the 1:1 report with Concierge */ @@ -1581,6 +1604,7 @@ export { addAttachment, reconnect, updateNotificationPreference, + updateWriteCapability, subscribeToReportTypingEvents, unsubscribeFromReportChannel, saveReportComment, diff --git a/src/pages/ReportSettingsPage.js b/src/pages/ReportSettingsPage.js index 8966bcf0859b..217f261f6ebf 100644 --- a/src/pages/ReportSettingsPage.js +++ b/src/pages/ReportSettingsPage.js @@ -233,8 +233,7 @@ class ReportSettingsPage extends Component { return; } - console.log(writeCapability); - // Report.updateWriteCapability(this.props.report.reportID, this.props.report.writeCapability, writeCapability); + Report.updateWriteCapability(this.props.report.reportID, this.props.report.writeCapability, writeCapability); }} items={this.getWriteCapabilityOptions()} value={this.props.report.writeCapability} From 18d734170134ce104fd75bd11eeff262be8607db Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Tue, 16 May 2023 14:07:14 -0700 Subject: [PATCH 03/20] Use CONST values for capability options --- src/CONST.js | 4 ++++ src/pages/ReportSettingsPage.js | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index e1335306d47a..e1fffde6d4e7 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -518,6 +518,10 @@ const CONST = { DAILY: 'daily', ALWAYS: 'always', }, + WRITE_CAPABILITIES: { + ALL: 'all', + ADMINS: 'admins', + }, VISIBILITY: { PUBLIC: 'public', PUBLIC_ANNOUNCE: 'public_announce', diff --git a/src/pages/ReportSettingsPage.js b/src/pages/ReportSettingsPage.js index 217f261f6ebf..7eb208028e0f 100644 --- a/src/pages/ReportSettingsPage.js +++ b/src/pages/ReportSettingsPage.js @@ -77,8 +77,8 @@ class ReportSettingsPage extends Component { getWriteCapabilityOptions() { return [ - {value: 'all', label: this.props.translate('reportSettings.writeCapability.all')}, - {value: 'admins', label: this.props.translate('reportSettings.writeCapability.admins')}, + {value: CONST.REPORT.WRITE_CAPABILITIES.ALL, label: this.props.translate('reportSettings.writeCapability.all')}, + {value: CONST.REPORT.WRITE_CAPABILITIES.ADMINS, label: this.props.translate('reportSettings.writeCapability.admins')}, ]; } From 4db2308444a0e14bfa9574e804d60aab79845ea8 Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Tue, 16 May 2023 14:25:58 -0700 Subject: [PATCH 04/20] Add spanish translations --- src/languages/es.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/languages/es.js b/src/languages/es.js index b936272d4622..99b44bd32d87 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -295,6 +295,13 @@ export default { `Este chat de espacio de trabajo esta desactivado porque ${displayName} ha dejado de ser miembro del espacio de trabajo ${policyName}.`, [CONST.REPORT.ARCHIVE_REASON.POLICY_DELETED]: ({policyName}) => `Este chat de espacio de trabajo esta desactivado porque el espacio de trabajo ${policyName} se ha eliminado.`, }, + reportSettings: { + writeCapability: { + label: 'Quién puede postear', + all: 'Todos los miembros', + admins: 'Solo administradores', + }, + }, sidebarScreen: { fabAction: 'Nuevo chat', newChat: 'Nuevo chat', From ab2075ded266c9f47458ff787278ab94598794c9 Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Tue, 16 May 2023 16:12:32 -0700 Subject: [PATCH 05/20] Hide composer if user is not allowed to post --- src/libs/ReportUtils.js | 25 +++++++++++++++++++++++++ src/pages/home/report/ReportFooter.js | 14 +++++++++++++- src/pages/reportPropTypes.js | 3 +++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 08ea0356eac6..680e2d836162 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -410,6 +410,30 @@ function getPolicyName(report) { return policy.name || report.oldPolicyName || Localize.translateLocal('workspace.common.unavailable'); } +/** + * Checks if the current user is allowed to comment on the given report. + * @param {Object} report + * @param {String} report.writeCapability + * @param {Object} policy + * @returns {Boolean} + */ +function isAllowedToComment(report, policy) { + // If the capability is unset, default to allowing all users to post + const capability = lodashGet(report, 'writeCapability', 'all'); + + if (capability === CONST.REPORT.WRITE_CAPABILITIES.ALL) { + return true; + } + + // If we've made it here, commenting on this report is restricted + // If the user is an admin, allow them to post + if (lodashGet(policy, 'role', '') === CONST.POLICY.ROLE.ADMIN) { + return true; + } + + return false; +} + /** * Checks if the current user is the admin of the policy given the policy expense chat. * @param {Object} report @@ -2147,4 +2171,5 @@ export { shouldReportShowSubscript, isReportDataReady, isSettled, + isAllowedToComment, }; diff --git a/src/pages/home/report/ReportFooter.js b/src/pages/home/report/ReportFooter.js index 15b89cb45082..08edcaab3da4 100644 --- a/src/pages/home/report/ReportFooter.js +++ b/src/pages/home/report/ReportFooter.js @@ -36,6 +36,12 @@ const propTypes = { /** The pending action when we are adding a chat */ pendingAction: PropTypes.string, + /** The policies which the user has access to and which the report could be tied to */ + policies: PropTypes.shape({ + /** Name of the policy */ + name: PropTypes.string, + }), + /** Whether the composer input should be shown */ shouldShowComposeInput: PropTypes.bool, @@ -51,6 +57,7 @@ const defaultProps = { onSubmitComment: () => {}, errors: {}, pendingAction: null, + policies: {}, shouldShowComposeInput: true, shouldDisableCompose: false, }; @@ -65,7 +72,9 @@ class ReportFooter extends React.Component { render() { const isArchivedRoom = ReportUtils.isArchivedRoom(this.props.report); - const hideComposer = isArchivedRoom || !_.isEmpty(this.props.errors) || ReportUtils.isTaskReport(this.props.report); + const linkedWorkspace = _.find(this.props.policies, (policy) => policy && policy.id === this.props.report.policyID); + const isAllowedToComment = ReportUtils.isAllowedToComment(this.props.report, linkedWorkspace); + const hideComposer = isArchivedRoom || !_.isEmpty(this.props.errors) || ReportUtils.isTaskReport(this.props.report) || !isAllowedToComment; return ( <> @@ -103,5 +112,8 @@ export default compose( withWindowDimensions, withOnyx({ shouldShowComposeInput: {key: ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT}, + policies: { + key: ONYXKEYS.COLLECTION.POLICY, + }, }), )(ReportFooter); diff --git a/src/pages/reportPropTypes.js b/src/pages/reportPropTypes.js index 17757480bbe7..bb7c197e8bf2 100644 --- a/src/pages/reportPropTypes.js +++ b/src/pages/reportPropTypes.js @@ -67,4 +67,7 @@ export default PropTypes.shape({ /** The status of the current report */ statusNum: PropTypes.oneOf(_.values(CONST.REPORT.STATUS)), + + /** Which user role is capable of posting messages on the report */ + writeCapability: PropTypes.oneOf(_.values(CONST.REPORT.WRITE_CAPABILITIES)), }); From 45ca54037cee3e43db0550113badc5380c0d576d Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Tue, 16 May 2023 16:43:45 -0700 Subject: [PATCH 06/20] Restrict editing of the field to admins --- src/pages/ReportSettingsPage.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/pages/ReportSettingsPage.js b/src/pages/ReportSettingsPage.js index 7eb208028e0f..664172718043 100644 --- a/src/pages/ReportSettingsPage.js +++ b/src/pages/ReportSettingsPage.js @@ -153,6 +153,7 @@ class ReportSettingsPage extends Component { const shouldShowRoomName = !ReportUtils.isPolicyExpenseChat(this.props.report); const linkedWorkspace = _.find(this.props.policies, (policy) => policy && policy.id === this.props.report.policyID); const shouldDisableRename = this.shouldDisableRename(linkedWorkspace); + const shouldAllowWriteCapabilityEditing = lodashGet(linkedWorkspace, 'role', '') === CONST.POLICY.ROLE.ADMIN; return ( @@ -226,18 +227,20 @@ class ReportSettingsPage extends Component { )} - { - if (this.props.report.writeCapability === writeCapability) { - return; - } + {shouldAllowWriteCapabilityEditing && ( + { + if (this.props.report.writeCapability === writeCapability) { + return; + } - Report.updateWriteCapability(this.props.report.reportID, this.props.report.writeCapability, writeCapability); - }} - items={this.getWriteCapabilityOptions()} - value={this.props.report.writeCapability} - /> + Report.updateWriteCapability(this.props.report.reportID, this.props.report.writeCapability, writeCapability); + }} + items={this.getWriteCapabilityOptions()} + value={this.props.report.writeCapability} + /> + )} {Boolean(linkedWorkspace) && ( From 3766b5a3520ffe47b3bebdd5262c27aaa0ab4c52 Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Tue, 16 May 2023 17:29:16 -0700 Subject: [PATCH 07/20] Show the setting as view-only for non-admins --- src/pages/ReportSettingsPage.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/pages/ReportSettingsPage.js b/src/pages/ReportSettingsPage.js index 664172718043..5e5fa39ebcb8 100644 --- a/src/pages/ReportSettingsPage.js +++ b/src/pages/ReportSettingsPage.js @@ -227,7 +227,7 @@ class ReportSettingsPage extends Component { )} - {shouldAllowWriteCapabilityEditing && ( + {shouldAllowWriteCapabilityEditing ? ( { @@ -240,6 +240,23 @@ class ReportSettingsPage extends Component { items={this.getWriteCapabilityOptions()} value={this.props.report.writeCapability} /> + ) : ( + + + {this.props.translate('reportSettings.writeCapability.label')} + + + {_.isEmpty(this.props.report.writeCapability) + ? this.props.translate('reportSettings.writeCapability.all') + : this.props.translate(`reportSettings.writeCapability.${this.props.report.writeCapability}`)} + + )} From eaa3b931d79121b369c6d11c2c00ec41083d68bf Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Tue, 16 May 2023 23:06:45 -0700 Subject: [PATCH 08/20] Remove task related check --- src/pages/home/report/ReportFooter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportFooter.js b/src/pages/home/report/ReportFooter.js index 08edcaab3da4..f4515d0bffea 100644 --- a/src/pages/home/report/ReportFooter.js +++ b/src/pages/home/report/ReportFooter.js @@ -74,7 +74,7 @@ class ReportFooter extends React.Component { const isArchivedRoom = ReportUtils.isArchivedRoom(this.props.report); const linkedWorkspace = _.find(this.props.policies, (policy) => policy && policy.id === this.props.report.policyID); const isAllowedToComment = ReportUtils.isAllowedToComment(this.props.report, linkedWorkspace); - const hideComposer = isArchivedRoom || !_.isEmpty(this.props.errors) || ReportUtils.isTaskReport(this.props.report) || !isAllowedToComment; + const hideComposer = isArchivedRoom || !_.isEmpty(this.props.errors) || !isAllowedToComment; return ( <> From daf53e38749233f46fab70d35e78bb7742f5182e Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Tue, 16 May 2023 23:14:12 -0700 Subject: [PATCH 09/20] Fix prettier style --- src/components/Pressable/PressableWithFeedback.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/components/Pressable/PressableWithFeedback.js b/src/components/Pressable/PressableWithFeedback.js index 0f4c07c63f64..9e475b7169cf 100644 --- a/src/components/Pressable/PressableWithFeedback.js +++ b/src/components/Pressable/PressableWithFeedback.js @@ -46,10 +46,9 @@ const PressableWithFeedback = forwardRef((props, ref) => { setDisabled(props.disabled); return; } - onPress - .finally(() => { - setDisabled(props.disabled); - }); + onPress.finally(() => { + setDisabled(props.disabled); + }); }); }} > From 5cebc092726433ed7152aa542be8e37fc4c26d4c Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Wed, 17 May 2023 10:41:15 -0700 Subject: [PATCH 10/20] Address PR feedback --- src/CONST.js | 1 + src/libs/ReportUtils.js | 10 ++---- src/pages/ReportSettingsPage.js | 64 ++++++++++++++++----------------- 3 files changed, 35 insertions(+), 40 deletions(-) diff --git a/src/CONST.js b/src/CONST.js index fbcdaa92f76b..991debe53e0e 100755 --- a/src/CONST.js +++ b/src/CONST.js @@ -576,6 +576,7 @@ const CONST = { DAILY: 'daily', ALWAYS: 'always', }, + // Options for which room members can post WRITE_CAPABILITIES: { ALL: 'all', ADMINS: 'admins', diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index bf55934c1029..657b5cecbf34 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -437,13 +437,9 @@ function isAllowedToComment(report, policy) { return true; } - // If we've made it here, commenting on this report is restricted - // If the user is an admin, allow them to post - if (lodashGet(policy, 'role', '') === CONST.POLICY.ROLE.ADMIN) { - return true; - } - - return false; + // If we've made it here, commenting on this report is restricted. + // If the user is an admin, allow them to post. + return lodashGet(policy, 'role', '') === CONST.POLICY.ROLE.ADMIN; } /** diff --git a/src/pages/ReportSettingsPage.js b/src/pages/ReportSettingsPage.js index 5e5fa39ebcb8..715d53c558c8 100644 --- a/src/pages/ReportSettingsPage.js +++ b/src/pages/ReportSettingsPage.js @@ -225,40 +225,38 @@ class ReportSettingsPage extends Component { )} - - - {shouldAllowWriteCapabilityEditing ? ( - { - if (this.props.report.writeCapability === writeCapability) { - return; - } + + {shouldAllowWriteCapabilityEditing ? ( + { + if (this.props.report.writeCapability === writeCapability) { + return; + } - Report.updateWriteCapability(this.props.report.reportID, this.props.report.writeCapability, writeCapability); - }} - items={this.getWriteCapabilityOptions()} - value={this.props.report.writeCapability} - /> - ) : ( - - - {this.props.translate('reportSettings.writeCapability.label')} - - - {_.isEmpty(this.props.report.writeCapability) - ? this.props.translate('reportSettings.writeCapability.all') - : this.props.translate(`reportSettings.writeCapability.${this.props.report.writeCapability}`)} - - - )} - + Report.updateWriteCapability(this.props.report.reportID, this.props.report.writeCapability, writeCapability); + }} + items={this.getWriteCapabilityOptions()} + value={this.props.report.writeCapability} + /> + ) : ( + + + {this.props.translate('reportSettings.writeCapability.label')} + + + {_.isEmpty(this.props.report.writeCapability) + ? this.props.translate('reportSettings.writeCapability.all') + : this.props.translate(`reportSettings.writeCapability.${this.props.report.writeCapability}`)} + + + )} {Boolean(linkedWorkspace) && ( From c9d1631aa412a24275f88b5440b9e2b38bd60045 Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Wed, 17 May 2023 11:06:18 -0700 Subject: [PATCH 11/20] Additional improvements per PR reviews --- src/libs/ReportUtils.js | 2 +- src/pages/ReportSettingsPage.js | 17 ++++++++++------- src/pages/home/report/ReportFooter.js | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 657b5cecbf34..1303cc843684 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -431,7 +431,7 @@ function getPolicyName(report) { */ function isAllowedToComment(report, policy) { // If the capability is unset, default to allowing all users to post - const capability = lodashGet(report, 'writeCapability', 'all'); + const capability = lodashGet(report, 'writeCapability', CONST.REPORT.WRITE_CAPABILITIES.ALL); if (capability === CONST.REPORT.WRITE_CAPABILITIES.ALL) { return true; diff --git a/src/pages/ReportSettingsPage.js b/src/pages/ReportSettingsPage.js index 715d53c558c8..b4350f7bbfd9 100644 --- a/src/pages/ReportSettingsPage.js +++ b/src/pages/ReportSettingsPage.js @@ -65,6 +65,7 @@ class ReportSettingsPage extends Component { super(props); this.validate = this.validate.bind(this); + this.updateWriteCapability = this.updateWriteCapability.bind(this); } getNotificationPreferenceOptions() { @@ -120,6 +121,14 @@ class ReportSettingsPage extends Component { Report.updatePolicyRoomName(this.props.report, values.newRoomName); } + updateWriteCapability(writeCapability) { + if (this.props.report.writeCapability === writeCapability) { + return; + } + + Report.updateWriteCapability(this.props.report.reportID, this.props.report.writeCapability, writeCapability); + } + /** * @param {Object} values - form input values passed by the Form component * @returns {Boolean} @@ -229,13 +238,7 @@ class ReportSettingsPage extends Component { {shouldAllowWriteCapabilityEditing ? ( { - if (this.props.report.writeCapability === writeCapability) { - return; - } - - Report.updateWriteCapability(this.props.report.reportID, this.props.report.writeCapability, writeCapability); - }} + onInputChange={this.updateWriteCapability} items={this.getWriteCapabilityOptions()} value={this.props.report.writeCapability} /> diff --git a/src/pages/home/report/ReportFooter.js b/src/pages/home/report/ReportFooter.js index f4515d0bffea..e84ee4275674 100644 --- a/src/pages/home/report/ReportFooter.js +++ b/src/pages/home/report/ReportFooter.js @@ -72,7 +72,7 @@ class ReportFooter extends React.Component { render() { const isArchivedRoom = ReportUtils.isArchivedRoom(this.props.report); - const linkedWorkspace = _.find(this.props.policies, (policy) => policy && policy.id === this.props.report.policyID); + const linkedWorkspace = _.findWhere(this.props.policies, {id: this.props.report.policyID}); const isAllowedToComment = ReportUtils.isAllowedToComment(this.props.report, linkedWorkspace); const hideComposer = isArchivedRoom || !_.isEmpty(this.props.errors) || !isAllowedToComment; From c146e0f96b27406d43a695c36b15fe66a9ba08af Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Wed, 17 May 2023 21:48:09 -0700 Subject: [PATCH 12/20] Refactor to push to page (WIP) --- src/ROUTES.js | 2 + .../AppNavigator/ModalStackNavigators.js | 7 ++ src/libs/Navigation/linkingConfig.js | 3 + src/libs/actions/Report.js | 10 ++- .../settings/Report/ReportSettingsPage.js | 27 ++++++++ .../settings/Report/WriteCapabilityPage.js | 66 +++++++++++++++++++ 6 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 src/pages/settings/Report/WriteCapabilityPage.js diff --git a/src/ROUTES.js b/src/ROUTES.js index 36af96003425..011294aaeccb 100644 --- a/src/ROUTES.js +++ b/src/ROUTES.js @@ -126,9 +126,11 @@ export default { REPORT_SETTINGS: 'r/:reportID/settings', REPORT_SETTINGS_ROOM_NAME: 'r/:reportID/settings/room-name', REPORT_SETTINGS_NOTIFICATION_PREFERENCES: 'r/:reportID/settings/notification-preferences', + REPORT_SETTINGS_WRITE_CAPABILITY: 'r/:reportID/settings/who-can-post', getReportSettingsRoute: (reportID) => `r/${reportID}/settings`, getReportSettingsRoomNameRoute: (reportID) => `r/${reportID}/settings/room-name`, getReportSettingsNotificationPreferencesRoute: (reportID) => `r/${reportID}/settings/notification-preferences`, + getReportSettingsWriteCapabilityRoute: (reportID) => `r/${reportID}/settings/who-can-post`, TRANSITION_FROM_OLD_DOT: 'transition', VALIDATE_LOGIN: 'v/:accountID/:validateCode', GET_ASSISTANCE: 'get-assistance/:taskID', diff --git a/src/libs/Navigation/AppNavigator/ModalStackNavigators.js b/src/libs/Navigation/AppNavigator/ModalStackNavigators.js index de821060b832..d8a6d8a94f63 100644 --- a/src/libs/Navigation/AppNavigator/ModalStackNavigators.js +++ b/src/libs/Navigation/AppNavigator/ModalStackNavigators.js @@ -191,6 +191,13 @@ const ReportSettingsModalStackNavigator = createModalStackNavigator([ }, name: 'Report_Settings_Notification_Preferences', }, + { + getComponent: () => { + const WriteCapabilityPage = require('../../../pages/settings/Report/WriteCapabilityPage').default; + return WriteCapabilityPage; + }, + name: 'Report_Settings_Write_Capability', + }, ]); const TaskModalStackNavigator = createModalStackNavigator([ diff --git a/src/libs/Navigation/linkingConfig.js b/src/libs/Navigation/linkingConfig.js index 1535880e8997..c071f52ad092 100644 --- a/src/libs/Navigation/linkingConfig.js +++ b/src/libs/Navigation/linkingConfig.js @@ -224,6 +224,9 @@ export default { Report_Settings_Notification_Preferences: { path: ROUTES.REPORT_SETTINGS_NOTIFICATION_PREFERENCES, }, + Report_Settings_Write_Capability: { + path: ROUTES.REPORT_SETTINGS_WRITE_CAPABILITY, + }, }, }, NewGroup: { diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index e781c7a4001a..22ea9c0e09cd 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1123,7 +1123,12 @@ function updateNotificationPreferenceAndNavigate(reportID, previousValue, newVal * @param {String} previousValue * @param {String} newValue */ -function updateWriteCapability(reportID, previousValue, newValue) { +function updateWriteCapabilityAndNavigate(reportID, previousValue, newValue) { + if (previousValue === newValue) { + Navigation.drawerGoBack(ROUTES.getReportSettingsRoute(reportID)); + return; + } + const optimisticData = [ { onyxMethod: Onyx.METHOD.MERGE, @@ -1139,6 +1144,7 @@ function updateWriteCapability(reportID, previousValue, newValue) { }, ]; API.write('UpdateReportWriteCapability', {reportID, writeCapability: newValue}, {optimisticData, failureData}); + Navigation.drawerGoBack(ROUTES.getReportSettingsRoute(reportID)); } /** @@ -1661,7 +1667,7 @@ export { addComment, addAttachment, reconnect, - updateWriteCapability, + updateWriteCapabilityAndNavigate, updateNotificationPreferenceAndNavigate, subscribeToReportTypingEvents, unsubscribeFromReportChannel, diff --git a/src/pages/settings/Report/ReportSettingsPage.js b/src/pages/settings/Report/ReportSettingsPage.js index 07ccf07d4db3..46011632cd50 100644 --- a/src/pages/settings/Report/ReportSettingsPage.js +++ b/src/pages/settings/Report/ReportSettingsPage.js @@ -84,6 +84,8 @@ class ReportSettingsPage extends Component { const linkedWorkspace = _.find(this.props.policies, (policy) => policy && policy.id === this.props.report.policyID); const shouldDisableRename = this.shouldDisableRename(linkedWorkspace) || ReportUtils.isThread(this.props.report); const notificationPreference = this.props.translate(`notificationPreferencesPage.notificationPreferences.${this.props.report.notificationPreference}`); + const writeCapability = this.props.translate(`reportSettings.writeCapability.${this.props.report.writeCapability}`); + const shouldAllowWriteCapabilityEditing = lodashGet(linkedWorkspace, 'role', '') === CONST.POLICY.ROLE.ADMIN; return ( @@ -131,6 +133,31 @@ class ReportSettingsPage extends Component { )} )} + {shouldAllowWriteCapabilityEditing ? ( + Navigation.navigate(ROUTES.getReportSettingsWriteCapabilityRoute(this.props.report.reportID))} + /> + ) : ( + + + {this.props.translate('reportSettings.writeCapability.label')} + + + {_.isEmpty(this.props.report.writeCapability) + ? this.props.translate('reportSettings.writeCapability.all') + : this.props.translate(`reportSettings.writeCapability.${this.props.report.writeCapability}`)} + + + )} {Boolean(linkedWorkspace) && ( diff --git a/src/pages/settings/Report/WriteCapabilityPage.js b/src/pages/settings/Report/WriteCapabilityPage.js new file mode 100644 index 000000000000..95ea23eed666 --- /dev/null +++ b/src/pages/settings/Report/WriteCapabilityPage.js @@ -0,0 +1,66 @@ +import React from 'react'; +import _ from 'underscore'; +import ScreenWrapper from '../../../components/ScreenWrapper'; +import HeaderWithCloseButton from '../../../components/HeaderWithCloseButton'; +import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize'; +import styles from '../../../styles/styles'; +import OptionsList from '../../../components/OptionsList'; +import Navigation from '../../../libs/Navigation/Navigation'; +import compose from '../../../libs/compose'; +import withReportOrNotFound from '../../home/report/withReportOrNotFound'; +import reportPropTypes from '../../reportPropTypes'; +import ROUTES from '../../../ROUTES'; +import * as Report from '../../../libs/actions/Report'; +import * as Expensicons from '../../../components/Icon/Expensicons'; +import themeColors from '../../../styles/themes/default'; + +const propTypes = { + ...withLocalizePropTypes, + + /** The report for which we are setting notification preferences */ + report: reportPropTypes.isRequired, +}; +const greenCheckmark = {src: Expensicons.Checkmark, color: themeColors.success}; + +const NotificationPreferencePage = (props) => { + const notificationPreferenceOptions = _.map(props.translate('notificationPreferencesPage.notificationPreferences'), (preference, key) => ({ + value: key, + text: preference, + keyForList: key, + + // Include the green checkmark icon to indicate the currently selected value + customIcon: key === props.report.notificationPreference ? greenCheckmark : null, + + // This property will make the currently selected value have bold text + boldStyle: key === props.report.notificationPreference, + })); + + return ( + + Navigation.navigate(ROUTES.getReportSettingsRoute(props.report.reportID))} + onCloseButtonPress={() => Navigation.dismissModal(true)} + /> + Report.updateNotificationPreferenceAndNavigate(props.report.reportID, props.report.notificationPreference, option.value)} + hideSectionHeaders + optionHoveredStyle={{ + ...styles.hoveredComponentBG, + ...styles.mhn5, + ...styles.ph5, + }} + shouldHaveOptionSeparator + shouldDisableRowInnerPadding + contentContainerStyles={[styles.ph5]} + /> + + ); +}; + +NotificationPreferencePage.displayName = 'NotificationPreferencePage'; +NotificationPreferencePage.propTypes = propTypes; + +export default compose(withLocalize, withReportOrNotFound)(NotificationPreferencePage); From ca689680320982c09d84540ef1df2dc5f74873ce Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Wed, 17 May 2023 21:55:09 -0700 Subject: [PATCH 13/20] Continue refactor: update page to reference correct values --- .../settings/Report/WriteCapabilityPage.js | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/pages/settings/Report/WriteCapabilityPage.js b/src/pages/settings/Report/WriteCapabilityPage.js index 95ea23eed666..d50a91e85f05 100644 --- a/src/pages/settings/Report/WriteCapabilityPage.js +++ b/src/pages/settings/Report/WriteCapabilityPage.js @@ -17,35 +17,35 @@ import themeColors from '../../../styles/themes/default'; const propTypes = { ...withLocalizePropTypes, - /** The report for which we are setting notification preferences */ + /** The report for which we are setting write capability */ report: reportPropTypes.isRequired, }; const greenCheckmark = {src: Expensicons.Checkmark, color: themeColors.success}; -const NotificationPreferencePage = (props) => { - const notificationPreferenceOptions = _.map(props.translate('notificationPreferencesPage.notificationPreferences'), (preference, key) => ({ +const WriteCapabilityPage = (props) => { + const writeCapabilityOptions = _.map(props.translate('reportSettings.writeCapability'), (preference, key) => ({ value: key, text: preference, keyForList: key, // Include the green checkmark icon to indicate the currently selected value - customIcon: key === props.report.notificationPreference ? greenCheckmark : null, + customIcon: key === props.report.writeCapability ? greenCheckmark : null, // This property will make the currently selected value have bold text - boldStyle: key === props.report.notificationPreference, + boldStyle: key === props.report.writeCapability, })); return ( Navigation.navigate(ROUTES.getReportSettingsRoute(props.report.reportID))} onCloseButtonPress={() => Navigation.dismissModal(true)} /> Report.updateNotificationPreferenceAndNavigate(props.report.reportID, props.report.notificationPreference, option.value)} + sections={[{data: writeCapabilityOptions}]} + onSelectRow={(option) => Report.updateWriteCapabilityAndNavigate(props.report.reportID, props.report.writeCapability, option.value)} hideSectionHeaders optionHoveredStyle={{ ...styles.hoveredComponentBG, @@ -60,7 +60,7 @@ const NotificationPreferencePage = (props) => { ); }; -NotificationPreferencePage.displayName = 'NotificationPreferencePage'; -NotificationPreferencePage.propTypes = propTypes; +WriteCapabilityPage.displayName = 'WriteCapabilityPage'; +WriteCapabilityPage.propTypes = propTypes; -export default compose(withLocalize, withReportOrNotFound)(NotificationPreferencePage); +export default compose(withLocalize, withReportOrNotFound)(WriteCapabilityPage); From d6324d2bbeae6091f4af53fb05893d0edff025bf Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Wed, 17 May 2023 22:02:30 -0700 Subject: [PATCH 14/20] Remove label from options list --- src/languages/en.js | 4 ++-- src/languages/es.js | 4 ++-- src/pages/settings/Report/ReportSettingsPage.js | 10 +++++----- src/pages/settings/Report/WriteCapabilityPage.js | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/languages/en.js b/src/languages/en.js index 9733cd838b18..611e4aaa7ed8 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -300,9 +300,9 @@ export default { `This workspace chat is no longer active because ${displayName} is no longer a member of the ${policyName} workspace.`, [CONST.REPORT.ARCHIVE_REASON.POLICY_DELETED]: ({policyName}) => `This workspace chat is no longer active because ${policyName} is no longer an active workspace.`, }, - reportSettings: { + writeCapabilityPage: { + label: 'Who can post', writeCapability: { - label: 'Who can post', all: 'All members', admins: 'Admins only', }, diff --git a/src/languages/es.js b/src/languages/es.js index 8f427ab715e9..d3df14260b98 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -299,9 +299,9 @@ export default { `Este chat de espacio de trabajo esta desactivado porque ${displayName} ha dejado de ser miembro del espacio de trabajo ${policyName}.`, [CONST.REPORT.ARCHIVE_REASON.POLICY_DELETED]: ({policyName}) => `Este chat de espacio de trabajo esta desactivado porque el espacio de trabajo ${policyName} se ha eliminado.`, }, - reportSettings: { + writeCapabilityPage: { + label: 'Quién puede postear', writeCapability: { - label: 'Quién puede postear', all: 'Todos los miembros', admins: 'Solo administradores', }, diff --git a/src/pages/settings/Report/ReportSettingsPage.js b/src/pages/settings/Report/ReportSettingsPage.js index 46011632cd50..6790bdcead2f 100644 --- a/src/pages/settings/Report/ReportSettingsPage.js +++ b/src/pages/settings/Report/ReportSettingsPage.js @@ -84,7 +84,7 @@ class ReportSettingsPage extends Component { const linkedWorkspace = _.find(this.props.policies, (policy) => policy && policy.id === this.props.report.policyID); const shouldDisableRename = this.shouldDisableRename(linkedWorkspace) || ReportUtils.isThread(this.props.report); const notificationPreference = this.props.translate(`notificationPreferencesPage.notificationPreferences.${this.props.report.notificationPreference}`); - const writeCapability = this.props.translate(`reportSettings.writeCapability.${this.props.report.writeCapability}`); + const writeCapability = this.props.translate(`writeCapabilityPage.writeCapability.${this.props.report.writeCapability}`); const shouldAllowWriteCapabilityEditing = lodashGet(linkedWorkspace, 'role', '') === CONST.POLICY.ROLE.ADMIN; return ( @@ -137,7 +137,7 @@ class ReportSettingsPage extends Component { Navigation.navigate(ROUTES.getReportSettingsWriteCapabilityRoute(this.props.report.reportID))} /> ) : ( @@ -146,15 +146,15 @@ class ReportSettingsPage extends Component { style={[styles.textLabelSupporting, styles.lh16, styles.mb1]} numberOfLines={1} > - {this.props.translate('reportSettings.writeCapability.label')} + {this.props.translate('writeCapabilityPage.label')} {_.isEmpty(this.props.report.writeCapability) - ? this.props.translate('reportSettings.writeCapability.all') - : this.props.translate(`reportSettings.writeCapability.${this.props.report.writeCapability}`)} + ? this.props.translate('writeCapabilityPage.writeCapability.all') + : this.props.translate(`writeCapabilityPage.writeCapability.${this.props.report.writeCapability}`)} )} diff --git a/src/pages/settings/Report/WriteCapabilityPage.js b/src/pages/settings/Report/WriteCapabilityPage.js index d50a91e85f05..cc7b4cdf87c7 100644 --- a/src/pages/settings/Report/WriteCapabilityPage.js +++ b/src/pages/settings/Report/WriteCapabilityPage.js @@ -23,7 +23,7 @@ const propTypes = { const greenCheckmark = {src: Expensicons.Checkmark, color: themeColors.success}; const WriteCapabilityPage = (props) => { - const writeCapabilityOptions = _.map(props.translate('reportSettings.writeCapability'), (preference, key) => ({ + const writeCapabilityOptions = _.map(props.translate('writeCapabilityPage.writeCapability'), (preference, key) => ({ value: key, text: preference, keyForList: key, @@ -38,7 +38,7 @@ const WriteCapabilityPage = (props) => { return ( Navigation.navigate(ROUTES.getReportSettingsRoute(props.report.reportID))} onCloseButtonPress={() => Navigation.dismissModal(true)} From 2a27962a68abf4a5bfafde332bb705abf39fa669 Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Thu, 18 May 2023 11:22:57 -0700 Subject: [PATCH 15/20] Improve comment and JS Doc --- src/libs/ReportUtils.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index d89dc3619c41..6de435a7f49b 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -437,10 +437,11 @@ function getPolicyName(report) { * @param {Object} report * @param {String} report.writeCapability * @param {Object} policy + * @param {String} policy.role * @returns {Boolean} */ function isAllowedToComment(report, policy) { - // If the capability is unset, default to allowing all users to post + // Default to allowing all users to post const capability = lodashGet(report, 'writeCapability', CONST.REPORT.WRITE_CAPABILITIES.ALL); if (capability === CONST.REPORT.WRITE_CAPABILITIES.ALL) { From a789f273b411360697b905bcc214226235e6c2a8 Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Thu, 18 May 2023 11:23:18 -0700 Subject: [PATCH 16/20] Prevent crash due to undefined translation --- src/pages/settings/Report/ReportSettingsPage.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/pages/settings/Report/ReportSettingsPage.js b/src/pages/settings/Report/ReportSettingsPage.js index 6790bdcead2f..6e3b460411de 100644 --- a/src/pages/settings/Report/ReportSettingsPage.js +++ b/src/pages/settings/Report/ReportSettingsPage.js @@ -84,7 +84,8 @@ class ReportSettingsPage extends Component { const linkedWorkspace = _.find(this.props.policies, (policy) => policy && policy.id === this.props.report.policyID); const shouldDisableRename = this.shouldDisableRename(linkedWorkspace) || ReportUtils.isThread(this.props.report); const notificationPreference = this.props.translate(`notificationPreferencesPage.notificationPreferences.${this.props.report.notificationPreference}`); - const writeCapability = this.props.translate(`writeCapabilityPage.writeCapability.${this.props.report.writeCapability}`); + const writeCapability = this.props.report.writeCapability || CONST.REPORT.WRITE_CAPABILITIES.ALL; + const writeCapabilityText = this.props.translate(`writeCapabilityPage.writeCapability.${writeCapability}`); const shouldAllowWriteCapabilityEditing = lodashGet(linkedWorkspace, 'role', '') === CONST.POLICY.ROLE.ADMIN; return ( @@ -136,7 +137,7 @@ class ReportSettingsPage extends Component { {shouldAllowWriteCapabilityEditing ? ( Navigation.navigate(ROUTES.getReportSettingsWriteCapabilityRoute(this.props.report.reportID))} /> @@ -152,9 +153,7 @@ class ReportSettingsPage extends Component { numberOfLines={1} style={[styles.optionAlternateText, styles.pre]} > - {_.isEmpty(this.props.report.writeCapability) - ? this.props.translate('writeCapabilityPage.writeCapability.all') - : this.props.translate(`writeCapabilityPage.writeCapability.${this.props.report.writeCapability}`)} + {writeCapabilityText} )} From 2596a29d63142551a4944ea8aa20d905224d0e24 Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Fri, 19 May 2023 15:09:24 -0700 Subject: [PATCH 17/20] Fix bug where default option isn't highlighted --- src/pages/settings/Report/WriteCapabilityPage.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/settings/Report/WriteCapabilityPage.js b/src/pages/settings/Report/WriteCapabilityPage.js index cc7b4cdf87c7..0da23c401e3e 100644 --- a/src/pages/settings/Report/WriteCapabilityPage.js +++ b/src/pages/settings/Report/WriteCapabilityPage.js @@ -1,5 +1,6 @@ import React from 'react'; import _ from 'underscore'; +import CONST from '../../../CONST'; import ScreenWrapper from '../../../components/ScreenWrapper'; import HeaderWithCloseButton from '../../../components/HeaderWithCloseButton'; import withLocalize, {withLocalizePropTypes} from '../../../components/withLocalize'; @@ -29,10 +30,10 @@ const WriteCapabilityPage = (props) => { keyForList: key, // Include the green checkmark icon to indicate the currently selected value - customIcon: key === props.report.writeCapability ? greenCheckmark : null, + customIcon: key === (props.report.writeCapability || CONST.REPORT.WRITE_CAPABILITIES.ALL) ? greenCheckmark : null, // This property will make the currently selected value have bold text - boldStyle: key === props.report.writeCapability, + boldStyle: key === (props.report.writeCapability || CONST.REPORT.WRITE_CAPABILITIES.ALL), })); return ( From 326340abbebbd2360eddd7cde0c7da4d226daa21 Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Fri, 19 May 2023 15:17:38 -0700 Subject: [PATCH 18/20] Map over CONST values for better stability --- src/pages/settings/Report/WriteCapabilityPage.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pages/settings/Report/WriteCapabilityPage.js b/src/pages/settings/Report/WriteCapabilityPage.js index 0da23c401e3e..8e1aa2cf640e 100644 --- a/src/pages/settings/Report/WriteCapabilityPage.js +++ b/src/pages/settings/Report/WriteCapabilityPage.js @@ -24,16 +24,16 @@ const propTypes = { const greenCheckmark = {src: Expensicons.Checkmark, color: themeColors.success}; const WriteCapabilityPage = (props) => { - const writeCapabilityOptions = _.map(props.translate('writeCapabilityPage.writeCapability'), (preference, key) => ({ - value: key, - text: preference, - keyForList: key, + const writeCapabilityOptions = _.map(CONST.REPORT.WRITE_CAPABILITIES, (value) => ({ + value, + text: props.translate(`writeCapabilityPage.writeCapability.${value}`), + keyForList: value, // Include the green checkmark icon to indicate the currently selected value - customIcon: key === (props.report.writeCapability || CONST.REPORT.WRITE_CAPABILITIES.ALL) ? greenCheckmark : null, + customIcon: value === (props.report.writeCapability || CONST.REPORT.WRITE_CAPABILITIES.ALL) ? greenCheckmark : null, // This property will make the currently selected value have bold text - boldStyle: key === (props.report.writeCapability || CONST.REPORT.WRITE_CAPABILITIES.ALL), + boldStyle: value === (props.report.writeCapability || CONST.REPORT.WRITE_CAPABILITIES.ALL), })); return ( From 6d71a73224be87ec29a5987eeb1eedb458b7b130 Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Fri, 19 May 2023 15:36:01 -0700 Subject: [PATCH 19/20] Pass policies as prop --- src/pages/home/ReportScreen.js | 1 + src/pages/home/report/ReportFooter.js | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 5ae3b0e8e294..223606dc30c3 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -359,6 +359,7 @@ class ReportScreen extends React.Component { report={this.props.report} isComposerFullSize={this.props.isComposerFullSize} onSubmitComment={this.onSubmitComment} + policies={this.props.policies} /> )} diff --git a/src/pages/home/report/ReportFooter.js b/src/pages/home/report/ReportFooter.js index e84ee4275674..a8ee48adec49 100644 --- a/src/pages/home/report/ReportFooter.js +++ b/src/pages/home/report/ReportFooter.js @@ -112,8 +112,5 @@ export default compose( withWindowDimensions, withOnyx({ shouldShowComposeInput: {key: ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT}, - policies: { - key: ONYXKEYS.COLLECTION.POLICY, - }, }), )(ReportFooter); From aec2afbed65e48d23b4979bc833f6621f4ea6043 Mon Sep 17 00:00:00 2001 From: Amy Evans Date: Mon, 22 May 2023 22:05:26 -0400 Subject: [PATCH 20/20] Implement additional code review feedback --- src/libs/ReportUtils.js | 9 ++++----- src/libs/actions/Report.js | 20 +++++++++---------- src/pages/home/report/ReportFooter.js | 10 +--------- .../settings/Report/WriteCapabilityPage.js | 2 +- 4 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index f3446be2fd9d..835330ca3ca0 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -435,14 +435,12 @@ function getPolicyName(report) { /** * Checks if the current user is allowed to comment on the given report. * @param {Object} report - * @param {String} report.writeCapability - * @param {Object} policy - * @param {String} policy.role + * @param {String} [report.writeCapability] * @returns {Boolean} */ -function isAllowedToComment(report, policy) { +function isAllowedToComment(report) { // Default to allowing all users to post - const capability = lodashGet(report, 'writeCapability', CONST.REPORT.WRITE_CAPABILITIES.ALL); + const capability = lodashGet(report, 'writeCapability', CONST.REPORT.WRITE_CAPABILITIES.ALL) || CONST.REPORT.WRITE_CAPABILITIES.ALL; if (capability === CONST.REPORT.WRITE_CAPABILITIES.ALL) { return true; @@ -450,6 +448,7 @@ function isAllowedToComment(report, policy) { // If we've made it here, commenting on this report is restricted. // If the user is an admin, allow them to post. + const policy = allPolicies[`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`]; return lodashGet(policy, 'role', '') === CONST.POLICY.ROLE.ADMIN; } diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 4293842bbf9e..42e3b3cfc1f4 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1119,32 +1119,32 @@ function updateNotificationPreferenceAndNavigate(reportID, previousValue, newVal } /** - * @param {String} reportID - * @param {String} previousValue + * @param {Object} report * @param {String} newValue */ -function updateWriteCapabilityAndNavigate(reportID, previousValue, newValue) { - if (previousValue === newValue) { - Navigation.drawerGoBack(ROUTES.getReportSettingsRoute(reportID)); +function updateWriteCapabilityAndNavigate(report, newValue) { + if (report.writeCapability === newValue) { + Navigation.drawerGoBack(ROUTES.getReportSettingsRoute(report.reportID)); return; } const optimisticData = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + key: `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, value: {writeCapability: newValue}, }, ]; const failureData = [ { onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - value: {writeCapability: previousValue}, + key: `${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`, + value: {writeCapability: report.writeCapability}, }, ]; - API.write('UpdateReportWriteCapability', {reportID, writeCapability: newValue}, {optimisticData, failureData}); - Navigation.drawerGoBack(ROUTES.getReportSettingsRoute(reportID)); + API.write('UpdateReportWriteCapability', {reportID: report.reportID, writeCapability: newValue}, {optimisticData, failureData}); + // Return to the report settings page since this field utilizes push-to-page + Navigation.drawerGoBack(ROUTES.getReportSettingsRoute(report.reportID)); } /** diff --git a/src/pages/home/report/ReportFooter.js b/src/pages/home/report/ReportFooter.js index a8ee48adec49..cdaad9b5ffc2 100644 --- a/src/pages/home/report/ReportFooter.js +++ b/src/pages/home/report/ReportFooter.js @@ -36,12 +36,6 @@ const propTypes = { /** The pending action when we are adding a chat */ pendingAction: PropTypes.string, - /** The policies which the user has access to and which the report could be tied to */ - policies: PropTypes.shape({ - /** Name of the policy */ - name: PropTypes.string, - }), - /** Whether the composer input should be shown */ shouldShowComposeInput: PropTypes.bool, @@ -57,7 +51,6 @@ const defaultProps = { onSubmitComment: () => {}, errors: {}, pendingAction: null, - policies: {}, shouldShowComposeInput: true, shouldDisableCompose: false, }; @@ -72,8 +65,7 @@ class ReportFooter extends React.Component { render() { const isArchivedRoom = ReportUtils.isArchivedRoom(this.props.report); - const linkedWorkspace = _.findWhere(this.props.policies, {id: this.props.report.policyID}); - const isAllowedToComment = ReportUtils.isAllowedToComment(this.props.report, linkedWorkspace); + const isAllowedToComment = ReportUtils.isAllowedToComment(this.props.report); const hideComposer = isArchivedRoom || !_.isEmpty(this.props.errors) || !isAllowedToComment; return ( diff --git a/src/pages/settings/Report/WriteCapabilityPage.js b/src/pages/settings/Report/WriteCapabilityPage.js index 8e1aa2cf640e..40246f29aadc 100644 --- a/src/pages/settings/Report/WriteCapabilityPage.js +++ b/src/pages/settings/Report/WriteCapabilityPage.js @@ -46,7 +46,7 @@ const WriteCapabilityPage = (props) => { /> Report.updateWriteCapabilityAndNavigate(props.report.reportID, props.report.writeCapability, option.value)} + onSelectRow={(option) => Report.updateWriteCapabilityAndNavigate(props.report, option.value)} hideSectionHeaders optionHoveredStyle={{ ...styles.hoveredComponentBG,