Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix rename room permission #22316

Merged
merged 18 commits into from
Jul 19, 2023
5 changes: 0 additions & 5 deletions src/pages/settings/Report/ReportSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
55 changes: 35 additions & 20 deletions src/pages/settings/Report/RoomNamePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 Policy from '../../../libs/actions/Policy';
import FullPageNotFoundView from '../../../components/BlockingViews/FullPageNotFoundView';

const propTypes = {
...withLocalizePropTypes,
Expand All @@ -27,12 +29,20 @@ const propTypes = {

/** All reports shared with the user */
reports: PropTypes.objectOf(reportPropTypes),

/** */
Copy link
Contributor

@abdulrahuman5196 abdulrahuman5196 Jul 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** */
/** Policy of the report for which the name is being edited */

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hungvu193 Kindly add proper comment for the policy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops my bad. Updated!

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;
Expand Down Expand Up @@ -67,26 +77,28 @@ function RoomNamePage(props) {

return (
<ScreenWrapper includeSafeAreaPaddingBottom={false}>
<HeaderWithBackButton
title={translate('newRoomPage.roomName')}
onBackButtonPress={() => Navigation.goBack(ROUTES.getReportSettingsRoute(report.reportID))}
/>
<Form
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.ROOM_NAME_FORM}
onSubmit={(values) => Report.updatePolicyRoomNameAndNavigate(report, values.roomName)}
validate={validate}
submitButtonText={translate('common.save')}
enabledWhenOffline
>
<View style={styles.mb4}>
<RoomNameInput
inputID="roomName"
autoFocus
defaultValue={report.reportName}
/>
</View>
</Form>
<FullPageNotFoundView shouldShow={!Policy.isPolicyOwner(policy) && policy.role !== CONST.POLICY.ROLE.ADMIN}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hungvu193 This is duplicating the room rename permission logic. We should create a util function to have the logic of room rename permission check and use it in both these places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abdulrahuman5196 Thank you, I've just fixed it

<HeaderWithBackButton
title={translate('newRoomPage.roomName')}
onBackButtonPress={() => Navigation.goBack(ROUTES.getReportSettingsRoute(report.reportID))}
/>
<Form
style={[styles.flexGrow1, styles.ph5]}
formID={ONYXKEYS.FORMS.ROOM_NAME_FORM}
onSubmit={(values) => Report.updatePolicyRoomNameAndNavigate(report, values.roomName)}
validate={validate}
submitButtonText={translate('common.save')}
enabledWhenOffline
>
<View style={styles.mb4}>
<RoomNameInput
inputID="roomName"
autoFocus
defaultValue={report.reportName}
/>
</View>
</Form>
</FullPageNotFoundView>
</ScreenWrapper>
);
}
Expand All @@ -102,5 +114,8 @@ export default compose(
reports: {
key: ONYXKEYS.COLLECTION.REPORT,
},
policy: {
key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`,
},
}),
)(RoomNamePage);