Skip to content

Commit

Permalink
Merge pull request #29887 from Expensify/tgolen-rename-shouldDisableW…
Browse files Browse the repository at this point in the history
…riteActions

Rename shouldDisableWriteActions to canUserPerformWriteAction
  • Loading branch information
chiragsalian authored Oct 30, 2023
2 parents 2f9db59 + 08be55a commit ec7fb3c
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3526,7 +3526,7 @@ function parseReportRouteParams(route) {
parsingRoute = parsingRoute.slice(1);
}

if (!parsingRoute.startsWith(Url.addTrailingForwardSlash('r'))) {
if (!parsingRoute.startsWith(Url.addTrailingForwardSlash(ROUTES.REPORT))) {
return {reportID: '', isSubReportPageRoute: false};
}

Expand Down Expand Up @@ -3810,9 +3810,9 @@ function getAddWorkspaceRoomOrChatReportErrors(report) {
* @param {Object} report
* @returns {Boolean}
*/
function shouldDisableWriteActions(report) {
function canUserPerformWriteAction(report) {
const reportErrors = getAddWorkspaceRoomOrChatReportErrors(report);
return isArchivedRoom(report) || !_.isEmpty(reportErrors) || !isAllowedToComment(report) || isAnonymousUser;
return !isArchivedRoom(report) && _.isEmpty(reportErrors) && isAllowedToComment(report) && !isAnonymousUser;
}

/**
Expand Down Expand Up @@ -3866,7 +3866,7 @@ function getPolicyExpenseChatReportIDByOwner(policyOwner) {
*/
function canCreateRequest(report, betas, iouType) {
const participantAccountIDs = lodashGet(report, 'participantAccountIDs', []);
if (shouldDisableWriteActions(report)) {
if (!canUserPerformWriteAction(report)) {
return false;
}
return getMoneyRequestOptions(report, participantAccountIDs, betas).includes(iouType);
Expand Down Expand Up @@ -4249,7 +4249,7 @@ export {
getRootParentReport,
getReportPreviewMessage,
getModifiedExpenseMessage,
shouldDisableWriteActions,
canUserPerformWriteAction,
getOriginalReportID,
canAccessReport,
getAddWorkspaceRoomOrChatReportErrors,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/SidebarUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ function getOptionData(
result.parentReportID = report.parentReportID ?? null;
result.isWaitingOnBankAccount = report.isWaitingOnBankAccount;
result.notificationPreference = report.notificationPreference ?? null;
result.isAllowedToComment = !ReportUtils.shouldDisableWriteActions(report);
result.isAllowedToComment = ReportUtils.canUserPerformWriteAction(report);
result.chatType = report.chatType;

const hasMultipleParticipants = participantPersonalDetailList.length > 1 || result.isChatRoom || result.isPolicyExpenseChat;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportActionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ function ReportActionsList({
// Native mobile does not render updates flatlist the changes even though component did update called.
// To notify there something changes we can use extraData prop to flatlist
const extraData = [isSmallScreenWidth ? currentUnreadMarker : undefined, ReportUtils.isArchivedRoom(report)];
const hideComposer = ReportUtils.shouldDisableWriteActions(report);
const hideComposer = !ReportUtils.canUserPerformWriteAction(report);
const shouldShowReportRecipientLocalTime = ReportUtils.canShowReportRecipientLocalTime(personalDetailsList, report, currentUserPersonalDetails.accountID) && !isComposerFullSize;

const contentContainerStyle = useMemo(
Expand Down
2 changes: 1 addition & 1 deletion src/pages/home/report/ReportFooter.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function ReportFooter(props) {
const isAnonymousUser = Session.isAnonymousUser();

const isSmallSizeLayout = props.windowWidth - (props.isSmallScreenWidth ? 0 : variables.sideBarWidth) < variables.anonymousReportFooterBreakpoint;
const hideComposer = ReportUtils.shouldDisableWriteActions(props.report);
const hideComposer = !ReportUtils.canUserPerformWriteAction(props.report);

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/tasks/TaskShareDestinationSelectorModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function TaskShareDestinationSelectorModal(props) {
const reports = {};
_.keys(props.reports).forEach((reportKey) => {
if (
ReportUtils.shouldDisableWriteActions(props.reports[reportKey]) ||
!ReportUtils.canUserPerformWriteAction(props.reports[reportKey]) ||
ReportUtils.isExpensifyOnlyParticipantInReport(props.reports[reportKey]) ||
ReportUtils.isCanceledTaskReport(props.reports[reportKey])
) {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/OptionsListUtilsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ describe('OptionsListUtils', () => {
// Filter current REPORTS as we do in the component, before getting share destination options
const filteredReports = {};
_.keys(REPORTS).forEach((reportKey) => {
if (ReportUtils.shouldDisableWriteActions(REPORTS[reportKey]) || ReportUtils.isExpensifyOnlyParticipantInReport(REPORTS[reportKey])) {
if (!ReportUtils.canUserPerformWriteAction(REPORTS[reportKey]) || ReportUtils.isExpensifyOnlyParticipantInReport(REPORTS[reportKey])) {
return;
}
filteredReports[reportKey] = REPORTS[reportKey];
Expand All @@ -617,7 +617,7 @@ describe('OptionsListUtils', () => {
// Filter current REPORTS_WITH_WORKSPACE_ROOMS as we do in the component, before getting share destination options
const filteredReportsWithWorkspaceRooms = {};
_.keys(REPORTS_WITH_WORKSPACE_ROOMS).forEach((reportKey) => {
if (ReportUtils.shouldDisableWriteActions(REPORTS_WITH_WORKSPACE_ROOMS[reportKey]) || ReportUtils.isExpensifyOnlyParticipantInReport(REPORTS_WITH_WORKSPACE_ROOMS[reportKey])) {
if (!ReportUtils.canUserPerformWriteAction(REPORTS_WITH_WORKSPACE_ROOMS[reportKey]) || ReportUtils.isExpensifyOnlyParticipantInReport(REPORTS_WITH_WORKSPACE_ROOMS[reportKey])) {
return;
}
filteredReportsWithWorkspaceRooms[reportKey] = REPORTS_WITH_WORKSPACE_ROOMS[reportKey];
Expand Down

0 comments on commit ec7fb3c

Please sign in to comment.