Skip to content

Commit

Permalink
Merge pull request #2258 from constantine2nd/develop
Browse files Browse the repository at this point in the history
Enhance the user requests a new locale flow
  • Loading branch information
simonredfern authored Sep 6, 2023
2 parents 3c5326f + f9ec92c commit 3d11bc7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
11 changes: 8 additions & 3 deletions obp-api/src/main/scala/bootstrap/liftweb/Boot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,14 @@ class Boot extends MdcLoggable {
S.param(PARAM_LOCALE) match {
case Full(requestedLocale) if requestedLocale != null && APIUtil.checkShortString(requestedLocale)==SILENCE_IS_GOLDEN => {
val computedLocale: Locale = I18NUtil.computeLocale(requestedLocale)
val id: Long = AuthUser.getCurrentUser.map(_.user.userPrimaryKey.value).getOrElse(0)
Users.users.vend.getResourceUserByResourceUserId(id).map {
u => u.LastUsedLocale(computedLocale.toString).save
AuthUser.getCurrentUser.map(_.user.userPrimaryKey.value) match {
case Full(id) =>
Users.users.vend.getResourceUserByResourceUserId(id).map {
u =>
u.LastUsedLocale(computedLocale.toString).save
logger.debug(s"ResourceUser.LastUsedLocale is saved for the resource user id: $id")
}
case _ => // There is no current user
}
S.addCookie(HTTPCookie(localeCookieName, requestedLocale))
computedLocale
Expand Down
7 changes: 6 additions & 1 deletion obp-api/src/main/scala/code/api/util/I18NUtil.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import code.util.Helper.SILENCE_IS_GOLDEN

import java.util.{Date, Locale}

import code.util.Helper.MdcLoggable
import code.webuiprops.MappedWebUiPropsProvider.getWebUiPropsValue
import com.openbankproject.commons.model.enums.I18NResourceDocField
import net.liftweb.common.Full
import net.liftweb.http.S
import net.liftweb.http.provider.HTTPCookie

object I18NUtil {
object I18NUtil extends MdcLoggable {
// Copied from Sofit
def getLocalDate(date: Date): String = {
import java.text.DateFormat
Expand Down Expand Up @@ -47,6 +48,10 @@ object I18NUtil {
case Array(lang) => new Locale(lang)
case Array(lang, country) => new Locale(lang, country)
case Array(lang, country, variant) => new Locale(lang, country, variant)
case _ =>
val locale = getDefaultLocale()
logger.warn(s"Cannot parse the string $tag to Locale. Use default value: ${locale.toString()}")
locale
}

object ResourceDocTranslation {
Expand Down
2 changes: 0 additions & 2 deletions obp-api/src/main/scala/code/model/dataAccess/AuthUser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,6 @@ import net.liftweb.util.Helpers._
} else {
logger.debug(ErrorMessages.CurrentUserNotFoundException)
Failure(ErrorMessages.CurrentUserNotFoundException)
//This is a big problem, if there is no current user from here.
//throw new RuntimeException(ErrorMessages.CurrentUserNotFoundException)
}
} yield {
resourceUser
Expand Down

0 comments on commit 3d11bc7

Please sign in to comment.