[Workavia] Drop double-save in remote.ts that wiped user.cache.companies

Upstream OIDC remote.updateUser does:
1. users.save(user) — basic fields, cache.companies unset
2. companies.setUserRole(company, user) — fetches fresh user, pushes
   company id into cache.companies, users.save() that fresh user
3. users.save(user) — saves the LOCAL stale user, overwriting (2)

Step 3 is what breaks: cache.companies ends up empty in DB, the user
search index loses the companies field, and the share-picker can't
find users from the same Company.

Removing step 3 fixes it: setUserRole's save is the authoritative one.
This commit is contained in:
stanig2106
2026-05-02 22:06:53 +02:00
parent ba4aac2d8b
commit 573e4a0cb4
@@ -214,8 +214,16 @@ export class ConsoleRemoteClient implements ConsoleServiceClient {
await gr.services.companies.setUserRole(company.id, user.id, userRole);
await gr.services.users.save(user, { user: { id: user.id, server_request: true } });
// [Workavia] Removed an upstream `users.save(user, ...)` here that
// overwrote the user record after setUserRole (line above) had
// already fetched a fresh user, pushed the new companyId into
// user.cache.companies, and saved. Saving the stale local `user`
// object on top wiped cache.companies → the OpenSearch `user` index
// ended up with an empty `companies` field → frontend share-picker
// search returned zero results for same-Company users. Without this
// double-save, setUserRole's save is the last write and the index
// is correct. Surfacing this comment so it doesn't get reintroduced
// on rebase.
return user;
}