bugfix/fixed future issue for setAccountHolderAndRefreshUserAccountAccess method

This commit is contained in:
hongwei 2023-07-04 01:54:37 +08:00
parent 5a9bcba6df
commit 746cf718ee
16 changed files with 27 additions and 107 deletions

View File

@ -832,7 +832,7 @@ trait APIMethods220 {
//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, postedOrLoggedInUser, callContext)
_ <- BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, postedOrLoggedInUser, callContext)
} yield {
(JSONFactory220.createAccountJSON(userIdAccountOwner, bankAccount), HttpCode.`200`(callContext))

View File

@ -1890,7 +1890,7 @@ trait APIMethods310 {
_ <- NewStyle.function.hasEntitlement("", userId, canRefreshUser, callContext)
startTime <- Future{Helpers.now}
(user, callContext) <- NewStyle.function.findByUserId(userId, callContext)
_ = AuthUser.refreshUser(user, callContext)
_ <- AuthUser.refreshUser(user, callContext)
endTime <- Future{Helpers.now}
durationTime = endTime.getTime - startTime.getTime
} yield {
@ -2340,8 +2340,9 @@ trait APIMethods310 {
"",
List.empty,
callContext)
success <- BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, u, callContext)
}yield {
BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, u, callContext)
success
}
case _ => Future{""}
}
@ -5428,7 +5429,7 @@ trait APIMethods310 {
//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, postedOrLoggedInUser, callContext)
_ <- BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, postedOrLoggedInUser, callContext)
} yield {
(JSONFactory310.createAccountJSON(userIdAccountOwner, bankAccount, accountAttributes), HttpCode.`201`(callContext))
}

View File

@ -536,7 +536,7 @@ trait APIMethods400 {
//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, postedOrLoggedInUser, callContext)
_ <- BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, postedOrLoggedInUser, callContext)
} yield {
(JSONFactory400.createSettlementAccountJson(userIdAccountOwner, bankAccount, accountAttributes), HttpCode.`201`(callContext))
}
@ -2631,7 +2631,7 @@ trait APIMethods400 {
//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, postedOrLoggedInUser, callContext)
_ <- BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, postedOrLoggedInUser, callContext)
} yield {
(JSONFactory310.createAccountJSON(userIdAccountOwner, bankAccount, accountAttributes), HttpCode.`201`(callContext))
}

View File

@ -391,7 +391,7 @@ trait APIMethods500 {
//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, postedOrLoggedInUser, callContext)
_ <- BankAccountCreation.setAccountHolderAndRefreshUserAccountAccess(bankId, accountId, postedOrLoggedInUser, callContext)
} yield {
(JSONFactory310.createAccountJSON(userIdAccountOwner, bankAccount, accountAttributes), HttpCode.`201`(callContext))
}

View File

@ -1376,8 +1376,11 @@ def restoreSomeSessions(): Unit = {
connectorEmptyResponse(_, callContext)
}
_ = logger.debug(s"--> for user($user): AuthUser.refreshUserAccountAccess.accounts : ${accountsHeld}")
success = refreshViewsAccountAccessAndHolders(user, accountsHeld, callContext)
}yield {
refreshViewsAccountAccessAndHolders(user, accountsHeld, callContext)
success
}
}
@ -1387,7 +1390,7 @@ def restoreSomeSessions(): Unit = {
* This method can only be used by the original user(account holder).
* InboundAccount return many fields, but in this method, we only need bankId, accountId and viewId so far.
*/
def refreshViewsAccountAccessAndHolders(user: User, accountsHeld: List[InboundAccount], callContext: Option[CallContext]): Unit = {
def refreshViewsAccountAccessAndHolders(user: User, accountsHeld: List[InboundAccount], callContext: Option[CallContext]) = {
if(user.isOriginalUser){
//first, we compare the accounts in obp and the accounts in cbs,
val (_, privateAccountAccess) = Views.views.vend.privateViewsUserCanAccess(user)
@ -1471,7 +1474,7 @@ def restoreSomeSessions(): Unit = {
//cbs has new views which are not in obp yet, we need to create new data for these accounts.
csbNewViewsForAccount = cbsViewsForAccount diff obpViewsForAccount
_ = logger.debug("refreshViewsAccountAccessAndHolders.csbNewViewsForAccount-------" + csbNewViewsForAccount)
_ = if(csbNewViewsForAccount.nonEmpty){
success = if(csbNewViewsForAccount.nonEmpty){
for{
newViewForAccount <- csbNewViewsForAccount
_ = logger.debug("refreshViewsAccountAccessAndHolders.csbNewViewsForAccount.newViewForAccount start:-------" + newViewForAccount)
@ -1487,10 +1490,14 @@ def restoreSomeSessions(): Unit = {
}
}
} yield {
bankAccountId
success
}
}
}
true
}
else {
false
}
}
/**
* Find the authUser by author user name(authUser and resourceUser are the same).

View File

@ -85,7 +85,7 @@ package code.model.dataAccess {
*
* @return This is a procedure, no return value. Just use the side effect.
*/
def setAccountHolderAndRefreshUserAccountAccess(bankId : BankId, accountId : AccountId, user: User, callContext: Option[CallContext]): Unit = {
def setAccountHolderAndRefreshUserAccountAccess(bankId : BankId, accountId : AccountId, user: User, callContext: Option[CallContext]) = {
// Here, we can call `addPermissionToSystemOwnerView` directly, but from now on, we try to simulate the CBS account creation.
// 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))

View File

@ -609,7 +609,7 @@ object MapperViews extends Views with MdcLoggable {
def getOrCreateSystemViewFromCbs(viewId: String): Box[View] = {
logger.debug(s"-->getOrCreateSystemViewFromCbs.${viewId} --- start ")
logger.debug(s"-->getOrCreateSystemViewFromCbs--- start--${viewId} ")
val ownerView = SYSTEM_OWNER_VIEW_ID.equals(viewId.toLowerCase)
val accountantsView = SYSTEM_ACCOUNTANT_VIEW_ID.equals(viewId.toLowerCase)
@ -633,7 +633,7 @@ object MapperViews extends Views with MdcLoggable {
Failure(ViewIdNotSupported+ s"Your input viewId is :$viewId")
}
logger.debug(s"-->getOrCreateSystemViewFromCbs.${viewId } --- finish : ${theView} ")
logger.debug(s"-->getOrCreateSystemViewFromCbs --- finish.${viewId } : ${theView} ")
theView
}

View File

@ -15,14 +15,6 @@ import scala.util.Random
class AccountTest extends V220ServerSetup with DefaultUsers {
override def beforeAll(): Unit = {
super.beforeAll()
}
override def afterAll(): Unit = {
super.afterAll()
}
val mockAccountId1 = "NEW_MOCKED_ACCOUNT_ID_01"
val mockAccountId2 = "NEW_MOCKED_ACCOUNT_ID_02"
@ -51,9 +43,6 @@ class AccountTest extends V220ServerSetup with DefaultUsers {
val responsePut = makePutRequest(requestPut, write(accountPutJSON))
And("We should get a 200")
responsePut.code should equal(200)
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(2)
When("We make the authenticated access request")
val requestGetAll = (v2_2Request / "accounts").GET <@ (user1)
@ -98,10 +87,6 @@ class AccountTest extends V220ServerSetup with DefaultUsers {
val requestPut = (v2_2Request / "banks" / testBank.value / "accounts" / mockAccountId1).PUT <@ (user1)
val responsePut = makePutRequest(requestPut, write(accountPutJSON))
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(2)
And("We should get a 200")
responsePut.code should equal(200)
@ -165,10 +150,6 @@ class AccountTest extends V220ServerSetup with DefaultUsers {
val requestPut = (v2_2Request / "banks" / testBank.value / "accounts" / mockAccountId1).PUT <@ (user1)
val responsePut = makePutRequest(requestPut, write(accountPutJSON))
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(2)
Then("we get the account access for this account")
val accountViewsRequest = (v2_2Request / "banks" / testBank.value / "accounts" / mockAccountId1 / "views").GET <@(user1)
val accountViewsResponse = makeGetRequest(accountViewsRequest)

View File

@ -103,10 +103,6 @@ class AccountTest extends V310ServerSetup with DefaultUsers {
responsePut1.code should equal(200)
responsePut1.body.extract[UpdateAccountResponseJsonV310].account_routings should be (testPutJsonWithIban.account_routings)
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(2)
val responseGet1 = makeGetRequest(requestGet)
And("We should get 200 and updated account routings in the getAccount response")
responseGet1.code should equal(200)
@ -202,10 +198,6 @@ class AccountTest extends V310ServerSetup with DefaultUsers {
val response310 = makePutRequest(request310, write(putCreateAccountJSONV310))
Then("We should get a 201")
response310.code should equal(201)
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(2)
val account = response310.body.extract[CreateAccountResponseJsonV310]
account.product_code should be (putCreateAccountJSONV310.product_code)
@ -217,10 +209,6 @@ class AccountTest extends V310ServerSetup with DefaultUsers {
account.label should be (putCreateAccountJSONV310.label)
account.account_routings should be (putCreateAccountJSONV310.account_routings)
//We need to waite some time for the account creation, because we introduce `AuthUser.refreshUser(user, callContext)`
//It may not finished when we call the get accounts directly.
TimeUnit.SECONDS.sleep(2)
Then(s"we call $ApiEndpoint4 to get the account back")
val requestApiEndpoint4 = (v3_1_0_Request / "my" / "accounts" ).PUT <@(user1)
@ -278,10 +266,7 @@ class AccountTest extends V310ServerSetup with DefaultUsers {
val response310 = makePutRequest(request310, write(putCreateAccountJson))
Then("We should get a 201")
response310.code should equal(201)
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(2)
val account = response310.body.extract[CreateAccountResponseJsonV310]
account.product_code should be (putCreateAccountJson.product_code)
account.`label` should be (putCreateAccountJson.`label`)
@ -308,10 +293,6 @@ class AccountTest extends V310ServerSetup with DefaultUsers {
Then("We should get a 201")
responseUser2_310.code should equal(201)
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(2)
Then(s"we call $ApiEndpoint6 to get the account back by user2")
val requestApiUser2Endpoint6 = (v3_1_0_Request /"banks" / testBankId.value / "accounts" / userAccountId / Constant.SYSTEM_OWNER_VIEW_ID/ "account" ).GET <@(user2)
@ -328,9 +309,6 @@ class AccountTest extends V310ServerSetup with DefaultUsers {
Then("We should get a 201")
response310_1.code should equal(201)
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(2)
val account = response310_1.body.extract[CreateAccountResponseJsonV310]
account.product_code should be (putCreateAccountJSONV310.product_code)
account.`label` should be (putCreateAccountJSONV310.`label`)

View File

@ -44,9 +44,6 @@ class AccountAccessTest extends V400ServerSetup {
val request400 = (v4_0_0_Request / "banks" / bankId / "accounts" ).POST <@(user1)
val response400 = makePostRequest(request400, write(addAccountJson))
Then("We should get a 201")
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(3)
response400.code should equal(201)
response400.body.extract[CreateAccountResponseJsonV310]

View File

@ -106,10 +106,7 @@ class AccountTest extends V400ServerSetup {
Then("We should get a 201")
response400.code should equal(201)
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(2)
val account = response400.body.extract[CreateAccountResponseJsonV310]
account.account_id should not be empty
account.product_code should be (addAccountJson.product_code)
@ -121,11 +118,6 @@ class AccountTest extends V400ServerSetup {
account.label should be (addAccountJson.label)
account.account_routings should be (addAccountJson.account_routings)
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(3)
Then(s"We call $ApiEndpoint1 to get the account back")
val request = (v4_0_0_Request /"my" / "banks" / testBankId.value/ "accounts" / account.account_id / "account").GET <@ (user1)
val response = makeGetRequest(request)
@ -170,10 +162,6 @@ class AccountTest extends V400ServerSetup {
Then("We should get a 201")
response400_1.code should equal(201)
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(2)
val account = response400_1.body.extract[CreateAccountResponseJsonV310]
account.account_id should not be empty
account.product_code should be (addAccountJson.product_code)

View File

@ -70,10 +70,6 @@ class DeleteAccountCascadeTest extends V400ServerSetup {
val account = response400.body.extract[CreateAccountResponseJsonV310]
account.account_id should not be empty
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(3)
val postBodyView = createViewJsonV300.copy(name = "_cascade_delete", metadata_view = "_cascade_delete", is_public = false).toCreateViewJson
createViewViaEndpoint(bankId, account.account_id, postBodyView, user1)

View File

@ -65,10 +65,7 @@ class DeleteBankCascadeTest extends V400ServerSetup {
val request400 = (v4_0_0_Request / "banks" / bankId / "accounts" ).POST <@(user1)
val response400 = makePostRequest(request400, write(addAccountJson))
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(3)
Then("We should get a 201")
response400.code should equal(201)
val account = response400.body.extract[CreateAccountResponseJsonV310]

View File

@ -125,10 +125,6 @@ class SettlementAccountTest extends V400ServerSetup {
makePostRequest((v4_0_0_Request / "banks" / testBankId.value / "settlement-accounts" ).POST <@(user1), write(createSettlementAccountJson))
makePostRequest((v4_0_0_Request / "banks" / testBankId.value / "settlement-accounts" ).POST <@(user1), write(createSettlementAccountOtherUser))
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(4)
When("We send the request")
val addedEntitlement: Box[Entitlement] = Entitlement.entitlement.vend.addEntitlement(testBankId.value, resourceUser1.userId, ApiRole.CanGetSettlementAccountAtOneBank.toString)

View File

@ -277,9 +277,7 @@ trait V400ServerSetup extends ServerSetupWithTestData with DefaultUsers {
And("We make a request v4.0.0")
val request400 = (v4_0_0_Request / "banks" / bankId / "accounts" ).POST <@(consumerAndToken)
val response400 = makePostRequest(request400, write(json))
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(3)
Then("We should get a 201")
response400.code should equal(201)

View File

@ -64,10 +64,6 @@ class AccountTest extends V500ServerSetup with DefaultUsers {
val response = makePutRequest(request, write(putCreateAccountJSONV310))
Then("We should get a 201")
response.code should equal(201)
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(2)
val account = response.body.extract[CreateAccountResponseJsonV310]
account.product_code should be (putCreateAccountJSONV310.product_code)
@ -80,10 +76,6 @@ class AccountTest extends V500ServerSetup with DefaultUsers {
account.account_routings should be (putCreateAccountJSONV310.account_routings)
//We need to waite some time for the account creation, because we introduce `AuthUser.refreshUser(user, callContext)`
//It may not finished when we call the get accounts directly.
TimeUnit.SECONDS.sleep(2)
Then(s"we call $ApiEndpoint4 to get the account back")
val requestApiEndpoint4 = (v5_0_0_Request / "my" / "accounts" ).PUT <@(user1)
val responseApiEndpoint4 = makeGetRequest(requestApiEndpoint4)
@ -141,9 +133,6 @@ class AccountTest extends V500ServerSetup with DefaultUsers {
val response500 = makePutRequest(request500, write(putCreateAccountJson))
Then("We should get a 201")
response500.code should equal(201)
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(2)
val account = response500.body.extract[CreateAccountResponseJsonV310]
account.product_code should be (putCreateAccountJson.product_code)
@ -172,11 +161,6 @@ class AccountTest extends V500ServerSetup with DefaultUsers {
Then("We should get a 201")
responseUser2_500.code should equal(201)
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(2)
Then(s"we call $ApiEndpoint6 to get the account back by user2")
val requestApiUser2Endpoint6 = (v5_0_0_Request /"banks" / testBankId.value / "accounts" / userAccountId / Constant.SYSTEM_OWNER_VIEW_ID/ "account" ).GET <@(user2)
val responseApiUser2Endpoint6 = makeGetRequest(requestApiUser2Endpoint6)
@ -193,9 +177,6 @@ class AccountTest extends V500ServerSetup with DefaultUsers {
Then("We should get a 201")
response310_1.code should equal(201)
//for create account endpoint, we need to wait for `setAccountHolderAndRefreshUserAccountAccess` method,
//it is an asynchronous process, need some time to be done.
TimeUnit.SECONDS.sleep(2)
val account = response310_1.body.extract[CreateAccountResponseJsonV310]
account.product_code should be (putCreateAccountJSONV310.product_code)
account.`label` should be (putCreateAccountJSONV310.`label`)