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

Rename shouldDisableWriteActions to canUserPerformWriteAction #29887

Merged
merged 11 commits into from
Oct 30, 2023
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))) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've been wanting to fix this for a while, so I'm sneaking it into this PR.

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
Loading