Skip to content

Commit

Permalink
Merge pull request #22820 from esh-g/restrict-room-settings
Browse files Browse the repository at this point in the history
Restrict workspace settings to admins
  • Loading branch information
grgia authored Jul 17, 2023
2 parents 39b2574 + 10d80e5 commit 25c8ae5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
24 changes: 21 additions & 3 deletions src/pages/ReportWelcomeMessagePage.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -17,9 +17,12 @@ 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 {policyPropTypes, policyDefaultProps} from './workspace/withPolicy';

const propTypes = {
...withLocalizePropTypes,
...policyPropTypes,

/** The report currently being looked at */
report: reportPropTypes.isRequired,
Expand All @@ -33,6 +36,10 @@ const propTypes = {
}).isRequired,
};

const defaultProps = {
...policyDefaultProps,
};

function ReportWelcomeMessagePage(props) {
const parser = new ExpensiMark();
const [welcomeMessage, setWelcomeMessage] = useState(parser.htmlToMarkdown(props.report.welcomeMessage));
Expand All @@ -55,7 +62,7 @@ function ReportWelcomeMessagePage(props) {
welcomeMessageInputRef.current.focus();
}}
>
<FullPageNotFoundView shouldShow={_.isEmpty(props.report)}>
<FullPageNotFoundView shouldShow={!PolicyUtils.isPolicyAdmin(props.policy)}>
<HeaderWithBackButton title={props.translate('welcomeMessagePage.welcomeMessage')} />
<Form
style={[styles.flexGrow1, styles.ph5]}
Expand Down Expand Up @@ -87,5 +94,16 @@ function ReportWelcomeMessagePage(props) {
);
}

ReportWelcomeMessagePage.displayName = 'ReportWelcomeMessagePage';
ReportWelcomeMessagePage.propTypes = propTypes;
export default compose(withLocalize, withReportOrNotFound)(ReportWelcomeMessagePage);
ReportWelcomeMessagePage.defaultProps = defaultProps;

export default compose(
withLocalize,
withReportOrNotFound,
withOnyx({
policy: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`,
},
}),
)(ReportWelcomeMessagePage);
25 changes: 23 additions & 2 deletions src/pages/settings/Report/WriteCapabilityPage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react';
import _ from 'underscore';
import {withOnyx} from 'react-native-onyx';
import ONYXKEYS from '../../../ONYXKEYS';
import CONST from '../../../CONST';
import ScreenWrapper from '../../../components/ScreenWrapper';
import HeaderWithBackButton from '../../../components/HeaderWithBackButton';
Expand All @@ -16,13 +18,21 @@ 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 {policyPropTypes, policyDefaultProps} from '../../workspace/withPolicy';

const propTypes = {
...withLocalizePropTypes,
...policyPropTypes,

/** The report for which we are setting write capability */
report: reportPropTypes.isRequired,
};

const defaultProps = {
...policyDefaultProps,
};

const greenCheckmark = {src: Expensicons.Checkmark, color: themeColors.success};

function WriteCapabilityPage(props) {
Expand All @@ -38,9 +48,11 @@ function WriteCapabilityPage(props) {
boldStyle: value === (props.report.writeCapability || CONST.REPORT.WRITE_CAPABILITIES.ALL),
}));

const isAbleToEdit = !ReportUtils.isAdminRoom(props.report) && PolicyUtils.isPolicyAdmin(props.policy);

return (
<ScreenWrapper includeSafeAreaPaddingBottom={false}>
<FullPageNotFoundView shouldShow={ReportUtils.isAdminRoom(props.report)}>
<FullPageNotFoundView shouldShow={!isAbleToEdit}>
<HeaderWithBackButton
title={props.translate('writeCapabilityPage.label')}
shouldShowBackButton
Expand All @@ -66,5 +78,14 @@ function WriteCapabilityPage(props) {

WriteCapabilityPage.displayName = 'WriteCapabilityPage';
WriteCapabilityPage.propTypes = propTypes;
WriteCapabilityPage.defaultProps = defaultProps;

export default compose(withLocalize, withReportOrNotFound)(WriteCapabilityPage);
export default compose(
withLocalize,
withReportOrNotFound,
withOnyx({
policy: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`,
},
}),
)(WriteCapabilityPage);

0 comments on commit 25c8ae5

Please sign in to comment.