From b0ac8500eba5dea75ce7fe34232bec64c1b43650 Mon Sep 17 00:00:00 2001 From: someone-here Date: Thu, 13 Jul 2023 21:44:02 +0530 Subject: [PATCH 1/5] Restrict workspace settings to admins --- src/pages/ReportWelcomeMessagePage.js | 25 ++++++++++-- src/pages/policyPropType.js | 40 +++++++++++++++++++ .../settings/Report/WriteCapabilityPage.js | 27 ++++++++++++- src/pages/workspace/withPolicy.js | 39 +----------------- 4 files changed, 89 insertions(+), 42 deletions(-) create mode 100644 src/pages/policyPropType.js diff --git a/src/pages/ReportWelcomeMessagePage.js b/src/pages/ReportWelcomeMessagePage.js index 541a7119eb1c..2b0a3522adc6 100644 --- a/src/pages/ReportWelcomeMessagePage.js +++ b/src/pages/ReportWelcomeMessagePage.js @@ -1,6 +1,6 @@ import React, {useCallback, useRef, useState} from 'react'; import PropTypes from 'prop-types'; -import _ from 'underscore'; +import {withOnyx} from 'react-native-onyx'; import {View} from 'react-native'; import ExpensiMark from 'expensify-common/lib/ExpensiMark'; import compose from '../libs/compose'; @@ -17,6 +17,8 @@ import ONYXKEYS from '../ONYXKEYS'; import CONST from '../CONST'; import FullPageNotFoundView from '../components/BlockingViews/FullPageNotFoundView'; import Form from '../components/Form'; +import * as PolicyUtils from '../libs/PolicyUtils'; +import policyPropType from './policyPropType'; const propTypes = { ...withLocalizePropTypes, @@ -31,6 +33,12 @@ const propTypes = { reportID: PropTypes.string, }), }).isRequired, + + policy: PropTypes.objectOf(policyPropType), +}; + +const defaultProps = { + policy: {}, }; function ReportWelcomeMessagePage(props) { @@ -55,7 +63,7 @@ function ReportWelcomeMessagePage(props) { welcomeMessageInputRef.current.focus(); }} > - +
`${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, + }, + }), +)(ReportWelcomeMessagePage); diff --git a/src/pages/policyPropType.js b/src/pages/policyPropType.js new file mode 100644 index 000000000000..6bacb28c84e5 --- /dev/null +++ b/src/pages/policyPropType.js @@ -0,0 +1,40 @@ +import _ from 'underscore'; +import PropTypes from 'prop-types'; +import CONST from '../CONST'; + +export default PropTypes.shape({ + /** The ID of the policy */ + id: PropTypes.string, + + /** The name of the policy */ + name: PropTypes.string, + + /** The current user's role in the policy */ + role: PropTypes.oneOf(_.values(CONST.POLICY.ROLE)), + + /** The policy type */ + type: PropTypes.oneOf(_.values(CONST.POLICY.TYPE)), + + /** The email of the policy owner */ + owner: PropTypes.string, + + /** The output currency for the policy */ + outputCurrency: PropTypes.string, + + /** The URL for the policy avatar */ + avatar: PropTypes.string, + + /** Errors on the policy keyed by microtime */ + errors: PropTypes.objectOf(PropTypes.string), + + /** + * Error objects keyed by field name containing errors keyed by microtime + * E.x + * { + * name: { + * [DateUtils.getMicroseconds()]: 'Sorry, there was an unexpected problem updating your workspace name.', + * } + * } + */ + errorFields: PropTypes.objectOf(PropTypes.objectOf(PropTypes.string)), +}); diff --git a/src/pages/settings/Report/WriteCapabilityPage.js b/src/pages/settings/Report/WriteCapabilityPage.js index bfec919fddc8..9adff38b8c2e 100644 --- a/src/pages/settings/Report/WriteCapabilityPage.js +++ b/src/pages/settings/Report/WriteCapabilityPage.js @@ -1,5 +1,8 @@ import React from 'react'; import _ from 'underscore'; +import PropTypes from 'prop-types'; +import {withOnyx} from 'react-native-onyx'; +import ONYXKEYS from '../../../ONYXKEYS'; import CONST from '../../../CONST'; import ScreenWrapper from '../../../components/ScreenWrapper'; import HeaderWithBackButton from '../../../components/HeaderWithBackButton'; @@ -16,13 +19,22 @@ import * as Expensicons from '../../../components/Icon/Expensicons'; import themeColors from '../../../styles/themes/default'; import * as ReportUtils from '../../../libs/ReportUtils'; import FullPageNotFoundView from '../../../components/BlockingViews/FullPageNotFoundView'; +import * as PolicyUtils from '../../../libs/PolicyUtils'; +import policyPropType from '../../policyPropType'; const propTypes = { ...withLocalizePropTypes, /** The report for which we are setting write capability */ report: reportPropTypes.isRequired, + + policy: PropTypes.objectOf(policyPropType), +}; + +const defaultProps = { + policy: {}, }; + const greenCheckmark = {src: Expensicons.Checkmark, color: themeColors.success}; function WriteCapabilityPage(props) { @@ -38,9 +50,11 @@ function WriteCapabilityPage(props) { boldStyle: value === (props.report.writeCapability || CONST.REPORT.WRITE_CAPABILITIES.ALL), })); + const canAccess = !ReportUtils.isAdminRoom(props.report) && PolicyUtils.isPolicyAdmin(props.policy); + return ( - + `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`, + }, + }), +)(WriteCapabilityPage); diff --git a/src/pages/workspace/withPolicy.js b/src/pages/workspace/withPolicy.js index b1659ea2b7a6..5cf70df79605 100644 --- a/src/pages/workspace/withPolicy.js +++ b/src/pages/workspace/withPolicy.js @@ -4,11 +4,11 @@ import React from 'react'; import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; import {useNavigationState} from '@react-navigation/native'; -import CONST from '../../CONST'; import getComponentDisplayName from '../../libs/getComponentDisplayName'; import * as Policy from '../../libs/actions/Policy'; import ONYXKEYS from '../../ONYXKEYS'; import policyMemberPropType from '../policyMemberPropType'; +import policyPropType from '../policyPropType'; /** * @param {Object} route @@ -20,42 +20,7 @@ function getPolicyIDFromRoute(route) { const policyPropTypes = { /** The policy object for the current route */ - policy: PropTypes.shape({ - /** The ID of the policy */ - id: PropTypes.string, - - /** The name of the policy */ - name: PropTypes.string, - - /** The current user's role in the policy */ - role: PropTypes.oneOf(_.values(CONST.POLICY.ROLE)), - - /** The policy type */ - type: PropTypes.oneOf(_.values(CONST.POLICY.TYPE)), - - /** The email of the policy owner */ - owner: PropTypes.string, - - /** The output currency for the policy */ - outputCurrency: PropTypes.string, - - /** The URL for the policy avatar */ - avatar: PropTypes.string, - - /** Errors on the policy keyed by microtime */ - errors: PropTypes.objectOf(PropTypes.string), - - /** - * Error objects keyed by field name containing errors keyed by microtime - * E.x - * { - * name: { - * [DateUtils.getMicroseconds()]: 'Sorry, there was an unexpected problem updating your workspace name.', - * } - * } - */ - errorFields: PropTypes.objectOf(PropTypes.objectOf(PropTypes.string)), - }), + policy: PropTypes.objectOf(policyPropType), /** The employee list of this policy */ policyMembers: PropTypes.objectOf(policyMemberPropType), From 6192d757bcd44f24310334a23e224ef577a6e66e Mon Sep 17 00:00:00 2001 From: someone-here Date: Thu, 13 Jul 2023 22:30:46 +0530 Subject: [PATCH 2/5] Add policy prop comment --- src/pages/ReportWelcomeMessagePage.js | 1 + src/pages/settings/Report/WriteCapabilityPage.js | 1 + 2 files changed, 2 insertions(+) diff --git a/src/pages/ReportWelcomeMessagePage.js b/src/pages/ReportWelcomeMessagePage.js index 2b0a3522adc6..6dafb9e1f935 100644 --- a/src/pages/ReportWelcomeMessagePage.js +++ b/src/pages/ReportWelcomeMessagePage.js @@ -34,6 +34,7 @@ const propTypes = { }), }).isRequired, + /** The policy of which the room os a part of */ policy: PropTypes.objectOf(policyPropType), }; diff --git a/src/pages/settings/Report/WriteCapabilityPage.js b/src/pages/settings/Report/WriteCapabilityPage.js index 9adff38b8c2e..a871d08bb0b6 100644 --- a/src/pages/settings/Report/WriteCapabilityPage.js +++ b/src/pages/settings/Report/WriteCapabilityPage.js @@ -28,6 +28,7 @@ const propTypes = { /** The report for which we are setting write capability */ report: reportPropTypes.isRequired, + /** The policy of which the room os a part of */ policy: PropTypes.objectOf(policyPropType), }; From fd82b351c0aa2f1f6ebf53da2110e4bdeefb0cca Mon Sep 17 00:00:00 2001 From: someone-here Date: Thu, 13 Jul 2023 22:35:51 +0530 Subject: [PATCH 3/5] whitespace difference --- src/pages/settings/Report/WriteCapabilityPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/settings/Report/WriteCapabilityPage.js b/src/pages/settings/Report/WriteCapabilityPage.js index a871d08bb0b6..af4dc331a9cf 100644 --- a/src/pages/settings/Report/WriteCapabilityPage.js +++ b/src/pages/settings/Report/WriteCapabilityPage.js @@ -28,7 +28,7 @@ const propTypes = { /** The report for which we are setting write capability */ report: reportPropTypes.isRequired, - /** The policy of which the room os a part of */ + /** The policy of which the room os a part of */ policy: PropTypes.objectOf(policyPropType), }; From 2d0b25dc3e8c2de8a229ab639c9adb8c864105de Mon Sep 17 00:00:00 2001 From: someone-here Date: Fri, 14 Jul 2023 20:10:19 +0530 Subject: [PATCH 4/5] prop-type fix --- src/pages/ReportWelcomeMessagePage.js | 6 +-- src/pages/policyPropType.js | 40 ------------------- .../settings/Report/WriteCapabilityPage.js | 10 ++--- src/pages/workspace/withPolicy.js | 39 +++++++++++++++++- 4 files changed, 43 insertions(+), 52 deletions(-) delete mode 100644 src/pages/policyPropType.js diff --git a/src/pages/ReportWelcomeMessagePage.js b/src/pages/ReportWelcomeMessagePage.js index 6dafb9e1f935..8e9b97340810 100644 --- a/src/pages/ReportWelcomeMessagePage.js +++ b/src/pages/ReportWelcomeMessagePage.js @@ -18,10 +18,11 @@ import CONST from '../CONST'; import FullPageNotFoundView from '../components/BlockingViews/FullPageNotFoundView'; import Form from '../components/Form'; import * as PolicyUtils from '../libs/PolicyUtils'; -import policyPropType from './policyPropType'; +import {policyPropTypes} from './workspace/withPolicy'; const propTypes = { ...withLocalizePropTypes, + ...policyPropTypes, /** The report currently being looked at */ report: reportPropTypes.isRequired, @@ -33,9 +34,6 @@ const propTypes = { reportID: PropTypes.string, }), }).isRequired, - - /** The policy of which the room os a part of */ - policy: PropTypes.objectOf(policyPropType), }; const defaultProps = { diff --git a/src/pages/policyPropType.js b/src/pages/policyPropType.js deleted file mode 100644 index 6bacb28c84e5..000000000000 --- a/src/pages/policyPropType.js +++ /dev/null @@ -1,40 +0,0 @@ -import _ from 'underscore'; -import PropTypes from 'prop-types'; -import CONST from '../CONST'; - -export default PropTypes.shape({ - /** The ID of the policy */ - id: PropTypes.string, - - /** The name of the policy */ - name: PropTypes.string, - - /** The current user's role in the policy */ - role: PropTypes.oneOf(_.values(CONST.POLICY.ROLE)), - - /** The policy type */ - type: PropTypes.oneOf(_.values(CONST.POLICY.TYPE)), - - /** The email of the policy owner */ - owner: PropTypes.string, - - /** The output currency for the policy */ - outputCurrency: PropTypes.string, - - /** The URL for the policy avatar */ - avatar: PropTypes.string, - - /** Errors on the policy keyed by microtime */ - errors: PropTypes.objectOf(PropTypes.string), - - /** - * Error objects keyed by field name containing errors keyed by microtime - * E.x - * { - * name: { - * [DateUtils.getMicroseconds()]: 'Sorry, there was an unexpected problem updating your workspace name.', - * } - * } - */ - errorFields: PropTypes.objectOf(PropTypes.objectOf(PropTypes.string)), -}); diff --git a/src/pages/settings/Report/WriteCapabilityPage.js b/src/pages/settings/Report/WriteCapabilityPage.js index af4dc331a9cf..b9fed0a63ba1 100644 --- a/src/pages/settings/Report/WriteCapabilityPage.js +++ b/src/pages/settings/Report/WriteCapabilityPage.js @@ -20,16 +20,14 @@ import themeColors from '../../../styles/themes/default'; import * as ReportUtils from '../../../libs/ReportUtils'; import FullPageNotFoundView from '../../../components/BlockingViews/FullPageNotFoundView'; import * as PolicyUtils from '../../../libs/PolicyUtils'; -import policyPropType from '../../policyPropType'; +import {policyPropTypes} from '../../workspace/withPolicy'; const propTypes = { ...withLocalizePropTypes, + ...policyPropTypes, /** The report for which we are setting write capability */ report: reportPropTypes.isRequired, - - /** The policy of which the room os a part of */ - policy: PropTypes.objectOf(policyPropType), }; const defaultProps = { @@ -51,11 +49,11 @@ function WriteCapabilityPage(props) { boldStyle: value === (props.report.writeCapability || CONST.REPORT.WRITE_CAPABILITIES.ALL), })); - const canAccess = !ReportUtils.isAdminRoom(props.report) && PolicyUtils.isPolicyAdmin(props.policy); + const isAbleToEdit = !ReportUtils.isAdminRoom(props.report) && PolicyUtils.isPolicyAdmin(props.policy); return ( - + Date: Fri, 14 Jul 2023 20:14:26 +0530 Subject: [PATCH 5/5] Fix Lint --- src/pages/ReportWelcomeMessagePage.js | 4 ++-- src/pages/settings/Report/WriteCapabilityPage.js | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/pages/ReportWelcomeMessagePage.js b/src/pages/ReportWelcomeMessagePage.js index 8e9b97340810..2e358e88a1b3 100644 --- a/src/pages/ReportWelcomeMessagePage.js +++ b/src/pages/ReportWelcomeMessagePage.js @@ -18,7 +18,7 @@ import CONST from '../CONST'; import FullPageNotFoundView from '../components/BlockingViews/FullPageNotFoundView'; import Form from '../components/Form'; import * as PolicyUtils from '../libs/PolicyUtils'; -import {policyPropTypes} from './workspace/withPolicy'; +import {policyPropTypes, policyDefaultProps} from './workspace/withPolicy'; const propTypes = { ...withLocalizePropTypes, @@ -37,7 +37,7 @@ const propTypes = { }; const defaultProps = { - policy: {}, + ...policyDefaultProps, }; function ReportWelcomeMessagePage(props) { diff --git a/src/pages/settings/Report/WriteCapabilityPage.js b/src/pages/settings/Report/WriteCapabilityPage.js index b9fed0a63ba1..e831d539f440 100644 --- a/src/pages/settings/Report/WriteCapabilityPage.js +++ b/src/pages/settings/Report/WriteCapabilityPage.js @@ -1,6 +1,5 @@ import React from 'react'; import _ from 'underscore'; -import PropTypes from 'prop-types'; import {withOnyx} from 'react-native-onyx'; import ONYXKEYS from '../../../ONYXKEYS'; import CONST from '../../../CONST'; @@ -20,7 +19,7 @@ import themeColors from '../../../styles/themes/default'; import * as ReportUtils from '../../../libs/ReportUtils'; import FullPageNotFoundView from '../../../components/BlockingViews/FullPageNotFoundView'; import * as PolicyUtils from '../../../libs/PolicyUtils'; -import {policyPropTypes} from '../../workspace/withPolicy'; +import {policyPropTypes, policyDefaultProps} from '../../workspace/withPolicy'; const propTypes = { ...withLocalizePropTypes, @@ -31,7 +30,7 @@ const propTypes = { }; const defaultProps = { - policy: {}, + ...policyDefaultProps, }; const greenCheckmark = {src: Expensicons.Checkmark, color: themeColors.success};