Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛(i18n/backend) Fix/email in receiving user language #401

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rvveber
Copy link
Collaborator

@rvveber rvveber commented Nov 4, 2024

Implements the following:

  • E-mails sent for granting access are sent in the users language if it exists - else they will be sent in system default language
  • On Language change in the frontend, the language attribute of the user is updated via API.
  • Fixes to language related Tests
  • Added helper for language related Tests

Closes #323

@rvveber rvveber force-pushed the fix/email-in-receiving-user-language branch 2 times, most recently from c645b5b to 72b5272 Compare November 4, 2024 14:10
@rvveber rvveber marked this pull request as draft November 4, 2024 14:27
@rvveber rvveber force-pushed the fix/email-in-receiving-user-language branch 4 times, most recently from 62ebf55 to 332e770 Compare November 18, 2024 17:20
@rvveber
Copy link
Collaborator Author

rvveber commented Nov 21, 2024

@sampaccoud
Would it make sense to refactor the backend user.language choices to ISO639-1?
eg. fr-fr -> fr

@rvveber rvveber force-pushed the fix/email-in-receiving-user-language branch 6 times, most recently from fef3dea to 3b3e90c Compare November 21, 2024 16:46
@rvveber rvveber requested review from AntoLC and sampaccoud November 21, 2024 16:55
@rvveber rvveber marked this pull request as ready for review November 21, 2024 16:56
Copy link
Collaborator

@AntoLC AntoLC left a comment

Choose a reason for hiding this comment

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

Looks good !
A few comments.

@sampaccoud Should we add a migration to make all our current users french by default, because they will all switch to english after that, wdyt ?

@rvveber rvveber force-pushed the fix/email-in-receiving-user-language branch 2 times, most recently from b3534d3 to 704550b Compare November 25, 2024 14:50
@rvveber rvveber requested a review from AntoLC November 25, 2024 14:51
@rvveber rvveber force-pushed the fix/email-in-receiving-user-language branch from 704550b to d9bad8c Compare November 25, 2024 14:53
@rvveber rvveber force-pushed the fix/email-in-receiving-user-language branch from d9bad8c to f773350 Compare November 27, 2024 14:30
@rvveber rvveber requested a review from AntoLC November 27, 2024 14:32
@rvveber rvveber force-pushed the fix/email-in-receiving-user-language branch 2 times, most recently from 1b5eb7b to 38639c9 Compare November 27, 2024 14:44
Copy link
Collaborator

@AntoLC AntoLC left a comment

Choose a reason for hiding this comment

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

🎉 Good job, works perfect ^^

I think Sam wants to have a look at it before merging.

@sampaccoud
Copy link
Contributor

I was expecting the language to be set on the user on first logging here:
https://github.com/numerique-gouv/impress/blob/main/src/backend/core/authentication/backends.py#L91

Otherwise how and when is this field set on the user? 🤔

Comment on lines +84 to +95
// Switch i18n.language and user.language via API
const switchLanguage = (targetLocale: string): void => {
const actions: Promise<unknown>[] = [i18n.changeLanguage(targetLocale)];

if (userData?.id) {
actions.push(
changeUserLanguage({
userId: userData.id,
language: targetLocale,
}),
);
}
Copy link
Collaborator Author

@rvveber rvveber Dec 4, 2024

Choose a reason for hiding this comment

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

I was expecting the language to be set on the user on first logging here: https://github.com/numerique-gouv/impress/blob/main/src/backend/core/authentication/backends.py#L91

Otherwise how and when is this field set on the user? 🤔

When we have a user, we will always have a language set on the user, the choice is not nullable.
So we set, whatever has been set on the user, as language in the frontend.

If the user is unsatisfied with the language that is set, he switches it here (code above) and in turn it updates the attribute at the user.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok but language will default to settings.LANGUAGE_CODE in the backend. Since the user can only be created via a login, it is a pity not to try harder to set the user's language on first login!

Copy link
Collaborator Author

@rvveber rvveber Dec 6, 2024

Choose a reason for hiding this comment

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

I thought users are created through the Identity Provider? I was thinking to let the IdP transmit the preferred language for initial Account creation.

Also since its not nullable, from the frontend, i have no way of knowing, that what is set on the user, was not set by the IdP or by him.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. It could be one possibility but it's not in the case of our idP. If it came from the idP it would have to be added here right as well right?
If it's not set by the idP, you sould set it from the request at the moment of user creation ie on first loggging like I propose?

Copy link
Collaborator Author

@rvveber rvveber Dec 14, 2024

Choose a reason for hiding this comment

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

Ok, i will try to find an elegant way and implement it on monday

Copy link
Collaborator Author

@rvveber rvveber Dec 18, 2024

Choose a reason for hiding this comment

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

Unfortunately, i did not find an elegant way, with the time i had.
I'm in the holidays now and will revist this in january 2025.

E-mails sent for granting access are sent
in the receiving users language.
Falling back to system default language.
On Language change in the frontend,
the user language is updated via API.
If user language is available, it will
be preferred and set in the frontend.
@rvveber rvveber force-pushed the fix/email-in-receiving-user-language branch from 62c3dd6 to 6a562b4 Compare December 4, 2024 11:22
@rvveber rvveber requested a review from sampaccoud December 4, 2024 11:24
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.

Receive email notification in my language
3 participants