Hide receipt attachment actions when the parent conversation is read-only - #97423
Hide receipt attachment actions when the parent conversation is read-only#97423wildan-m wants to merge 11 commits into
Conversation
…ly-receipt-attachment
…ly-receipt-attachment
…ly-receipt-attachment
|
@Krishna2323 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cbc493be1c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // A conversation's read-only restriction lives on the parent conversation report, not on the transaction thread, | ||
| // so checking the thread alone lets someone who cannot post in the conversation still attach a receipt to it. | ||
| // Mirrors how the conversation composer is gated. Skipped when there is no parent conversation to check. | ||
| const canWriteInChatReport = !chatReport || !!canUserPerformWriteActionReportUtils(chatReport, isChatReportArchived); |
There was a problem hiding this comment.
Require the parent chat to load before enabling uploads
When parentReport?.parentReportID is already known but that chat report has not hydrated yet (for example after opening the transaction from search/deep link or after clearing Onyx), !chatReport makes this guard treat the parent conversation as writable. That leaves the receipt actions enabled for a read-only parent chat until the chat report arrives, so a user with only READ permission can still press Add additional receipt and send addAttachmentWithComment before the guard flips. Please only skip this check when there is truly no parent conversation, not when the expected parent chat is missing from Onyx.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch — fixed in b25e1ea: a report above the expense that is expected but not yet in Onyx now blocks the add button until it loads, instead of reading as writable.
Codecov Report❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.
|
|
Reviewing this one shortly... |
There was a problem hiding this comment.
Hey @wildan-m, I tested this on staging and I think there's a simpler fix.
The conversation itself isn't read-only in this repro—the invited user can still post messages. What's actually blocked is editing the expense, not the conversation.
The full-screen receipt view already handles this correctly using canEditFieldOfMoneyRequest(... RECEIPT ...), which is why the invited user only sees Download.
MoneyRequestReceiptView already computes the same canEditReceipt flag and uses it in several places. I think we just need to include it here:
const canShowReceiptActions = hasReceipt && !isLoading && isEditable && canEditReceipt && !mergeTransactionID;I tested it locally—the + disappears for the invited user and still shows for the expense owner.
There was a problem hiding this comment.
Thanks @Krishna2323 — you're right, this is an IOU report so the invited user already fails the edit check. Two problems with using it directly though: that check also rules out scanning receipts and map-distance receipts, so the + would vanish for the expense owner too, which breaks two tests already on main; and it gates the expand button as well, so the invited user could never open the receipt to see the Download you mentioned. If you just want the permission part, (isAdmin || isManager || isRequestor || isApprover) is the bit that matters
There was a problem hiding this comment.
@wildan-m could we extract that part of the check out of canEditFieldOfMoneyRequest so it skips the scanning and map-distance conditions? Then we could use the same function in both canEditFieldOfMoneyRequest and the receipt view.
There was a problem hiding this comment.
Done in 89659b9 — pulled the role check out as canCurrentUserEditExpense and used it in both places. The scanning and map-distance conditions stay behind in canEditFieldOfMoneyRequest, so those receipts still show the button. All 1176 ReportUtils tests pass and CI is green.
There was a problem hiding this comment.
You mean the payer of an IOU should not have edit control over the receipt?
There was a problem hiding this comment.
@rlinoz yes — for an IOU only the requestor can edit the expense, so the payer never had edit control in the receipt modal either. This just makes the inline + match. Happy to scope it to non-payers if you'd rather they keep it.
There was a problem hiding this comment.
This makes sense to me, but I'm not super familiar with IOUs, so tagging @trjExpensify here to help confirm this behavior.
There was a problem hiding this comment.
Now the payer also loses + option, but I think that's the correct behaviour since the attachment modal also hides those edit options:
Can you clarify what you mean by the payer loses the + option? As in, they can't add an expense to an IOUReport if they're owed?
There was a problem hiding this comment.
@trjExpensify not that — the + is the small add-additional-receipt button on the receipt image inside an expense, so it only attaches another image to that one expense. Adding expenses to the report and paying are unaffected. It disappears for the payer because only the requestor can edit an IOU expense, which the receipt modal already reflected.

Explanation of Change
In a read-only conversation, someone who cannot post there can still add an attachment to an expense — opening the expense and using the receipt's add-additional-receipt control attaches an image that lands in the conversation. The restriction that makes a conversation read-only is carried on the report the user was given limited access to, which here is the expense's own report. The receipt view is handed the transaction thread below it and decides editability from that alone; the thread carries no restriction, so the control stays visible and the attachment goes through.
Editability now also requires write permission on the reports above the expense — its own report and the conversation above it — using the same permission check that hides the conversation composer. Only the add control is gated: the expand control still renders, so someone who cannot post can still open the receipt to read it, exactly as they can today.
Fixed Issues
$ #92679
PROPOSAL: #92679 (comment)
Tests
Offline tests
This is a visibility check computed from conversation data that is already cached locally, and it adds no network request. Offline, the add-additional-receipt control is hidden or shown from that cached data exactly as it is online: hidden in a read-only conversation, offered in one the user can post in.
QA Steps
Same as tests.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Kapture.2026-07-31.at.10.43.04.mp4
Android: mWeb Chrome
Kapture.2026-07-31.at.10.46.06.mp4
iOS: Native
Kapture.2026-07-31.at.10.53.10.mp4
iOS: mWeb Safari
Kapture.2026-07-31.at.10.54.48.mp4
MacOS: Chrome / Safari
Kapture.2026-07-31.at.10.47.15.mp4