Skip to content

Filter unreported expenses by owner to prevent showing member expenses to admin#73230

Merged
iwiznia merged 16 commits into
Expensify:mainfrom
abzokhattab:fix/unreported-expenses-ownership-check
Feb 4, 2026
Merged

Filter unreported expenses by owner to prevent showing member expenses to admin#73230
iwiznia merged 16 commits into
Expensify:mainfrom
abzokhattab:fix/unreported-expenses-ownership-check

Conversation

@abzokhattab

@abzokhattab abzokhattab commented Oct 22, 2025

Copy link
Copy Markdown
Contributor

Explanation of Change

Fixed Issues

$ #70639
PROPOSAL: #70639 (comment)

Tests

Precondition:

  • Admin invites member to the workspace chat.

Steps:

  1. [Member] Go to workspace chat.
  2. [Member] Create an expense.
  3. [Member] Go to expense report.
  4. [Member] Click Report field > Remove from report.
  5. [Admin] Go to workspace chat (workspace chat with yourself).
  6. [Admin] Click + > Create report.
  7. [Admin] On report preview, click Add expense > Add unreported expense.
  8. Verify that the unreported expense from member in Step 4 doesn't appear in unreported expense list for admin.

Offline tests

Same as tests

QA Steps

same as tests

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I followed proper code patterns (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
      • If any non-english text was added/modified, I used JaimeGPT to get English > Spanish translation. I then posted it in #expensify-open-source and it was approved by an internal Expensify engineer. Link to Slack message:
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • I verified that if a function's arguments changed that all usages have also been updated correctly
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Screen.Recording.2026-01-17.at.16.13.02.mov
Android: mWeb Chrome
Screen.Recording.2026-01-17.at.16.15.59.mov
iOS: Native
Screen.Recording.2026-01-17.at.16.08.38.mov
iOS: mWeb Safari
Screen.Recording.2026-01-17.at.16.09.49.mov
MacOS: Chrome / Safari
Screen.Recording.2026-01-17.at.16.03.15.mov

@abzokhattab abzokhattab requested a review from a team as a code owner October 22, 2025 15:12
@melvin-bot melvin-bot Bot requested review from rojiphil and removed request for a team October 22, 2025 15:12
@melvin-bot

melvin-bot Bot commented Oct 22, 2025

Copy link
Copy Markdown

@rojiphil 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]

@abzokhattab abzokhattab marked this pull request as draft October 22, 2025 15:12
@abzokhattab

abzokhattab commented Oct 22, 2025

Copy link
Copy Markdown
Contributor Author

@iwiznia @rojiphil

there is a problem with the cardID solution; the cardList is empty in both admin and member

so what should we do here? am i accessing it in the wrong way?

here is the log of the transaction and the cardList:

image

@rojiphil

Copy link
Copy Markdown
Contributor

@iwiznia I think the card for cash expense is not sent back by BE in the card list as noticed in test video below.

70639-web-chrome-issue.mp4

@iwiznia

iwiznia commented Oct 22, 2025

Copy link
Copy Markdown
Contributor

Damnit! I see here we are not returning all cards to newDot (cash, personal cards not returned, not sure if some others).
@nkuoch I see your name on that code, do you know why we are not just returning all cards owned by the user? Seems like something we will need for one reason or another, so wonder what was the reason to not return them all basically.

@nkuoch

nkuoch commented Oct 22, 2025

Copy link
Copy Markdown
Contributor

Not me :). cc @grgia https://github.com/Expensify/Auth/pull/9223 for personal cards

@iwiznia

iwiznia commented Oct 23, 2025

Copy link
Copy Markdown
Contributor

Ah thanks for that. I don't see a real reason not to add them, just that we did not want them to display them in the cards table. I think we should've done that in the frontend instead. So if @grgia agrees, I think we would:

Thoughts?

@grgia

grgia commented Oct 23, 2025

Copy link
Copy Markdown
Contributor

Yeah @iwiznia, now that we are using personal cards in ND, makes sense

@iwiznia

iwiznia commented Oct 23, 2025

Copy link
Copy Markdown
Contributor

We are? Where? How if we are not returning them from auth?

@abzokhattab

abzokhattab commented Oct 27, 2025

Copy link
Copy Markdown
Contributor Author

still waiting for the team's decision.

cc @iwiznia @grgia @rojiphil

@rojiphil

rojiphil commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

@grgia Can you please help confirm if the BE changes are in production already? Thanks

@rojiphil

Copy link
Copy Markdown
Contributor

I think the card for cash expense is not sent back by BE in the card list as noticed in test video below.

@iwiznia @grgia The card id for cash expense is not yet available in FE.
Any update on the BE implementation for this? Thanks.

73230-missing-cardid.mp4

@iwiznia

iwiznia commented Nov 24, 2025

Copy link
Copy Markdown
Contributor

@grgia please respond to the question above so we can get this moving forward

@grgia

grgia commented Nov 26, 2025

Copy link
Copy Markdown
Contributor

No update on the BE implementation, I only worked on ECards @iwiznia. Is there an issue for the BE?

@iwiznia

iwiznia commented Nov 26, 2025

Copy link
Copy Markdown
Contributor

ok talked to @grgia, I am sending the backend change right now. We need to do this, but maybe we need to do it in 3 steps so we don't break anything, so:

  • Send a new App PR to filter out the personal cards (and cash one) from the list of cards and get it deployed
  • Revert https://github.com/Expensify/Auth/pull/9223 and ensure that returns personal cards, including the cash one and get it deployed
  • Finish up this PR and get it deployed

Sounds good @rojiphil? If so, can you start working on the PR for the first item?

@iwiznia

iwiznia commented Nov 26, 2025

Copy link
Copy Markdown
Contributor

PR for the backend is here https://github.com/Expensify/Auth/pull/18448 will merge once the PR for item 1 in my comment above is deployed

@rojiphil

Copy link
Copy Markdown
Contributor
  • Send a new App PR to filter out the personal cards (and cash one) from the list of cards and get it deployed

@iwiznia That sounds good as first step to me as well so that we don’t break anything.
Also happy to pick the PR work for this.

Meanwhile, I would need your help with the following as I am unable to figure out a way to filter. Thanks.

  1. Mock card structure for personal card and cash expense for testing.
  2. The parameter of card (within `cardList) that would help us to filter the personal cards(and cash expense) from others.

An access to the relevant design document is also good enough if that helps.

Btw, I am partially available today and tomorrow due to travel but hope to work on the PR over the weekend.

@abzokhattab

Copy link
Copy Markdown
Contributor Author

Looks like a solid plan if you will need a C+ for the other PR I can work on it as well.

@iwiznia

iwiznia commented Dec 1, 2025

Copy link
Copy Markdown
Contributor

Meanwhile, I would need your help with the following as I am unable to figure out a way to filter. Thanks.

Are you asking how to identify which cards are personal vs non personal and how to differentiate the cash personal card from other cards? If so:

  • Personal cards will have fundID set to 0
  • Cash card will have a name of __CASH__

@iwiznia

iwiznia commented Dec 23, 2025

Copy link
Copy Markdown
Contributor

Can we keep this moving please @rojiphil ?

@abzokhattab

Copy link
Copy Markdown
Contributor Author

so according to this plan seems like we are now pending on the second point #73230 (comment)

@iwiznia

@grgia

grgia commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

The second point is https://github.com/Expensify/Auth/pull/18448 I believe @iwiznia

@iwiznia

iwiznia commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

I am lost. Did we do step 1 here already?

@abzokhattab

Copy link
Copy Markdown
Contributor Author

Sure ,, just resolved the conflicts

@rojiphil

rojiphil commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Conflicts again @abzokhattab. Please resolve. Working on checklist now

@rojiphil

rojiphil commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified that the composer does not automatically focus or open the keyboard on mobile unless explicitly intended. This includes checking that returning the app from the background does not unexpectedly open the keyboard.
  • I verified tests pass on all platforms & I tested again on:
    • Android: HybridApp
    • Android: mWeb Chrome
    • iOS: HybridApp
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified there are no new alerts related to the canBeMissing param for useOnyx
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product is localized by adding it to src/languages/* files and using the translation method
    • I verified all numbers, amounts, dates and phone numbers shown in the product are using the localization methods
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
  • I verified any variables that can be defined as constants (ie. in CONST.ts or at the top of the file that uses the constant) are defined as such
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If any new file was added I verified that:
    • The file has a description of what it does and/or why is needed at the top of the file if the code is not self explanatory
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • If a new page is added, I verified it's using the ScrollView component to make it scrollable when more elements are added to the page.
  • For any bug fix or new feature in this PR, I verified that sufficient unit tests are included to prevent regressions in this flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.
  • I have checked off every checkbox in the PR reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Android: HybridApp
70639-android-hybrid-001.mp4
Android: mWeb Chrome
70639-mweb-chrome-001.mp4
iOS: HybridApp
70639-ios-hybrid-001.mp4
iOS: mWeb Safari
70639-mweb-safari-001.mp4
MacOS: Chrome / Safari
79772-web-chrome-002.mp4

Comment thread src/pages/AddUnreportedExpense.tsx Outdated
const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${getNonEmptyStringOnyxID(report?.policyID)}`, {canBeMissing: true});
const [hasMoreUnreportedTransactionsResults] = useOnyx(ONYXKEYS.HAS_MORE_UNREPORTED_TRANSACTIONS_RESULTS, {canBeMissing: true});
const [isLoadingUnreportedTransactions] = useOnyx(ONYXKEYS.IS_LOADING_UNREPORTED_TRANSACTIONS, {canBeMissing: true});
const [cardList] = useOnyx(ONYXKEYS.CARD_LIST, {selector: filterPersonalCards, canBeMissing: true});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@abzokhattab We should not include the selector here as we should look into the entire cardlist to determine if the transaction belongs to this user

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
const [cardList] = useOnyx(ONYXKEYS.CARD_LIST, {selector: filterPersonalCards, canBeMissing: true});
const [cardList] = useOnyx(ONYXKEYS.CARD_LIST, {canBeMissing: true});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@rojiphil

Copy link
Copy Markdown
Contributor

Completed checklist. Tests well after applying the suggestion here.
Will check once again after the changes are done.

@rojiphil

Copy link
Copy Markdown
Contributor

LGTM

79772-web-chrome-002.mp4

@rojiphil rojiphil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @abzokhattab for the updates.

@iwiznia Changes LGTM.
Over to you. Thanks.

@melvin-bot melvin-bot Bot requested a review from iwiznia January 29, 2026 18:22
@abzokhattab

abzokhattab commented Jan 29, 2026

Copy link
Copy Markdown
Contributor Author

FYI: To incorporate this comment, I negated the isPersonalCard calls. However, I didn’t negate this condition:

card?.bank === CONST.PERSONAL_CARD.BANK_NAME.CSV which was added later by another PR

i am afriad that the current changes bring regressions since we are now checking for !isPersonalCard instead of isPersonalCard

cc @rojiphil

@rojiphil

Copy link
Copy Markdown
Contributor

i am afriad that the current changes bring regressions since we are now checking for !isPersonalCard instead of isPersonalCard

@abzokhattab I think this will get addressed once we resolve the conflicts here.
Also, related to comment here, please note that if we are removing the duplicate code in cardutils, we need to move the unit tests from cardutils to card

@abzokhattab

Copy link
Copy Markdown
Contributor Author

resolved the conflicts

@abzokhattab abzokhattab requested a review from rojiphil February 1, 2026 00:30
@rojiphil

rojiphil commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

Changes LGTM

73230-web-chrome-003.mp4

@rojiphil rojiphil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@iwiznia Over to you for review. Thanks.

@iwiznia iwiznia merged commit f6b0796 into Expensify:main Feb 4, 2026
30 checks passed
@github-actions

github-actions Bot commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

🚧 @iwiznia has triggered a test Expensify/App build. You can view the workflow run here.

@github-actions

github-actions Bot commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

@OSBotify

OSBotify commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify

OSBotify commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/iwiznia in version: 9.3.13-1 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@OSBotify

OSBotify commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

🚀 Deployed to staging by https://github.com/iwiznia in version: 9.3.15-0 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by https://github.com/lakchote in version: 9.3.15-10 🚀

platform result
🕸 web 🕸 success ✅
🤖 android 🤖 success ✅
🍎 iOS 🍎 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants