App icon indicating copy to clipboard operation
App copied to clipboard

[$175] [Exploratory] w44-Secondary email-Both emails become workspace members when changing default one

Open applause-bot[bot] opened this issue 1 month ago • 14 comments

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: v9.5.26-0 Reproducible in staging?: Yes Reproducible in production?: Yes If this was caught during regression testing, add the test name, ID and link from BrowserStack: https://test-management.browserstack.com/projects/2219752/test-runs/81501458/folder/52723565/49419429/1929776044 Email or phone of affected tester (no customers): [email protected] Issue reported by: Applause Internal Team Bug source: Exploratory - Significant User Experience Deterioration Device used: Desktop / Windows 11 App Component: User Settings

Action Performed:

Preconditions:

  • User A has two contact methods (emails) in the account profile settings.
  • User B is any existing user.
  1. Open the Expensify Web App and log in as User A from the Precondition
  2. Create a workspace
  3. Go to Workspace / Members and invite User B to the workspace
  4. Go to Account / Profile / Contact methods and set the secondary contact method as the default one
  5. Go to Workspace / Members again and observe the members list

Expected Result:

Nothing should change. The workspace should have two people (Owner and Member).

Actual Result:

The previous default email appears in the members list as the Owner. The new default email (previously secondary) appears in the members list as the Workspace Admin. User B still appears as the Member.

The workspace now has three people.

Workaround:

Unknown

Platforms:

  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [ ] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [x] Windows: Chrome
  • [ ] MacOS: Chrome Safari

Screenshots/Videos

https://github.com/user-attachments/assets/56ced547-4209-4b08-b7af-352e14731c8c

View all open jobs on GitHub

Applause Internal Information Exported by: Chandana Kiran Bug ID: 7300888

Upwork Automation - Do Not Edit

applause-bot[bot] avatar Oct 30 '26 20:10 applause-bot[bot]

While Applause doesn't embed attachments for this bug, here are the links for quick view: https://platform.applause.com/services/links/v1/external/e916debb910a8ee4f5de5862c1b45d48ca1e0b28a8ae8ad36a64a7460557dac9

https://platform.applause.com/services/links/v1/external/14c97a8f3791b6f977319f573c260da956e8c2b014dd6ae833635248b65acef0

applause-bot[bot] avatar Oct 30 '26 20:10 applause-bot[bot]

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0105ac9050d5ca10e5

Proposal

What is the root cause of that problem?

In src/libs/actions/User.ts:1120-1175 (setContactMethodAsDefault), setting a secondary contact method as default was refactored to Pattern C (deferring local state mutations to successData). However, successData only updates ACCOUNT.primaryLogin, SESSION.email, LOGINS, and PERSONAL_DETAILS_LIST: https://github.com/Expensify/App/blob/main/src/libs/actions/User.ts#L1126-L1160

It omits the workspace policy migration that was originally added in PR #45234 (fixing #44705). Specifically:

  1. policy.employeeList[oldDefaultContactMethod] is never removed or set to null in Onyx.
  2. policy.owner is never updated to newDefaultContactMethod.

When the user subsequently navigates to Workspace / Members, openWorkspaceMembersPage fetches the member list and merges the new default email into policy.employeeList. Because Onyx merges the dictionary keys without removing the old key:

  • policy.employeeList retains both oldDefaultContactMethod and newDefaultContactMethod.
  • In src/pages/workspace/WorkspaceMembersPage.tsx:431, const role = policy?.owner === details.login ? ownerDisplayRole : employeeRole. Because policy.owner still holds the old email, the old email is rendered with the Owner badge (with fallback personal details generated by useWorkspaceMembers).
  • The new default email matches the user's active personal details and renders with role admin (Workspace Admin).
  • This results in two separate member rows for the same user.

What changes do you think we should make in order to solve the problem?

  1. In src/libs/actions/User.ts:

    • Connect or pass allPolicies (Onyx.connect({key: ONYXKEYS.COLLECTION.POLICY, ...}) or retrieve policies from Onyx).
    • When building successData in setContactMethodAsDefault: Iterate over policies where the user is a member or owner, and append policy updates to successData:
      • In employeeList, set [oldDefaultContactMethod]: null and [newDefaultContactMethod]: currentEmployee (preserving the member's current role and permissions).
      • If policy.ownerAccountID === currentUserPersonalDetails.accountID (or policy.owner === oldDefaultContactMethod), update owner: newDefaultContactMethod.
    • Also append the inverse to failureData if the call fails to ensure rollback consistency.
  2. In tests/unit/UserTest.ts:

    • Add a unit test verifying that when setContactMethodAsDefault succeeds, policy.employeeList removes the old default contact method (null), adds the new contact method, and updates policy.owner to the new email.

What alternative solutions did you explore? (Optional)

  1. Deduplicating members strictly in the UI layer inside useWorkspaceMembers.ts by grouping on accountID: rejected because the underlying Onyx store remains out-of-sync with stale member keys, which would cause errors in downstream member management actions (e.g. removing members, role changes, or approvals). Fixing it in successData keeps Onyx consistent across the entire application.

edotwedo avatar Oct 30 '26 21:10 edotwedo

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Oct 30 '26 21:10 melvin-bot[bot]

Proposal

What is the root cause of that problem?

setContactMethodAsDefault no longer renames the user's entry in each workspace's employeeList. It also no longer updates policy.owner. After a successful call, it only updates account, session, logins, and personal details (User.ts:1124-1156).

This is a regression of [HOLD for payment 2024-07-24] [$250] Workspace member - Hidden admin appears in the members list after changing contact method. Fix hidden member appears in the WS members after changing default contact method fixed it by moving each policy from employeeList[old] to employeeList[new] and setting owner to the new email. Add magic code verification when setting default contact method moved the function to "Pattern C", where data changes wait for the server to confirm success. It deleted the policy loop instead of moving it into successData.

The members page then shows two rows for the same person:

  • Old email: the key is still in employeeList, but no personal details match it anymore. useWorkspaceMembers.ts:31-57 builds a fallback row for it. policy.owner still holds the old email, so WorkspaceMembersPage.tsx:432 labels this row Owner.
  • New email: the server returns this key. It matches the real personal details but not policy.owner, so the row shows the user's actual role, Workspace Admin.

Before Show workspace members with missing personal details instead of dropping them, the page silently dropped the stale row. Since that PR, the row is visible.

What changes do you think we should make in order to solve the problem?

  1. In setContactMethodAsDefault, accept a policies parameter. Include only id, ownerAccountID, and employeeList.
  2. For each policy, add a MERGE to successData:
    • If employeeList[oldLogin] exists, set employeeList: {[oldLogin]: null, [newLogin]: <old entry>}.
    • If ownerAccountID equals the current user's accountID, set owner: newLogin.
  3. In SetDefaultContactMethodConfirmValidateCodePage.tsx, read the policies with useOnyx and a narrow selector. Pass them to the action at line 77.
  4. Add a UserTest case that checks the old key is removed, the new key is added, and owner is updated after success.

Because of Pattern C, failureData needs no policy rollback.

What alternative solutions did you explore? (Optional)

  • Compare owner by accountID: at WorkspaceMembersPage.tsx:432, check accountID === policy.ownerAccountID instead of comparing emails. This is useful extra hardening. On its own it won't fix the bug, because the stale employeeList key would still render a second row.
  • Remove duplicates in the UI by accountID: rejected, because Onyx would still hold a stale member key that other member actions read.
Investigation notes
  • Add magic code verification when setting default contact method (merged 2026-04-30) removed the policies: OnyxCollection<Policy> parameter and the for (const policy of Object.values(policies)) loop that updated employeeList and owner. Nothing replaced it in successData.
  • openWorkspaceMembersPage (Member.ts:1346-1358) has no client-side Onyx data, so the server response decides what happens to employeeList. The page builds clientMemberEmails with getMemberAccountIDsForWorkspace (members.ts:147-175), which skips emails with no personal details. So the client never reports the stale email to the server, and the server never clears it.
  • Not verified: whether the backend ever sends employeeList[old]: null or a new owner after SetContactMethodAsDefault. The front-end fix above makes the client correct either way.
  • The earlier contributor proposal from edotwedo reaches the same root cause and fix.

Next Steps for Contributor+ team: To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/105532) to create a draft PR. To refine: @MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.

MelvinBot avatar Nov 03 '26 00:11 MelvinBot

Triggered auto assignment to Contributor-plus team member for initial proposal review - @ZhenjaHorbach (External)

melvin-bot[bot] avatar Nov 03 '26 00:11 melvin-bot[bot]

Job added to Upwork: https://www.upwork.com/jobs/~022117413290377373797

melvin-bot[bot] avatar Nov 03 '26 00:11 melvin-bot[bot]

@MelvinBot Create a PR with your proposal

ZhenjaHorbach avatar Nov 05 '26 11:11 ZhenjaHorbach

🤖 Web test steps verification results: ❌ fail

Blocked on dev NewDot web: the handed-over session rendered a blank page. The fix could not be verified; no reload, reauthentication, or magic-code bypass was attempted.

Blank application page in the handed-over web session
Step Status
Open Expensify signed inInitial and follow-up snapshots returned no nodes; waiting for Inbox timed out.
Blank application page in the handed-over web session
❌
Create a workspaceNot reached because the application remained blank.
⚠️
Invite an existing user and confirm Owner + MemberNot reached because the application remained blank.
⚠️
Make the secondary contact email defaultNot reached; the two-email prerequisite could not be confirmed.
⚠️
Verify exactly two workspace members, new email as Owner, and old email absentNot reached because the application remained blank.
⚠️

Created draft PR: Prevent duplicate workspace members after changing the default email, assigned to ZhenjaHorbach, with PullerBear review requested.

Implemented the approved proposal and added regression coverage. All 37,138 Jest tests passed, alongside lint, typechecking and Storybook smoke testing. Remaining check limitations are documented in the PR.

Please complete human testing before marking it ready for review, or ask me to mark it ready once testing is complete.


view run · no recording available

MelvinBot avatar Nov 05 '26 12:11 MelvinBot

Proposal

Please re-state the problem that we are trying to solve in this issue.

When a user who owns or belongs to a workspace adds a secondary email, sets that secondary email as their default contact method, and then checks the workspace Members page, both the old default email and the new default email appear as separate members in the workspace members list.

What is the root cause of that problem?

In src/libs/actions/User.ts (lines 1120–1160, setContactMethodAsDefault), when refactoring setContactMethodAsDefault to defer state updates to successData, the workspace policy.employeeList and policy.owner migration logic originally added in PR #45234 (for issue #44705) was dropped. Specifically, setContactMethodAsDefault currently updates ONYXKEYS.ACCOUNT, ONYXKEYS.SESSION, ONYXKEYS.LOGIN_LIST, and ONYXKEYS.PERSONAL_DETAILS_LIST, but never removes policy.employeeList[oldDefaultContactMethod] or moves that employee entry to policy.employeeList[newDefaultContactMethod] in ONYXKEYS.COLLECTION.POLICY. When the backend adds the new primary login to the policy's employeeList, Onyx merges the new key while retaining the stale oldDefaultContactMethod key in policy.employeeList, causing both emails to render in WorkspaceMembersPage.

What changes do you think we should make in order to solve the problem?

  1. In src/libs/actions/User.ts (setContactMethodAsDefault, lines 1120–1175), iterate through allPolicies (ONYXKEYS.COLLECTION.POLICY) where policy?.employeeList?.[oldDefaultContactMethod] exists or policy?.owner === oldDefaultContactMethod.
  2. For each matching policy, add an Onyx.Method.MERGE entry in successData (matching Pattern C used by setContactMethodAsDefault) that:
    • Updates owner: policy.owner === oldDefaultContactMethod ? newDefaultContactMethod : policy.owner, and
    • Updates employeeList by setting [newDefaultContactMethod]: {...policy.employeeList[oldDefaultContactMethod], email: newDefaultContactMethod} and [oldDefaultContactMethod]: null so the stale entry under the old email is deleted from Onyx.
  3. Add a unit test in tests/actions/UserTest.ts verifying that setContactMethodAsDefault migrates policy.employeeList and policy.owner from the old default login to the new default login without leaving duplicate member entries.

What alternative solutions did you explore? (Optional)

We considered deduplicating employeeList entries by accountID in WorkspaceMembersPage.tsx, but policy.employeeList is keyed by email across the entire codebase, so cleaning up [oldDefaultContactMethod]: null in setContactMethodAsDefault keeps Onyx state consistent everywhere.

jeffrey-graham avatar Nov 07 '26 06:11 jeffrey-graham

📣 @jeffrey-graham! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

melvin-bot[bot] avatar Nov 07 '26 06:11 melvin-bot[bot]

Not overdue Will check the PR today or tomorrow

ZhenjaHorbach avatar Nov 10 '26 14:11 ZhenjaHorbach

@ZhenjaHorbach this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!

melvin-bot[bot] avatar Nov 13 '26 21:11 melvin-bot[bot]

@ZhenjaHorbach 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

@ZhenjaHorbach Now this issue is 8 days overdue. Are you sure this should be a Daily? Feel free to change it!