Skip to content

Commit

Permalink
Merge pull request #30886 from esh-g/task-room-name
Browse files Browse the repository at this point in the history
Restrict room rename for Task
  • Loading branch information
stitesExpensify authored Nov 20, 2023
2 parents 7a9c773 + b6aefc8 commit 1991736
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3966,7 +3966,7 @@ function getWorkspaceChats(policyID, accountIDs) {
* @returns {Boolean}
*/
function shouldDisableRename(report, policy) {
if (isDefaultRoom(report) || isArchivedRoom(report) || isChatThread(report) || isMoneyRequestReport(report) || isPolicyExpenseChat(report)) {
if (isDefaultRoom(report) || isArchivedRoom(report) || isThread(report) || isMoneyRequestReport(report) || isPolicyExpenseChat(report)) {
return true;
}

Expand All @@ -3981,6 +3981,15 @@ function shouldDisableRename(report, policy) {
return !_.keys(loginList).includes(policy.owner) && policy.role !== CONST.POLICY.ROLE.ADMIN;
}

/**
* @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 canEditWriteCapability(report, policy) {
return PolicyUtils.isPolicyAdmin(policy) && !isAdminRoom(report) && !isArchivedRoom(report) && !isThread(report);
}

/**
* Returns the onyx data needed for the task assignee chat
* @param {Number} accountID
Expand Down Expand Up @@ -4438,4 +4447,5 @@ export {
getChannelLogMemberMessage,
getRoom,
shouldDisableWelcomeMessage,
canEditWriteCapability,
};
2 changes: 1 addition & 1 deletion src/pages/settings/Report/ReportSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function ReportSettingsPage(props) {
const writeCapability = ReportUtils.isAdminRoom(report) ? CONST.REPORT.WRITE_CAPABILITIES.ADMINS : report.writeCapability || CONST.REPORT.WRITE_CAPABILITIES.ALL;

const writeCapabilityText = translate(`writeCapabilityPage.writeCapability.${writeCapability}`);
const shouldAllowWriteCapabilityEditing = lodashGet(linkedWorkspace, 'role', '') === CONST.POLICY.ROLE.ADMIN && !ReportUtils.isAdminRoom(report) && !isMoneyRequestReport;
const shouldAllowWriteCapabilityEditing = useMemo(() => ReportUtils.canEditWriteCapability(report, linkedWorkspace), [report, linkedWorkspace]);

const shouldShowNotificationPref = !isMoneyRequestReport && report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
const roomNameLabel = translate(isMoneyRequestReport ? 'workspace.editor.nameInputLabel' : 'newRoomPage.roomName');
Expand Down
3 changes: 1 addition & 2 deletions src/pages/settings/Report/WriteCapabilityPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import SelectionList from '@components/SelectionList';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import compose from '@libs/compose';
import Navigation from '@libs/Navigation/Navigation';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import withReportOrNotFound from '@pages/home/report/withReportOrNotFound';
import reportPropTypes from '@pages/reportPropTypes';
Expand Down Expand Up @@ -38,7 +37,7 @@ function WriteCapabilityPage(props) {
isSelected: value === (props.report.writeCapability || CONST.REPORT.WRITE_CAPABILITIES.ALL),
}));

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

return (
<ScreenWrapper
Expand Down

0 comments on commit 1991736

Please sign in to comment.