mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
i18n: Fix default language for users created via API/LDAP.
This fixes a regression introduced in
9954db4b59, where the realm's default
language would be ignored for users created via API/LDAP/SAML,
resulting in all such users having English as their default language.
The API/LDAP/SAML account creation code paths don't have a request,
and thus cannot pull default language from the user's browser.
We have the `realm.default_language` field intended for this use case,
but it was not being passed through the system.
Rather than pass `realm.default_language` through from each caller, we
make the low-level user creation code set this field, as that seems
more robust to the creation of future callers.
This commit is contained in:
committed by
Mateusz Mandera
parent
7669fe8446
commit
c6fe799369
@@ -7,6 +7,7 @@ from django.contrib.auth.models import UserManager
|
||||
from django.utils.timezone import now as timezone_now
|
||||
|
||||
from zerver.lib.hotspots import copy_hotspots
|
||||
from zerver.lib.i18n import get_default_language_for_new_user
|
||||
from zerver.lib.timezone import canonicalize_timezone
|
||||
from zerver.lib.upload import copy_avatar
|
||||
from zerver.models import (
|
||||
@@ -92,7 +93,7 @@ def create_user_profile(
|
||||
is_mirror_dummy: bool,
|
||||
tos_version: Optional[str],
|
||||
timezone: str,
|
||||
default_language: str = "en",
|
||||
default_language: str,
|
||||
tutorial_status: str = UserProfile.TUTORIAL_WAITING,
|
||||
force_id: Optional[int] = None,
|
||||
force_date_joined: Optional[datetime] = None,
|
||||
@@ -152,7 +153,7 @@ def create_user(
|
||||
timezone: str = "",
|
||||
avatar_source: str = UserProfile.AVATAR_FROM_GRAVATAR,
|
||||
is_mirror_dummy: bool = False,
|
||||
default_language: str = "en",
|
||||
default_language: Optional[str] = None,
|
||||
default_sending_stream: Optional[Stream] = None,
|
||||
default_events_register_stream: Optional[Stream] = None,
|
||||
default_all_public_streams: Optional[bool] = None,
|
||||
@@ -174,6 +175,12 @@ def create_user(
|
||||
# so we hardcode them to EMAIL_ADDRESS_VISIBILITY_EVERYONE.
|
||||
user_email_address_visibility = UserProfile.EMAIL_ADDRESS_VISIBILITY_EVERYONE
|
||||
|
||||
# Users created via the API or LDAP/SAML syncing code paths will
|
||||
# usually not have a default_language value, and should fall back
|
||||
# to the realm default.
|
||||
if default_language is None:
|
||||
default_language = get_default_language_for_new_user(realm, request=None)
|
||||
|
||||
user_profile = create_user_profile(
|
||||
realm,
|
||||
email,
|
||||
|
||||
Reference in New Issue
Block a user