diff --git a/changelog.d/0-release-notes/pr-2028 b/changelog.d/0-release-notes/pr-2028 new file mode 100644 index 0000000000..cc4cf7d5a4 --- /dev/null +++ b/changelog.d/0-release-notes/pr-2028 @@ -0,0 +1 @@ +The brig server config option `setDefaultLocale` has been replaced by `setDefaultUserLocale` and `setDefaultTemplateLocale` (see docs/reference/config-options.md for details) diff --git a/changelog.d/2-features/pr-2028 b/changelog.d/2-features/pr-2028 new file mode 100644 index 0000000000..03d788286e --- /dev/null +++ b/changelog.d/2-features/pr-2028 @@ -0,0 +1 @@ +Specialize `setDefaultLocale` to distinguish between default user locale and default template locale if the user's locale is n/a. diff --git a/charts/brig/templates/configmap.yaml b/charts/brig/templates/configmap.yaml index a127f33559..f2374810ab 100644 --- a/charts/brig/templates/configmap.yaml +++ b/charts/brig/templates/configmap.yaml @@ -204,7 +204,8 @@ data: suspendTimeout: {{ .setSuspendInactiveUsers.suspendTimeout }} {{- end }} setRichInfoLimit: {{ .setRichInfoLimit }} - setDefaultLocale: {{ .setDefaultLocale }} + setDefaultTemplateLocale: en + setDefaultUserLocale: {{ .setDefaultUserLocale }} setMaxTeamSize: {{ .setMaxTeamSize }} setMaxConvSize: {{ .setMaxConvSize }} setEmailVisibility: {{ .setEmailVisibility }} diff --git a/charts/brig/values.yaml b/charts/brig/values.yaml index 05616c3249..e8a5b9e329 100644 --- a/charts/brig/values.yaml +++ b/charts/brig/values.yaml @@ -53,7 +53,6 @@ config: legalholdUserTokenTimeout: 4838400 legalholdAccessTokenTimeout: 900 optSettings: - setDefaultLocale: en setActivationTimeout: 1209600 setTeamInvitationTimeout: 1814400 setUserMaxConnections: 1000 @@ -64,7 +63,8 @@ config: stdDev: 3000 retryAfter: 86400 setRichInfoLimit: 5000 - setDefaultLocale: en + setDefaultTemplateLocale: en + setDefaultUserLocale: en setMaxTeamSize: 500 setMaxConvSize: 500 # Allowed values: https://github.com/wireapp/wire-server/blob/0126651a25aabc0c5589edc2b1988bb06550a03a/services/brig/src/Brig/Options.hs#L304-L306 diff --git a/deploy/services-demo/conf/brig.demo-docker.yaml b/deploy/services-demo/conf/brig.demo-docker.yaml index 6de26fd1e6..ff9c1417d1 100644 --- a/deploy/services-demo/conf/brig.demo-docker.yaml +++ b/deploy/services-demo/conf/brig.demo-docker.yaml @@ -109,7 +109,8 @@ optSettings: stdDev: 3000 # 50 minutes retryAfter: 86400 # 1 day setRichInfoLimit: 5000 # should be in sync with Spar - setDefaultLocale: en + setDefaultTemplateLocale: en + setDefaultUserLocale: en setMaxTeamSize: 128 setMaxConvSize: 128 setEmailVisibility: visible_to_self diff --git a/deploy/services-demo/conf/brig.demo.yaml b/deploy/services-demo/conf/brig.demo.yaml index 90072befc8..c4243c2942 100644 --- a/deploy/services-demo/conf/brig.demo.yaml +++ b/deploy/services-demo/conf/brig.demo.yaml @@ -109,7 +109,8 @@ optSettings: stdDev: 3000 # 50 minutes retryAfter: 86400 # 1 day setRichInfoLimit: 5000 # should be in sync with Spar - setDefaultLocale: en + setDefaultTemplateLocale: en + setDefaultUserLocale: en setMaxTeamSize: 128 setMaxConvSize: 128 setEmailVisibility: visible_to_self diff --git a/docs/reference/config-options.md b/docs/reference/config-options.md index 03630aee07..c5143212ac 100644 --- a/docs/reference/config-options.md +++ b/docs/reference/config-options.md @@ -319,3 +319,30 @@ When a `null` value is encountered, it is assumed to be `defaultForNull`. (Introduced in https://github.com/wireapp/wire-server/pull/1811.) + +### Locale + + +#### setDefaultLocale (deprecated / ignored) + +The brig server config option `setDefaultLocale` has been replaced by `setDefaultUserLocale` and `setDefaultTemplateLocale`. Both settings are optional and `setDefaultTemplateLocale` defaults to `EN` and `setDefaultLocale` defaults to `setDefaultTemplateLocale`. If `setDefaultLocale` was not set or set to `EN` before this change, nothing needs to be done. If `setDefaultLocale` was set to any other language other than `EN` the name of the setting should be changed to `setDefaultTemplateLocale`. + +#### `setDefaultTemplateLocale` + +This option determines the default locale for email templates. The language of the email communication is determined by the user locale (see above). Only if templates of the the locale of the user do not exist or if user locale is not set the `setDefaultTemplateLocale` is used as a fallback. If not set the default is `EN`. This setting should not be changed unless a complete set of templates is available for the given language. + +``` +# [brig.yaml] +optSettings: + setDefaultTemplateLocale: en +``` + +#### `setDefaultUserLocale` + +This option is the default user locale to be used if it is not set in the user profile. This can be the case if the users are provisioned by SCIM e.g. This option determines which language to use for email communication. If not set the default is the value that is configured for `setDefaultTemplateLocale`. + +``` +# [brig.yaml] +optSettings: + setDefaultUserLocale: en +``` diff --git a/hack/helm_vars/wire-server/values.yaml.gotmpl b/hack/helm_vars/wire-server/values.yaml.gotmpl index c872b4c04a..b7004f90dd 100644 --- a/hack/helm_vars/wire-server/values.yaml.gotmpl +++ b/hack/helm_vars/wire-server/values.yaml.gotmpl @@ -69,7 +69,8 @@ brig: retryLimit: 5 # how many times can you have a failed login in that timeframe. setSuspendInactiveUsers: suspendTimeout: 10 - setDefaultLocale: en + setDefaultTemplateLocale: en + setDefaultUserLocale: en setMaxConvAndTeamSize: 16 setMaxTeamSize: 32 setMaxConvSize: 16 diff --git a/services/brig/brig.integration.yaml b/services/brig/brig.integration.yaml index b5ca314dfb..fa2d13ffe1 100644 --- a/services/brig/brig.integration.yaml +++ b/services/brig/brig.integration.yaml @@ -152,7 +152,8 @@ optSettings: setSuspendInactiveUsers: # if this is omitted: never suspend inactive users. suspendTimeout: 10 setRichInfoLimit: 5000 # should be in sync with Spar - setDefaultLocale: en + setDefaultTemplateLocale: en + setDefaultUserLocale: en setMaxTeamSize: 32 setMaxConvSize: 16 setEmailVisibility: visible_to_self diff --git a/services/brig/src/Brig/API/User.hs b/services/brig/src/Brig/API/User.hs index f1bdc2f0b8..b70bc93f5d 100644 --- a/services/brig/src/Brig/API/User.hs +++ b/services/brig/src/Brig/API/User.hs @@ -1062,7 +1062,7 @@ deleteAccount account@(accountUser -> user) = do revokeAllCookies uid where mkTombstone = do - defLoc <- setDefaultLocale <$> view settings + defLoc <- setDefaultUserLocale <$> view settings return $ account { accountStatus = Deleted, diff --git a/services/brig/src/Brig/Data/User.hs b/services/brig/src/Brig/Data/User.hs index 1d501b0f48..56d8698266 100644 --- a/services/brig/src/Brig/Data/User.hs +++ b/services/brig/src/Brig/Data/User.hs @@ -118,7 +118,7 @@ data ReAuthError -- there, it was claimed properly. newAccount :: NewUser -> Maybe InvitationId -> Maybe TeamId -> Maybe Handle -> AppIO (UserAccount, Maybe Password) newAccount u inv tid mbHandle = do - defLoc <- setDefaultLocale <$> view settings + defLoc <- setDefaultUserLocale <$> view settings domain <- viewFederationDomain uid <- Id <$> do @@ -132,7 +132,7 @@ newAccount u inv tid mbHandle = do -- Ephemeral users' expiry time is in expires_in (default sessionTokenTimeout) seconds e <- view zauthEnv let ZAuth.SessionTokenTimeout defTTL = e ^. ZAuth.settings . ZAuth.sessionTokenTimeout - ttl = fromMaybe defTTL (fromRange <$> newUserExpiresIn u) + ttl = maybe defTTL fromRange (newUserExpiresIn u) now <- liftIO =<< view currentTime return . Just . toUTCTimeMillis $ addUTCTime (fromIntegral ttl) now _ -> return Nothing @@ -154,7 +154,7 @@ newAccount u inv tid mbHandle = do newAccountInviteViaScim :: UserId -> TeamId -> Maybe Locale -> Name -> Email -> AppIO UserAccount newAccountInviteViaScim uid tid locale name email = do - defLoc <- setDefaultLocale <$> view settings + defLoc <- setDefaultUserLocale <$> view settings domain <- viewFederationDomain return (UserAccount (user domain (fromMaybe defLoc locale)) PendingInvitation) where @@ -370,7 +370,7 @@ deactivateUser u = lookupLocale :: UserId -> AppIO (Maybe Locale) lookupLocale u = do - defLoc <- setDefaultLocale <$> view settings + defLoc <- setDefaultUserLocale <$> view settings fmap (toLocale defLoc) <$> retry x1 (query1 localeSelect (params LocalQuorum (Identity u))) lookupName :: UserId -> AppIO (Maybe Name) @@ -417,7 +417,7 @@ lookupAuth u = fmap f <$> retry x1 (query1 authSelect (params LocalQuorum (Ident -- Skips nonexistent users. /Does not/ skip users who have been deleted. lookupUsers :: HavePendingInvitations -> [UserId] -> AppIO [User] lookupUsers hpi usrs = do - loc <- setDefaultLocale <$> view settings + loc <- setDefaultUserLocale <$> view settings domain <- viewFederationDomain toUsers domain loc hpi <$> retry x1 (query usersSelect (params LocalQuorum (Identity usrs))) @@ -426,7 +426,7 @@ lookupAccount u = listToMaybe <$> lookupAccounts [u] lookupAccounts :: [UserId] -> AppIO [UserAccount] lookupAccounts usrs = do - loc <- setDefaultLocale <$> view settings + loc <- setDefaultUserLocale <$> view settings domain <- viewFederationDomain fmap (toUserAccount domain loc) <$> retry x1 (query accountsSelect (params LocalQuorum (Identity usrs))) diff --git a/services/brig/src/Brig/Options.hs b/services/brig/src/Brig/Options.hs index ad631e4932..8487c2c476 100644 --- a/services/brig/src/Brig/Options.hs +++ b/services/brig/src/Brig/Options.hs @@ -26,13 +26,15 @@ import Brig.Types import Brig.User.Auth.Cookie.Limit import Brig.Whitelist (Whitelist (..)) import qualified Brig.ZAuth as ZAuth +import Control.Applicative import qualified Control.Lens as Lens -import Data.Aeson (withText) +import Data.Aeson (defaultOptions, fieldLabelModifier, genericParseJSON, withText) import qualified Data.Aeson as Aeson import Data.Aeson.Types (typeMismatch) import qualified Data.Char as Char import Data.Domain (Domain (..)) import Data.Id +import Data.LanguageCodes (ISO639_1 (EN)) import Data.Misc (HttpsUrl) import Data.Range import Data.Scientific (toBoundedInteger) @@ -439,9 +441,12 @@ data Settings = Settings -- field names and values), should be in sync -- with Spar setRichInfoLimit :: !Int, - -- | Default locale to use - -- (e.g. when selecting templates) - setDefaultLocale :: !Locale, + -- | Default locale to use when selecting templates + -- use `setDefaultTemplateLocale` as the getter function which always provides a default value + setDefaultTemplateLocaleInternal :: !(Maybe Locale), + -- | Default locale to use for users + -- use `setDefaultUserLocale` as the getter function which always provides a default value + setDefaultUserLocaleInternal :: !(Maybe Locale), -- | Max. # of members in a team. -- NOTE: This must be in sync with galley setMaxTeamSize :: !Word32, @@ -474,7 +479,7 @@ data Settings = Settings -- setFederationAllowedDomains: -- - wire.com -- - example.com - setFederationDomain :: !(Domain), + setFederationDomain :: !Domain, -- | The amount of time in milliseconds to wait after reading from an SQS queue -- returns no message, before asking for messages from SQS again. -- defaults to 'defSqsThrottleMillis'. @@ -499,6 +504,18 @@ data Settings = Settings } deriving (Show, Generic) +defaultTemplateLocale :: Locale +defaultTemplateLocale = Locale (Language EN) Nothing + +defaultUserLocale :: Locale +defaultUserLocale = defaultTemplateLocale + +setDefaultUserLocale :: Settings -> Locale +setDefaultUserLocale = fromMaybe defaultUserLocale . setDefaultUserLocaleInternal + +setDefaultTemplateLocale :: Settings -> Locale +setDefaultTemplateLocale = fromMaybe defaultTemplateLocale . setDefaultTemplateLocaleInternal + -- | The analog to `GT.FeatureFlags`. This type tracks only the things that we need to -- express our current cloud business logic. -- @@ -664,7 +681,16 @@ instance FromJSON Timeout where maybe defaultV fromIntegral bounded parseJSON v = typeMismatch "activationTimeout" v -instance FromJSON Settings +instance FromJSON Settings where + parseJSON = genericParseJSON customOptions + where + customOptions = + defaultOptions + { fieldLabelModifier = \case + "setDefaultUserLocaleInternal" -> "setDefaultUserLocale" + "setDefaultTemplateLocaleInternal" -> "setDefaultTemplateLocale" + other -> other + } instance FromJSON Opts diff --git a/services/brig/src/Brig/Provider/API.hs b/services/brig/src/Brig/Provider/API.hs index 8cebe4a4f6..3e70599000 100644 --- a/services/brig/src/Brig/Provider/API.hs +++ b/services/brig/src/Brig/Provider/API.hs @@ -846,7 +846,7 @@ addBot zuid zcon cid add = do let botReq = Ext.NewBotRequest bid bcl busr bcnv btk bloc rs <- RPC.createBot scon botReq !>> StdError . serviceError -- Insert the bot user and client - locale <- setDefaultLocale <$> view settings + locale <- Opt.setDefaultUserLocale <$> view settings let name = fromMaybe (serviceProfileName svp) (Ext.rsNewBotName rs) let assets = fromMaybe (serviceProfileAssets svp) (Ext.rsNewBotAssets rs) let colour = fromMaybe defaultAccentId (Ext.rsNewBotColour rs) @@ -858,7 +858,7 @@ addBot zuid zcon cid add = do { newClientPrekeys = Ext.rsNewBotPrekeys rs } lift $ User.insertAccount (UserAccount usr Active) (Just (cid, cnvTeam cnv)) Nothing True - maxPermClients <- fromMaybe Opt.defUserMaxPermClients <$> Opt.setUserMaxPermClients <$> view settings + maxPermClients <- fromMaybe Opt.defUserMaxPermClients . Opt.setUserMaxPermClients <$> view settings (clt, _, _) <- do _ <- do -- if we want to protect bots against lh, 'addClient' cannot just send lh capability diff --git a/services/brig/src/Brig/Provider/Template.hs b/services/brig/src/Brig/Provider/Template.hs index 579a0149e6..b2c7828b7d 100644 --- a/services/brig/src/Brig/Provider/Template.hs +++ b/services/brig/src/Brig/Provider/Template.hs @@ -137,7 +137,7 @@ loadProviderTemplates o = readLocalesDir defLocale (templateDir gOptions) "provi maybeUrl = fromByteString $ encodeUtf8 $ homeUrl pOptions gOptions = general $ emailSMS o pOptions = provider $ emailSMS o - defLocale = setDefaultLocale (optSettings o) + defLocale = setDefaultTemplateLocale (optSettings o) readTemplate = readTemplateWithDefault (templateDir gOptions) defLocale "provider" readText = readTextWithDefault (templateDir gOptions) defLocale "provider" -- URL templates diff --git a/services/brig/src/Brig/Team/Template.hs b/services/brig/src/Brig/Team/Template.hs index 35946a1404..1599d810a0 100644 --- a/services/brig/src/Brig/Team/Template.hs +++ b/services/brig/src/Brig/Team/Template.hs @@ -95,6 +95,6 @@ loadTeamTemplates o = readLocalesDir defLocale (templateDir gOptions) "team" $ \ gOptions = general (emailSMS o) tOptions = team (emailSMS o) tUrl = template $ tInvitationUrl tOptions - defLocale = setDefaultLocale (optSettings o) + defLocale = setDefaultTemplateLocale (optSettings o) readTemplate = readTemplateWithDefault (templateDir gOptions) defLocale "team" readText = readTextWithDefault (templateDir gOptions) defLocale "team" diff --git a/services/brig/src/Brig/User/Template.hs b/services/brig/src/Brig/User/Template.hs index 60d1b5cab1..9d44a2ad78 100644 --- a/services/brig/src/Brig/User/Template.hs +++ b/services/brig/src/Brig/User/Template.hs @@ -228,7 +228,7 @@ loadUserTemplates o = readLocalesDir defLocale templateDir "user" $ \fp -> teamActivationUrl = template $ Opt.tActivationUrl tOptions passwordResetUrl = template $ Opt.passwordResetUrl uOptions deletionUserUrl = template $ Opt.deletionUrl uOptions - defLocale = Opt.setDefaultLocale (Opt.optSettings o) + defLocale = Opt.setDefaultTemplateLocale (Opt.optSettings o) templateDir = Opt.templateDir gOptions readTemplate = readTemplateWithDefault templateDir defLocale "user" readText = readTextWithDefault templateDir defLocale "user"