bugfix/added the box method for refreshUser relevant methods

This commit is contained in:
hongwei 2023-09-08 14:55:58 +02:00
parent 36e89a365e
commit d5c8f31195
6 changed files with 46 additions and 26 deletions

View File

@ -423,7 +423,7 @@ trait OBPRestHelper extends RestHelper with MdcLoggable {
val (user, callContext) = OAuth2Login.getUser(cc)
user match {
case Full(u) =>
AuthUser.refreshUser(u, callContext)
AuthUser.refreshUserLegacy(u, callContext)
fn(cc.copy(user = Full(u))) // Authentication is successful
case Empty => fn(cc.copy(user = Empty)) // Anonymous access
case ParamFailure(a, b, c, apiFailure : APIFailure) => ParamFailure(a, b, c, apiFailure : APIFailure)

View File

@ -1071,17 +1071,16 @@ object NewStyle extends MdcLoggable{
validateRequestPayload(callContext)(boxResult)
}
def createUserAuthContext(user: User, key: String, value: String, callContext: Option[CallContext]): OBPReturnType[UserAuthContext] = {
Connector.connector.vend.createUserAuthContext(user.userId, key, value, callContext) map {
i => (connectorEmptyResponse(i._1, callContext), i._2)
} map {
result =>
//We will call the `refreshUserAccountAccess` after we successfully create the UserAuthContext
// because `createUserAuthContext` is a connector method, here is the entry point for OBP to refreshUser
AuthUser.refreshUser(user, callContext)
result
def createUserAuthContext(user: User, key: String, value: String, callContext: Option[CallContext]): OBPReturnType[UserAuthContext] =
for{
(userAuthContext, callContext) <- Connector.connector.vend.createUserAuthContext(user.userId, key, value, callContext) map {
i => (connectorEmptyResponse(i._1, callContext), i._2)
}
_ <- AuthUser.refreshUser(user, callContext)
}yield{
(userAuthContext, callContext)
}
}
def createUserAuthContextUpdate(userId: String, key: String, value: String, callContext: Option[CallContext]): OBPReturnType[UserAuthContextUpdate] = {
Connector.connector.vend.createUserAuthContextUpdate(userId, key, value, callContext) map {
i => (connectorEmptyResponse(i._1, callContext), i._2)
@ -1098,17 +1097,15 @@ object NewStyle extends MdcLoggable{
}
}
def deleteUserAuthContextById(user: User, userAuthContextId: String, callContext: Option[CallContext]): OBPReturnType[Boolean] = {
Connector.connector.vend.deleteUserAuthContextById(userAuthContextId, callContext) map {
i => (connectorEmptyResponse(i._1, callContext), i._2)
}map {
result =>
// We will call the `refreshUserAccountAccess` after we successfully delete the UserAuthContext
// because `deleteUserAuthContextById` is a connector method, here is the entry point for OBP to refreshUser
AuthUser.refreshUser(user, callContext)
result
def deleteUserAuthContextById(user: User, userAuthContextId: String, callContext: Option[CallContext]): OBPReturnType[Boolean] =
for {
(userAuthContext, callContext) <- Connector.connector.vend.deleteUserAuthContextById(userAuthContextId, callContext) map {
i => (connectorEmptyResponse(i._1, callContext), i._2)
}
_ <- AuthUser.refreshUser(user, callContext)
} yield {
(userAuthContext, callContext)
}
}
def deleteUser(userPrimaryKey: UserPrimaryKey, callContext: Option[CallContext]): OBPReturnType[Boolean] = Future {
AuthUser.scrambleAuthUser(userPrimaryKey) match {

View File

@ -1245,7 +1245,7 @@ def restoreSomeSessions(): Unit = {
for {
u <- Users.users.vend.getUserByUserName(provider, username)
} yield {
refreshUser(u, None)
refreshUserLegacy(u, None)
}
}
}
@ -1373,7 +1373,21 @@ def restoreSomeSessions(): Unit = {
(accountsHeld, _) <- Connector.connector.vend.getBankAccountsForUser(user.provider, user.name,callContext) map {
connectorEmptyResponse(_, callContext)
}
_ = logger.debug(s"--> for user($user): AuthUser.refreshUserAccountAccess.accounts : ${accountsHeld}")
_ = logger.debug(s"--> for user($user): AuthUser.refreshUser.accountsHeld : ${accountsHeld}")
success = refreshViewsAccountAccessAndHolders(user, accountsHeld, callContext)
}yield {
success
}
}
@deprecated("This return Box, not a future, try to use @refreshUser instead. ","08-09-2023")
def refreshUserLegacy(user: User, callContext: Option[CallContext]) = {
for{
(accountsHeld, _) <- Connector.connector.vend.getBankAccountsForUserLegacy(user.provider, user.name, callContext)
_ = logger.debug(s"--> for user($user): AuthUser.refreshUserLegacy.accountsHeld : ${accountsHeld}")
success = refreshViewsAccountAccessAndHolders(user, accountsHeld, callContext)

View File

@ -92,6 +92,15 @@ package code.model.dataAccess {
// 2rd-refreshUserAccountAccess: in this method, we will simulate onboarding bank user processes. @refreshUserAccountAccess definition.
AuthUser.refreshUser(user, callContext)
}
@deprecated("This return Box, not a future, try to use @setAccountHolderAndRefreshUserAccountAccess instead. ","08-09-2023")
def setAccountHolderAndRefreshUserAccountAccessLegacy(bankId : BankId, accountId : AccountId, user: User, callContext: Option[CallContext]) = {
// 1st-getOrCreateAccountHolder: in this method, we only create the account holder, no view, account access involved here.
AccountHolders.accountHolders.vend.getOrCreateAccountHolder(user: User, BankIdAccountId(bankId, accountId))
// 2rd-refreshUserAccountAccess: in this method, we will simulate onboarding bank user processes. @refreshUserAccountAccess definition.
AuthUser.refreshUserLegacy(user, callContext)
}
}
@ -132,7 +141,7 @@ package code.model.dataAccess {
)
} yield {
logger.debug(s"created account with id ${bankAccount.bankId.value} with number ${bankAccount.number} at bank with identifier ${message.bankIdentifier}")
BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankAccount.bankId, bankAccount.accountId, user, None)
BankAccountCreation.setAccountHolderAndRefreshUserAccountAccessLegacy(bankAccount.bankId, bankAccount.accountId, user, None)
}
result match {

View File

@ -95,7 +95,7 @@ object CreateTestAccountForm{
//1 Create or Update the `Owner` for the new account
//2 Add permission to the user
//3 Set the user as the account holder
_ = BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, user, callContext)
_ = BankAccountCreation.setAccountHolderAndRefreshUserAccountAccessLegacy(bankId, accountId, user, callContext)
} yield {
bankAccount
}

View File

@ -219,7 +219,7 @@ class AuthUserTest extends ServerSetup with DefaultUsers with PropsReset{
scenario("we fake the output from getBankAccounts(), and check the functions there") {
When("We call the method use resourceUser1")
val result = Await.result(AuthUser.refreshUser(resourceUser1, None), Duration.Inf)
val result = AuthUser.refreshUserLegacy(resourceUser1, None)
Then("We check the accountHolders")
var accountholder1 = MapperAccountHolders.getAccountHolders(bankIdAccountId1.bankId, bankIdAccountId1.accountId)