LF-5318 (2) Address 'null' user.language_preference for newly invited users#4188
Conversation
…on-functional (escaped) query param; remove no-op patch on non-existent language_preference
cb78f55 to
981508d
Compare
| return async (req, res) => { | ||
| let result; | ||
| const { user_id, farm_id } = req.auth; | ||
| const { language_preference } = req.body; |
There was a problem hiding this comment.
Not to be confused with userController.acceptInvitationAndPostPassword (the controller downstream of filling out the InvitedUserCreateAccount form), the language_preference here is non-existent; both acceptInvitation() and acceptInvitationWithAccessToken() are called from the frontend without a req.body, so the patch below was always a no-op.
Not related to the bug (since it did nothing), but removed only because it's misleading.
| token = await createToken('invite', { | ||
| ...user, | ||
| ...userFarm, | ||
| language_preference: user.language_preference, |
There was a problem hiding this comment.
user.language_preference is the sender's selected language in the case of a new account, and the actual user.language_preference for an existing account.
In the existing account case there is no difference between this and the userFarm value, but for a new account userFarm.language_preference is always 'en' and was over-writing the invitation language here.
|
@SayakaOno I'm going to go ahead and give this a direct merge now so that Denis can start QA as soon as he starts work, but that isn't to say it doesn't need review -- it does!! Please do review it!! 🙏🙏🙏 If either you or Denis find any blockers we can hold off on patch, but I was hoping the simulataneous code review + QA during your earlier shifts could set us up for still getting the patch out tomorrow morning if everything checks out 🤞 Sorry I didn't get a chance to set up the patch branch yet though... |
Description
Unfortunately I came to the wrong conclusion on #4186 this morning! The fact that there is no
'null'language_preferencerecords on beta or prod was because the ability to create them came from the LF-5318 change. After that change, 100% of invited new accounts will show that pattern, so it needs to be fixed before patch.There were a lot of errors in this invite account creation flow, but the closest proximate cause was the failure of this line:
It looks like that params.get() fails because of how the
&languageis escaped, but I don't know if that is a change that happened since this logic was first written, or if it has never worked.When language can't be taken from the URL like this, the saga payload language is also null, and
litefarm_langgets set as'null'inpatchUserFarmStatusSaga():When i18n.changeLanguage was changed to be called conditionally, that changeLanguage was skipped and the local storage value was never overwritten, exposing this bug.
One side effect of this is that what looks like the intended language setting (= matching the language selected for the invite email, in the case of a new account) was never applied. After accepting an invite, no matter the language of the invite email, the LiteFarm UI is rendered in English.
This PR will repair that, so now LiteFarm show the accept invitation UI in the same language as the accept invitation email.
Summary of Changes
language_preferencealready passed in the invite token to the one that matches the inviting languageuserFarmController.jsto make the actual behaviour of the flow more transparentJira link: https://lite-farm.atlassian.net/browse/LF-5318
Type of change
How Has This Been Tested?
Tested SSO + password account creation via invites to trace language in this flow.
Checklist:
pnpm i18nto help with this)